Simple query

Forum related to SQLite

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
Yogrik
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 11.04.2007, 16:30

Simple query

Post 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???
pol
Senior Boarder
Senior Boarder
Posts: 91
Joined: 13.10.2005, 08:19

Post 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.
btrewern
Expert Boarder
Expert Boarder
Posts: 193
Joined: 06.10.2005, 18:51

Post 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
pol
Senior Boarder
Senior Boarder
Posts: 91
Joined: 13.10.2005, 08:19

Post 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
Post Reply