select last_insert_id() returns always 0
Posted: 01.11.2008, 08:12
Hi,
I am developing a app with Delphi 2007 using ZEOS 6.6.3 stable and MySQL 5. I use 7 tables to store data, on 6 of them using last_insert_id() to retrieve the auto_increment id of the last inserted row works as expected, but on one table it does not. I receive allways 0 (zero) as result using >select last_insert_id()<. I have tried several versions to exec this statement, no success.
Code snipped:
qrMain.SQL.Clear;
qrMain.SQL.Text := 'insert into clients (WsName, WsSettings) ' +
' values (:WsName, :WsSettings);';
qrMain.Params.ParamByName('WsName').AsString := R.Mp3ClName;
qrMain.Params.ParamByName('WsSettings').SetBlobData(@D, SizeOf(D));
qrMain.ExecSQL;
qrMain.SQL.Text := ('select last_insert_id() as `clientId`;');
qrMain.Open;
R.ClientID := qrMain.FieldByName('clientId').AsInteger;
I use the same code in all of my tables (adapted to the table row data fields), except one table it works as expected and retuns the id of the last inserted row.
I tested the SQL statements with the command line client on my SQL Server (SLES 10.1) with success. I turned on the debug log on the server to see if the connection from client to server is interupted, this is not the case, all SQL commands my app is executing via ZEOS receives the server ...
Any help and directive to solve the problem is appreciated.
P.S.
I am resident in Upper Austria and would warmly welcome Delphi / ZEOS Developer(s) to contact me via Skype. I am new to SQL / ZEOS and sometimes it would be helpfull not only to have a forum but also be able to talk to some expirienced people(s) about problems and so on.
Regards
Werner
I am developing a app with Delphi 2007 using ZEOS 6.6.3 stable and MySQL 5. I use 7 tables to store data, on 6 of them using last_insert_id() to retrieve the auto_increment id of the last inserted row works as expected, but on one table it does not. I receive allways 0 (zero) as result using >select last_insert_id()<. I have tried several versions to exec this statement, no success.
Code snipped:
qrMain.SQL.Clear;
qrMain.SQL.Text := 'insert into clients (WsName, WsSettings) ' +
' values (:WsName, :WsSettings);';
qrMain.Params.ParamByName('WsName').AsString := R.Mp3ClName;
qrMain.Params.ParamByName('WsSettings').SetBlobData(@D, SizeOf(D));
qrMain.ExecSQL;
qrMain.SQL.Text := ('select last_insert_id() as `clientId`;');
qrMain.Open;
R.ClientID := qrMain.FieldByName('clientId').AsInteger;
I use the same code in all of my tables (adapted to the table row data fields), except one table it works as expected and retuns the id of the last inserted row.
I tested the SQL statements with the command line client on my SQL Server (SLES 10.1) with success. I turned on the debug log on the server to see if the connection from client to server is interupted, this is not the case, all SQL commands my app is executing via ZEOS receives the server ...
Any help and directive to solve the problem is appreciated.
P.S.
I am resident in Upper Austria and would warmly welcome Delphi / ZEOS Developer(s) to contact me via Skype. I am new to SQL / ZEOS and sometimes it would be helpfull not only to have a forum but also be able to talk to some expirienced people(s) about problems and so on.
Regards
Werner