Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Making surrogate keys, the Tastrade way
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Making surrogate keys, the Tastrade way
Divers
Thread ID:
00053840
Message ID:
00053840
Vues:
89
I need to receive more wisdom from all you surrogate key experts out there. What do you think of the Tastrade sample app's way of making them? That is, apart from the fact that it uses a character field, which is easy enough to change. To refresh our memory, the Tastrade database has a table called "setup" whose fields are the names of tables having keys, and the next unused value for each key. The primary key of each table has a default value newid(), which is a stored procedure that looks like this:

FUNCTION NewID(tcAlias)
LOCAL lcAlias, ;
lcID, ;
lcOldReprocess, ;
lnOldArea

lnOldArea = SELECT()

IF PARAMETERS() < 1
lcAlias = UPPER(ALIAS())
ELSE
lcAlias = UPPER(tcAlias)
ENDIF

lcID = ""
lcOldReprocess = SET('REPROCESS')

*-- Lock until user presses Esc
SET REPROCESS TO AUTOMATIC

IF !USED("SETUP")
USE tastrade!setup IN 0
ENDIF
SELECT setup

IF SEEK(lcAlias, "setup", "key_name")
IF RLOCK()
lcID = setup.value
REPLACE setup.value WITH ;
STR(VAL(ALLT(lcID)) + 1, LEN(setup.value))
UNLOCK
ENDIF
ENDIF

SELECT (lnOldArea)
SET REPROCESS TO lcOldReprocess

RETURN lcID
ENDFUNC

<\pre>

Does it look secure? I'll probably do it this way unless someone sees a problem. Thank you.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform