Initizialising global variable

Forum related to MySQL

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
marcocot
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: 23.05.2007, 13:52

Initizialising global variable

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
marcocot
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: 23.05.2007, 13:52

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
marcocot
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: 23.05.2007, 13:52

Post by marcocot »

Sure! Where should I post it?
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
marcocot
Fresh Boarder
Fresh Boarder
Posts: 17
Joined: 23.05.2007, 13:52

Post 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

:)
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Post Reply