[Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)
Reimar Grabowski
reimgrab at web.de
Sat Nov 15 03:20:50 CET 2014
On Fri, 14 Nov 2014 19:23:50 +0100 (CET)
Michael Van Canneyt <michael at freepascal.org> wrote:
> a) Did you do an insert right before the call to GetInsertID ?
> b) Is the transaction active after the insert ?
> c) The connection transaction should be the same as the transaction of the insert.
Got it working.
MySQL55Connection1.Connected:=True;
SQLTransaction1.Active:=True;
SQLQuery.Active:=True;
SQLQuery.Insert;
SQLQuery.FieldByName(...);
...
SQLQuery.Post;
SQLQuery.ApplyUpdates;
writeln('ID1: ', MySQL55Connection1.GetInsertID);
SQLTransaction1.Commit;
writeln('ID2: ', MySQL55Connection1.GetInsertID);
SQLQuery1.Open;
writeln('ID3: ', SQLQuery1.FieldByName('LastInserID').AsLargeInt);
ID1 and ID3 are correct but ID2 = 0
So GetInsertID works only before the commit.
Thanks
R.
More information about the Lazarus
mailing list