Page 1 of 1

Stored procedure using "ORDER BY" and "auto-increment" columns

Posted: Tue 26 Jun 2007 17:38
by jackfirst72
If a MySQL table contains an auto-increment column, we are able to get it's new value after having done an "MyStoredProc.ApplyUpdates".
Example for an integer auto-increment column:

Code: Select all

...
MyStoredProc.Insert;
...
MyConnection.StartTransaction;
MyStoredProc.ApplyUpdates;
// here we can access the value of the auto-increment field, even if the transaction has not been completed yet
// MyIntValue := MyStoredProc.FieldByName('auto-inc-column-name').AsInteger;
...
MyConnection.Commit;
Now, if write into the stored procedure an "ORDER BY" at the end of the last SELECT that differs of the initial columns order, this features does not work anymore ! In fact, here the value of "MyStoredProc.FieldByName('auto-inc-column-name').AsInteger" is zero !!!

Maybe it's related to the "Update SQL" code generated in Delphi that must be re-generate after the "ORDER BY" has been added to the stored procedure ? No, I just tested that and it does not work either.

Any idea ?

Posted: Wed 27 Jun 2007 07:39
by Antaeus
Please specify the following information:
- exact version of MyDAC. You can see it in the About sheet of TMyConnection Editor;
- exact version of MySQL server and MySQL client. You can see it in the Info sheet of TMyConnection Editor.