Is it possible to put INSERT followed by SELECT SQL statement into the SQL.Text property of TZQuery component?
I got a table has auto-incremented as primary key.
I want to insert a new record and get the last insert id from the table.
MySQL - INSERT and SELECT in same component
Moderators: gto, EgonHugeist
-
- Fresh Boarder
- Posts: 23
- Joined: 23.06.2010, 05:33
- mdaems
- Zeos Project Manager
- Posts: 2766
- Joined: 20.09.2005, 15:28
- Location: Brussels, Belgium
- Contact:
I wouldn't advise to do it in one query execution.
Just do the insert statement with the execsql method of the tzquery and then Open after setting the SQL.Text to 'select last_insert_id...'
But it much depends on what you try to do, because when you use the automatic update methods of tzquery/tztable the autoinc values of newly inserted records is retrieved automatically.
I don't know why you have to write the insert stratements manually. (I hope it's not a way to update/insert into a table you're showing in another dataset?)
Mark
Just do the insert statement with the execsql method of the tzquery and then Open after setting the SQL.Text to 'select last_insert_id...'
But it much depends on what you try to do, because when you use the automatic update methods of tzquery/tztable the autoinc values of newly inserted records is retrieved automatically.
I don't know why you have to write the insert stratements manually. (I hope it's not a way to update/insert into a table you're showing in another dataset?)
Mark