MySQL - INSERT and SELECT in same component

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
ManUtdFans
Fresh Boarder
Fresh Boarder
Posts: 23
Joined: 23.06.2010, 05:33

MySQL - INSERT and SELECT in same component

Post by ManUtdFans »

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.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

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