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)
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement