Page 1 of 1

Simple query

Posted: 11.04.2007, 17:13
by Yogrik

Code: Select all

ZReadOnlyQuery1.Active := false;
ZReadOnlyQuery1.SQL.Clear;
ZReadOnlyQuery1.SQL.Append('select Last_Insert_Rowid() as id;');
ZReadOnlyQuery1.Active := true;
id := qRwGeneral.FieldByName('id').AsInteger;
How to make easier???

Posted: 12.04.2007, 10:36
by pol
What is not easy here?
But what is qRwGeneral? Shouldn#t it be ZREadOnlyQuery1?
And with queries returning rows it is better to use Query.Close and Query.Open.

Posted: 12.04.2007, 14:20
by btrewern
I agree that it can't get much easier but if you are doing this often, you could create a function to do it. Also have you looked at the TZSequence component? It could be useful for this but I'm not sure what databases it supports.

BTW Query.Open is completely equivalent to Query.Active := True;

Ben

Posted: 13.04.2007, 08:15
by pol
OK Ben that is true. But there have been many people who where confused with open/close and execute. So as a rule of thumb I say: when the query retorns rows: open/close, when not: execute.

RĂ¼diger