Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Autoincrementing number on table
Message
 
 
À
01/07/2005 09:45:40
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP1
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01028122
Message ID:
01028267
Vues:
12
>>I am trying to create a table of users for my application. I have 2 fields one named userno and one named username. How can I automatically create the usernumber when creating the user. therefore autocrement the number by one each time. Is this possible?
>
>In VFP 8 and later there is an autoincremental field.
>
>To have more control (or for older versions), you can use a sequence function, that stores the sequences in a separate table. Here is my function, which I store in the DB stored procedures; you will need to create the table too:
>
>
>**********************************************************************
>FUNCTION SerialNumber(tcSequence)
>	* Get serial number. Used mainly to generate primary keys.
>	* The easiest way to achieve this is to call this function from a fields default value.
>	* Example: default value for primary key "Client" of table "Client" = SerialNumber("Client")
>	* This function accesses table SerialNumber. Fields: Sequence C(30), NextNum I.
>	tcSequence = lower(tcSequence)
>	local lnSelect
>	lnSelect = select()
>	if used("serialnumber")
>		select serialnumber
>	else
>		select 0
>		use serialnumber
>	endif
>	set order to "sequence"
>	seek padr(tcSequence, len(sequence))
>	if not found()
>		append blank
>		replace sequence with tcSequence, nextnum with 1
>	endif
>	local lnReturnValue
>	if lock()
>		lnReturnValue = nextnum
>		replace nextnum with nextnum + 1
>	else
>		lnReturnValue = -1
>	endif
>	unlock
>	select (lnSelect)
>	return lnReturnValue
>ENDFUNC
>
What is lock(), I think, it should be rlock(). How do you handle -1?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform