Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Primary Key with one to many Form
Message
De
16/07/2001 10:23:03
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00530359
Message ID:
00530988
Vues:
18
This message has been marked as a message which has helped to the initial question of the thread.
Basically correct. But you should also:

  • Use lock() / rlock() to avoid conflicts (two users trying to create the same PK-value at the same time).
  • Instead of closing the table, keep it open - this is much faster.
    if not used("ids")
      use ids in 0
    endif
    select ids
  • Make sure you return to the previously SELECTed area.
  • Instead of notifying the user that a specific sequence doesn't exist, you can create it.
  • A single parameter should be enough for most operations: the name of the sequence.

    Here is my own version of the function:
    **********************************************************************
    FUNCTION SERIALNUMBER(tnSequence)
    	* 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.
    	tnSequence = lower(tnSequence)
    	local lnSelect
    	lnSelect = select()
    	if used("serialnumber")
    		select serialnumber
    	else
    		select 0
    		use serialnumber
    	endif
    	set order to "sequence"
    	seek padr(tnSequence, len(sequence))
    	if not found()
    		append blank
    		replace sequence with tnSequence, 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
    Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
  • Précédent
    Suivant
    Répondre
    Fil
    Voir

    Click here to load this message in the networking platform