On 2016-03-10 11:22, [email protected] 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_identity

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."

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to