Page 1 of 1

Initizialising global variable

Posted: 16.11.2007, 10:51
by marcocot
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

Posted: 16.11.2007, 20:14
by mdaems
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

Posted: 20.11.2007, 16:01
by marcocot
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 need to write security information, so it won't be the right place.
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.
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.

if Info.Values['MYSQL_INIT_COMMAND'] <>'' then
begin
FPlainDriver.SetOptions(FHandle, MYSQL_INIT_COMMAND,
PChar(Info.Values['MYSQL_INIT_COMMAND']));
end;

Easiest solution is yours : a separate SET query after connect/reconnect.
Yes, it is the easiest and secure.



thanks

Marco

Posted: 20.11.2007, 16:43
by mdaems
Did this code patch work? Can you please send me your modified files so I can add it to zeoslib... Please also provide a small test project if that's possible?
That way you won't have the zeoslib upgrade problem and we have a new feature...

Mark

Posted: 20.11.2007, 17:40
by marcocot
Sure! Where should I post it?

Posted: 20.11.2007, 20:14
by mdaems
You can also attach it to this thread or send it in a private message on the forum. (pm button)
Or you could provide a link somewhere or...
So if it get's here it's OK...

Mark

Posted: 21.11.2007, 17:04
by mdaems
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

Posted: 26.11.2007, 10:28
by marcocot
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?
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
I have sent a code to you

:)

Posted: 26.11.2007, 11:13
by mdaems
Not yet... Only when you use SVN. I'll see when I have some time to build a new testing branch snapshot. (And when I can affort using upload bandwidth of my ISP account)

Mark