There is an example request:
SELECT * FROM table JOIN table2 ON (column1 = arg1) WHERE column2 = arg2;
Is it possible to make it so that when we create a connection with the base (session), then a global alias is transmitted for the current session? When the mysql server encounters a certain combination of characters, for example, column1 = arg1
, this alias would tell you to replace it with another condition, for example, SELECT id FROM table 124 WHERE name = lastname
or any other. In general, by the type of how we set the parameter, for example, SET sql_mode = ANSI_QUOTES;
and during the session we work with the specified sql mode
.
Is there an easy way to solve this problem?
I will explain why this is necessary. There is an engine in which there is a mass of requests. One of the conditions in the queries is the combination of goods by default. Something like: column1 = arg1
. I am writing a module that will watch the user's session, and set up for it a combination of all products, by default, based on geo-location.
You can of course everywhere in the engine, find the entries column1 = arg1
and replace them with SELECT id FROM table 124 WHERE name = lastname
, but this seems to me a bad decision. The task of any normal module is to work without interfering with the engine files. Therefore, there was such an idea.
I would be grateful if someone advises a different way to solve the problem.
@
. make such a variable and in all sql queries put a condition of the type(@arg is null or column1=@arg)
immediately after connecting to the base and establishing(@arg is null or column1=@arg)
do simplyset @arg=xxx
- Mike