Author: Bhavbhuti Nathwani
Posted: 2004-01-09 at 03:03:56
Quote: >>Oh, so you're using remote data. Normally the remote database
has its own method of key generation, such as autoincrement fields in
MySQL. In those cases, you don't generate the ID locally; you simply
commit the new record without a value in the ID field, and then call
the database server function that returns the ID of the last record
that was inserted. You can then replace the iID field of the local
record with that value.
I see from your DSN that you are using Firebird as your database. I
don't have any experience with that product, so I'll leave it to
others to fill in the specifics as to how to best do this with
Firebird.
Eureka, I just found out a fine place to put in such code:
iDataBhaviour.GetNextRemotePK()
<code>LPARAMETERS tcBaseTable
LOCAL lnConHnd, lnOldArea, luRetVal
*** we are overriding the parent logic
lnOldArea = SELECT(0)
lnConnHnd = CURSORGETPROP("ConnectHandle")
= SQLEXEC(lnConnHnd , [SELECT gen_id(GEN_] +
STRTRAN(tcBaseTable, "DBO.", "") +
[_ID, 1) AS nNextId from rdb$database])
luRetVal = VAL(sqlResult.nNextID)
SELECT (lnOldArea)
RETURN luRetVal</code>
Now the problem. If I have overridden i class, that means my personal
framework is now either VFP or FireBird for remote data.
How can I make it application wise, this time if not VFP FireBird,
next time if not VFP MySQL?
I wouldn't have known about this function if it had not created an
error by the default c-level code.