Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generating id....
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00334247
Message ID:
00334270
Vues:
28
here is the function i used: (i didn't write it, i got it from a book, can't remember which one)

put in the stored procedures:

function getkey(pcTableName)
* pcTableName is the name of the table that we want a PK for
* Check for a character parameter
IF TYPE("pcTableName") <> "C"
* Invalid parameter
RETURN 0
ENDIF
pcTableName = UPPER(pcTableName)
* Save the environment
LOCAL lcAlias, liReturn
lcAlias = ALIAS()
IF NOT USED("nextkey")
SELECT 0
USE nextkey
ELSE
SELECT nextkey
ENDIF
LOCATE FOR cTableName = pcTableName
IF NOT FOUND()
* No record for this table
APPEND BLANK
REPLACE inextkey WITH 1, cTableName WITH pcTableName, iidkey with 0
liReturn = 0
ENDIF
* Lock the record
DO WHILE NOT RLOCK()
* Short delay
INKEY(.02,"H")
ENDDO
* Get the PK
liReturn = inextkey
* Update the inext_key field
REPLACE inextkey WITH inextkey + 1
UNLOCK
IF NOT EMPTY( lcAlias )
SELECT ( lcAlias )
ELSE
SELECT 0
ENDIF
RETURN liReturn
ENDFUNC

then create a table, 'nextkey', with three fields:
iidkey, int, 4
ctablename, char, 128
inextkey, int, 4

then put getkey(name_of_table), in the default value of the id field.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform