Page 1 of 1

TZSQLMonitor ? as result of Event.AsString

Posted: 13.07.2007, 13:00
by slai
Hey there

i've got a problem with my TZSQLMonitor. i write the log in the onLogTrace event. i save the sql with Event.AsString ist that wrong?

That's the result of Event.AsString:

2007-07-13 13:54:00 cat: Execute, proto: firebird-1.5, msg: UPDATE ADRESSSTAMM SET STRASSENR2=? WHERE ID=?

Why ? and not the values.

thanks for replys

greez

i use:
lazarus 0.9.23 Beta
zeosdbo-6.6.1-beta
firebird 1.5

Posted: 16.07.2007, 20:48
by mdaems
I suppose the ? are there as the statement is executed using a 'prepare','bind variables','execute' sequence. The query actually sent to the server does not contain the values. They are sent separately.
Is this statement created by a query component when posting the updates?

Idea behind this is that some databases support 'prepared statements'. When executed more than once with only different parameters only the parameters have to be send to the server to re-execute. Unfortunately zeoslib does not yet support this way of working (prep,bind,exec,bind,exec,...). However, we're thinking about adding it. (Should give better performance when your database supports it.)

Mark

Posted: 17.07.2007, 07:05
by slai
Hey

Thank you for the answer. This statement is created if the user click on a button(Save). I think the problem is that i have a dynamic form that only show the fields of a table in the database the edits are TDBEdits with a datasource and the datasource connected to a TZTable. If the user click on the btn, I append/edit the record and in the end I use the ZTATable.CommitUpdates; (CommitUpdates ist the event that run the function LogTrace on the monitor) procedure should I take post or something else?

Is the meaning of your idea that i should create an prepare function that prepare the insert or update sql and than run it on an TZQuery?

I think it would be nice if zeoslib supports the way of working (prep,bind,exec,bind,exec,...), because if that is possible you can log the database changes, and than you have the choice to rollback the updates or inserts every time. (that would be awesome)

thank you

Posted: 17.07.2007, 08:49
by mdaems
slai,
I think you understood me wrong.
The query really is created with the question marks. And this is good. Once we really implement 'reusable' prepared statements this makes it possible to process the automatically generated updates/inserts/deletes 'the good way'.

Maybe we should add a new logging line when we bind/execute the values to fix the problem of the missing values. Now this will always give 2 logging lines for drivers that effectively support prepared statements: on prepare and on bind/execute. Drivers that do not (yet?) implement prepared statements simulate them by replacing the '?' by the actual values before processing a query. (eg mysql, but I'm working on that)

Would you like to help developing this (prep,bind,exec,bind,exec,...) thing? We just lack people to work on it...

Mark

Posted: 17.07.2007, 10:10
by slai
aaaaa ok, now i understand.

I try it on my programm if it is running i would copy my code into the zeoslib subversion repository. if i'm able to do that work :-) I would do this thing next week or in 2 weeks cause now i'm busy at work. And if I solved it i will contact you for that login thing on subversion, is that ok?

thank you very much

Posted: 17.07.2007, 13:46
by mdaems
slai,
If you want to try to implement the (prep,bind,exec,bind,exec,...) thing there will be more to discuss (believe me ;) ). Just drop me a pm before you start with that.

To split the logging would be a nice start exploring our code. Start in TZInterbase6PreparedStatement.ExecuteQueryPrepared.
At the end there is this line:
DriverManager.LogMessage(lcExecute, GetPlainDriver.GetProtocol, SQL);

This one should be moved to ZDbcInterbase6Utils.PrepareStatement.
A second log should be done after the execute, where it's done now, but with the parameter values in brackets behind the sql statement. You'll have to figure out how you can do that. Instead of lcExecute you should use lcPrepStmt and lcExecPrepStmt -> now only available in testing branch, I think.