On SQL server the keys are kept in a table. The stored procedure just increments the key, then returns it to the client. You'll want wrap this in a transaction of better isolation. On the client side, I just increment an Appication property that holds an integer.
*- Client Code
*- Returns a new key
FUNCTION GetKey
LOCAL lnKey
oCMIS.lowkey = oCMIS.lowkey + 1
lnKey = ALLTR(STR(oCMIS.hikey)) + ALLTR(STR(oCMIS.lowkey))
RETURN VAL(lnKey)
*- Stored Procedure call at application startup that gets highkey
*- Took out error handling for clarity
lnKey = 0
= SQLEXEC(oCMIS.ConHandle, 'BEGIN TRANSACTION')
= SQLEXEC(oCMIS.ConHandle, '{CALL spGetNextHiKey(?@lnKey)}')
= SQLEXEC(oCMIS.ConHandle, 'COMMIT')
oCMIS.HiKey = lnKey
oCMIS.LowKey = 0
*- SQL Server Stored procedure that returns high key
*- Counters is table that holds key
CREATE PROCEDURE spGetNextHiKey(
@retval int = null OUTPUT)
AS
update Counters set nxthighkey = nxthighkey + 1
set @retval = (select nxthighkey from Counters)
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only