On 2016-03-10 11:22, mbsoftwaresolutions@mbsoftwaresolutions.com wrote:
It's *almost* 15 years, and I always used this function in my framework:
FUNCTION GetNewID(tiHandle as Integer) as Integer
- Retrieves newly created ID from MYSQL backend.
*** mjb 11/09/2011 - added here from Scheduler LOCAL liKey as Integer IF SQLEXEC(tiHandle,'SELECT @@IDENTITY as iNewKey',"curKey") = 1 THEN && retrieve PK from resulting cursor liKey = curKey.iNewKey IF VARTYPE(liKey) = "C" THEN liKey = VAL(liKey) ENDIF ELSE liKey = -1 ENDIF RETURN liKey ENDFUNC && GetNewID(tiHandle as Integer) as Integer
Wondering about the difference between last_insert_id() and SELECT @@IDENTITY? Researching later...
Got the answer (and see why it works): http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_i...
Identity: "This variable is a synonym for the last_insert_id variable. It exists for compatibility with other database systems. You can read its value with SELECT @@identity, and set it using SET identity."