Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-04

SQLDB: logging all generated SQL?

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Good morning list,

I vaguely remember somebody mentioning SQLDB has the option of dumping to a log all the SQL it sends to the database (in other words: logging all SQL sent to the database).

Can somebody tell me if that functionality is there and where to find it? Perhaps something to do with TSQLConnection.LogEvents?

Thanks,
Reinier

Reply by email

Unknown author
to Reinier Olislagers
Reinier Olislagers wrote 8 lines
Good morning list, I vaguely remember somebody mentioning SQLDB has the option of dumping to a log all the SQL it sends to the database (in other words: logging all SQL sent to the database). Can somebody tell me if that functionality is there and where to find it? Perhaps something to do with TSQLConnection.LogEvents?

That's the one.

Michael.

Reply by email

LacaK
to Reinier Olislagers: I vaguely remember somebody mentioning SQLDB has the option of dumping to a log all the…
Show quoted text 5 lines
Can somebody tell me if that functionality is there and where to find it? Perhaps something to do with TSQLConnection.LogEvents?

Look into sqldb.pp at TSQLConnection property OnLog or at global variable GlobalDBLogHook.
You can register procedure, which will receive log events and you can handle them as you want (write to form or into file) ... Look at sources ... ;-)
L.

Reply by email

Reinier Olislagers
to LacaK
LacaK wrote 9 lines
> Can somebody tell me if that functionality is there and where to find > it? Perhaps something to do with TSQLConnection.LogEvents? > > Look into sqldb.pp at TSQLConnection property OnLog or at global variable GlobalDBLogHook. You can register procedure, which will receive log events and you can handle them as you want (write to form or into file) ... Look at sources ... ;-)

Thanks guys, doing exactly that right now (looking at sources) ;)...

I'll update my pasql command line interpreter and update the wiki...

Regards,
Reinier

Reply by email

Ludo Brands
to Unknown author: That's the one. Michael.
Show quoted text 12 lines
> I vaguely remember somebody mentioning SQLDB has the option of dumping > to a log all the SQL it sends to the database (in other words: logging > all SQL sent to the database). > > Can somebody tell me if that functionality is there and where to find > it? Perhaps something to do with TSQLConnection.LogEvents? That's the one.

Just to be clear. The logging happens at the level of TSQLQuery and TSQLTransaction and will record events such as prepare, execute, commit, rollback, etc. SQL strings are as known at that layer (ie parameters are not expanded). Database layers that use data binding will never expand parameters and use a proprietary protocol to send the data to the database.

Ludo

Reply by email

Reinier Olislagers
to Ludo Brands
Ludo Brands wrote 16 lines
>> I vaguely remember somebody mentioning SQLDB has the option > of dumping >> to a log all the SQL it sends to the database (in other > words: logging >> all SQL sent to the database). >> >> Can somebody tell me if that functionality is there and > where to find >> it? Perhaps something to do with TSQLConnection.LogEvents? > > That's the one. Just to be clear. The logging happens at the level of TSQLQuery and TSQLTransaction and will record events such as prepare, execute, commit, rollback, etc. SQL strings are as known at that layer (ie parameters are not expanded). Database layers that use data binding will never expand parameters and use a proprietary protocol to send the data to the database.

Thanks, guess you must have read my forum post as well ;)

It makes sense parameters are not expanded; I'll just have to see what the logging contains.

Thanks,
Reinier

Reply by email

Reinier Olislagers
to LacaK: Look into sqldb.pp at TSQLConnection property OnLog or at global variable GlobalDBLogHook.
LacaK wrote 12 lines
> > Can somebody tell me if that functionality is there and where to find > it? Perhaps something to do with TSQLConnection.LogEvents? > > Look into sqldb.pp at TSQLConnection property OnLog or at global variable GlobalDBLogHook. You can register procedure, which will receive log events and you can handle them as you want (write to form or into file) ... Look at sources ... ;-) L.

Ok, got it working in my pasql "yet another command line SQL client": https://bitbucket.org/reiniero/fpc_laz_patch_playground/src directory SQL...

...and wrote up what I found at:
http://wiki.lazarus.freepascal.org/SqlDBHowto
(as well as the Dutch version)

Corrections/additions welcome, as ever.

Thanks,
Reinier

Reply by email