On Wed, 1 Dec 2010, Joost van der Sluis wrote:
On Wed, 2010-12-01 at 16:01 +0100, [email protected] wrote:
On Wed, 1 Dec 2010, Joost van der Sluis wrote:
Is there somewhere I can hook into the TSQLQuery to (a) see exactly what
query was passed to the server (b) collect any error text and (c) get
execution timing?
a) Easiest is to use the database-client's log mechanism. (If there is
any). Else you can change the TPQConnection.Preparestatement function.
The 'buf' parameter is the actual query. But as you'll see it also adds
some more to the query, so it opens a cursor, before it is send to the
database-server.
b) Ehm.. the error-text is in the exception?
c) Hook into TPQConnection.PrepareStatement and TPQCOnnection.Execute
I am a firm proponent of putting a unified mechanism for a) and c) in
TSQLQuery/TSQLConnection, and have, in fact, a patch ready for this
(it implements a simple event mechanism for the log).
That's a no-brainer. It could als use TCustomApplication.Log, if
Customapplication is assigned. Or, add events before and after an
statement is prepared, executed or unprepared. (And when data is
fetched)
That would create a dependency on custapp. If it isn't there yet, I would
not introduce it.
I have now
TDBEventType = (detPrepare,detExecute,detFetch,detCommit);
TDBLogNotifyEvent = Procedure (Sender : TSQLConnection; EventType :
TDBEventType; Const Msg : String) of object;
And in TSQLConnection:
Property OnLog : TDBLogNotifyEvent Read FOnLog Write FOnLog;
But we can provide a unit that, when included, logs all queries
to custapp through a global hook. In fact, I think that's a good
idea.
If it is OK with you, I'll implement and commit it Friday ?
But should we add this code in the connection-objects for each db-type,
or in the code in the sqldb unit?
In the sqldb unit, of course.
Michael.
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus