Hello,
I need to inizialise a global variable to mysql server during a connection. Is there a way to include the initizialization in TZConnectio component? maybe in params property? I actually excute a separated query with a SET statement.
thanks
Marco
Initizialising global variable
Moderators: gto, cipto_kh, EgonHugeist
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
This may be done using a trick.
If you add a 'set' statement to the my.cnf init-command parameter you should be able to execute it at every connect.
You can use an application specific cnf file by adding MYSQL_READ_DEFAULT_FILE=<filename> to connection.parameters and change TZMySQLConnection.Open function in ZDBCMysql.pas the way it's done for 'timeout' the property. (see mysql documentation of mysql_options API call)
You could also use the trick that's used in the same function, but for the Character set options. There a SET statement is fired depending on a connection.parameters line.
Easiest solution is yours : a separate SET query after connect/reconnect.
Mark
If you add a 'set' statement to the my.cnf init-command parameter you should be able to execute it at every connect.
You can use an application specific cnf file by adding MYSQL_READ_DEFAULT_FILE=<filename> to connection.parameters and change TZMySQLConnection.Open function in ZDBCMysql.pas the way it's done for 'timeout' the property. (see mysql documentation of mysql_options API call)
You could also use the trick that's used in the same function, but for the Character set options. There a SET statement is fired depending on a connection.parameters line.
Easiest solution is yours : a separate SET query after connect/reconnect.
Mark
I need to write security information, so it won't be the right place.mdaems wrote:This may be done using a trick.
If you add a 'set' statement to the my.cnf init-command parameter you should be able to execute it at every connect.
I added this code in TZMySQLConnection.Open function and works fine... except a newer version of zeoslib will overwrite it.. I considered to extend TZeconnection but I gave up quite soon becouse I should have rewrite some parts and I could not prevent errors due to future upgrades.You can use an application specific cnf file by adding MYSQL_READ_DEFAULT_FILE=<filename> to connection.parameters and change TZMySQLConnection.Open function in ZDBCMysql.pas the way it's done for 'timeout' the property. (see mysql documentation of mysql_options API call)
You could also use the trick that's used in the same function, but for the Character set options. There a SET statement is fired depending on a connection.parameters line.
if Info.Values['MYSQL_INIT_COMMAND'] <>'' then
begin
FPlainDriver.SetOptions(FHandle, MYSQL_INIT_COMMAND,
PChar(Info.Values['MYSQL_INIT_COMMAND']));
end;
Yes, it is the easiest and secure.Easiest solution is yours : a separate SET query after connect/reconnect.
thanks
Marco
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
This patch has been added to zeos testing branch (REV 314) and will be included in Zeoslib 6.6 unless somebody experiences serious trouble. It looks very safe, however, as it only has effects when you deliberately add new connection options to the TZConnection.Properties setting.
marcocot,
This was a nice piece of smart coding to enable all settings at once.
Do you know how to do this trick for te connection flags as well? I suppose I can figure this out myself but I have the impression you'll do it quicker.
Mark
marcocot,
This was a nice piece of smart coding to enable all settings at once.
Do you know how to do this trick for te connection flags as well? I suppose I can figure this out myself but I have the impression you'll do it quicker.
Mark
mdaems wrote:This patch has been added to zeos testing branch (REV 314) and will be included in Zeoslib 6.6 unless somebody experiences serious trouble. It looks very safe, however, as it only has effects when you deliberately add new connection options to the TZConnection.Properties setting.
marcocot,
thanks, Can I download somewhere?
I have sent a code to youThis was a nice piece of smart coding to enable all settings at once.
Do you know how to do this trick for te connection flags as well? I suppose I can figure this out myself but I have the impression you'll do it quicker.
Mark