Page 1 of 1

[solved] Value in the insert ZQuery

Posted: 10.08.2012, 20:51
by elidorio2
How to get the value in the insert ZQuery, sends to the database?

Edson

Posted: 13.08.2012, 00:12
by EgonHugeist
elidorio2,

Edson, i do not understand what you mean ): !
Some more details?

Michael

Posted: 13.08.2012, 01:03
by elidorio2
Want to catch ZQuery script that is sending to the database.
example:
insert into t1 values ​​(: col1,: col2,: col3,: col4);

The script to insert the values ​​that zquery set up for the columns: col1, col2, col3 and col4.

Posted: 13.08.2012, 12:55
by josimarz
Hello elidorio2

Use the ParamByName to retrieve the value setted up to parameters of TZQuery. Example:

Code: Select all

var
   I: Integer;
begin
   ZQuery1.ParamByName('col1').AsInteger := 9;
   I := ZQuery1.ParamByName('col1').AsInteger;
   {...}
end;
Bye, bye

Josimar

Posted: 13.08.2012, 13:07
by elidorio2
Olá Josimar,

Quero pegar o script sql que a query enviou para o banco.

Posted: 13.08.2012, 20:14
by josimarz
Though our language is Portuguese, I suggest using English for what others may benefit from the information.

For your case I suggest using the TZSQLMonitor component. Just add it to your project, preferably in the same place the TZConnection component.

Change the TZSQLMonitor Active property to True and encode the event OnLogTrace to get the SQL that was sent to the database from Event.Message

I hope this helps.

Posted: 15.08.2012, 09:16
by EgonHugeist
elidorio2,

i think josimarz, is right here. One hint from me:

Your

Code: Select all

insert into t1 values ​​(: col1,: col2,: col3,: col4); 
should be:

Code: Select all

insert into t1 values ​​(:col1, :col2, :col3, :col4); 
then you can use

Code: Select all

ZQuery.ParamByName('col1').AsString(what ever) := 'Your value';
ZQuery.ParamByName('col2').AsString := 'Your second value';
.....
Also can you execute:

Code: Select all

ZQuery.SQL.Text := 'insert into t1 values ​​(:col1, :col2, :col3, :col4);'
ZQuery.Prepare;
ZQuery.ParamByName('col1').AsString(what ever) := 'Your value';
ZQuery.ParamByName('col2').AsString := 'Your second value';
....
ZQuery.ExecSQL;
ZQuery.ParamByName('col1').AsString(what ever) := 'Your value';
ZQuery.ParamByName('col2').AsString := 'Your second value';
....
ZQuery.ExecSQL;
ZQuery.ParamByName('col1').AsString(what ever) := 'Your value';
ZQuery.ParamByName('col2').AsString := 'Your second value';
....
ZQuery.ExecSQL;
ZQuery.Unprepare;
This should speed up the Paramerters IF the Plain drivers do support Real Prepared statements. (for MySQL you need to set TZQuery.Options := [doPreferePreparedResolver...])

Michael

Posted: 15.08.2012, 14:17
by elidorio2
ok,

Thank you;

Edson