Page 1 of 1

MySQL - INSERT and SELECT in same component

Posted: 23.06.2010, 06:47
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.

Posted: 29.08.2010, 21:19
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