Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique key generator
Message
De
05/01/2000 05:24:59
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
04/01/2000 19:00:47
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00312803
Message ID:
00313091
Vues:
35
>>>Hi,
>>>
>>>I'm using this function to get unique ID numbers for various files. The "SYSTEM" file contains one record with several fields of unique numbers.
>>>
>>>A typical call to the function looks like this:
>>>
>>>cOrderID = NextNumber( "NxtOrderNo", 10 )
>>>
>>>The problem is I'm getting duplicate order numbers!!!
>>>
>>>Can anyone spot the reason why this might happen?
>>>
>>>Here's the function:
>>>
>>>
>>>    *-------------------------------------------------
>>>FUNCTION NextNumber
>>>    * get the next incremental number for the passed field, padded with
>>>    * leading zeros
>>>
>>>    PARAMETER cField,nLen
>>>
>>>    cOldAlias = ALIAS()
>>>    lUsed = USED( "System" )
>>>    IF ! lUsed
>>>        USE SYSTEM IN 0
>>>    ENDIF
>>>    SELECT SYSTEM
>>>    lDone = .F.
>>>    DO WHILE ! lDone
>>>        IF FLOCK()
>>>            nReturnNum = &cField
>>>            REPLACE &cField WITH &cField + 1
>>>            cReturnNum = PADL( nReturnNum, nLen, '0' )
>>>            UNLOCK
>>>            lDone = .T.
>>>        ELSE
>>>            INKEY(.5)
>>>        ENDIF
>>>    ENDDO
>>>    IF ! EMPTY( cOldAlias )
>>>        SELECT (cOldAlias)
>>>    ENDIF
>>>    IF ! lUsed
>>>        USE IN SYSTEM
>>>    ENDIF
>>>    RETURN cReturnNum
>>>
>>>
>>>
>>>TIA
>>
>>You might want to make sure there is no buffering enabled for this particular table.
>
>I'm using a framework (Visual ProMatrix) so I wasn't sure of the buffering...
>
>MULTILOCKS is ON but I added a TABLEUPDATE() to the code and got the message "Function requires row or table buffering mode"... does this mean buffering is not on?
>
>TIA


Larry,
Pardon me for jumping in. If you're using VPM then you could use S_Prefix_CGPK(-1) to generate unique integer keys. If what you want is unique 10 char character value then I suggest using sys(2015) instead. You could combine it with a station id to make completely unique on a network (keep a table holding netbios names of stations -sys(0)- and prefix the sys(2015) with particular stations record) :
* Stations.dbf
*Netbios_name c(30) - indexed with tagname stationid
function GenerateKey
if !used("Stations")
  use stations in 0
endif
if !seek(sys(0), "stations","stationid")
 insert into stations (Netbios_name) values (sys(0))
endif
lcRetVal = bintoc(recno("stations")-128,1)+substr(sys(2015),2)
return lcRetVal
BTW VPM doesn't set buffering on for tables by default (but it sets buffering to 2 at form level).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform