Why does GetInsertID always return 0? lazarus / 16-Databases ---------------------------------------------------------------------- kinlion · 2019-01-11 01:36 Hi, guys, I'm using TMySQL56Connection, connect to a MariaDB server,  which version is 10.2.18-MariaDB-10.2.18+maria~xenial-log. Everything is OK except when I trying to get last insert id. I insert a record, then if I using a query 'select last_insert_id()', the result is correct. But if I use TConnectionName(TheQuery.Database).GetInsertID, it returns 0. What's wrong? ---------------------------------------------------------------------- madref · 2019-01-16 09:19 this is an assumption. But if Last_ID is auto generated it is also the Max_ID. Can't you try and get that one? ---------------------------------------------------------------------- Leledumbo · 2019-01-17 09:38 I dig in the implementation, it seems correct, but I'm on trunk. No idea if it was already implemented in stable. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // $(fpcsrc)/packages/fcl-db/src/sqldb/mysql/mysqlconn.inc:378Function TConnectionName.GetInsertID: int64;begin  CheckConnected;  Result:=mysql_insert_id(GetHandle);end; ---------------------------------------------------------------------- kinlion · 2019-01-18 01:24 Quote from: madref on January 16, 2019, 10:19:45 amthis is an assumption. But if Last_ID is auto generated it is also the Max_ID. Can't you try and get that one? Max_ID maybe not what I want if multiple connections do Insert at same time. ---------------------------------------------------------------------- kinlion · 2019-01-18 01:28 Quote from: Leledumbo on January 17, 2019, 10:38:29 amI dig in the implementation, it seems correct, but I'm on trunk. No idea if it was already implemented in stable. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // $(fpcsrc)/packages/fcl-db/src/sqldb/mysql/mysqlconn.inc:378Function TConnectionName.GetInsertID: int64;begin  CheckConnected;  Result:=mysql_insert_id(GetHandle);end;  Yes, I also see the implementation. I think there must be some bad code in my project because I have used it before, and the result was right. Now, I use 'select last_insert_id()'. I will dig it when have time. Thanks Leledumbo