2 messages in com.mysql.lists.win32Re: Delphi and mySQL AUTOINCREMENT
FromSent OnAttachments
ian_...@tiscali.co.uk22 Jul 2004 07:15 
Petr Vileta22 Jul 2004 18:00 
Subject:Re: Delphi and mySQL AUTOINCREMENT
From:Petr Vileta (pe@practisoft.cz)
Date:07/22/2004 06:00:28 PM
List:com.mysql.lists.win32

I am using Delphi 5 and 7. When I post a new record into a table which is keyed on an autoincrement field I do not get a result set back telling me the number the server has allocated to the record.

I am using a TQuery component to execute the SQL statement. Are there any way to retrieve the result set back on posting? I have checked all associated properties, methods and events etc... but nothing seems to work.

Immediately after insert you must to run query

SELECT last_insert_id();

and read result. But remeber that the value is valid IMMEDIATE after insert only, before other query.