Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Codebook 2.0 duplicate IDs
Message
From
18/09/2000 12:33:57
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Codebook 2.0 duplicate IDs
Miscellaneous
Thread ID:
00417672
Message ID:
00417672
Views:
71
I'm beginning to generate duplicate ID's on an old FPW 2.6 application. The primary keys are created using the old codebook netid function which is based on julian dates and the seconds since midnight. When batch creating ID's on fast processors, duplicate keys get created. When I pause the routine using inkey() it creates unique ID's but the process slows dramatically even though I only use a fraction of a second intervals.

Did anyone come up with a fix for this routine. I know I can come up with a new algorithm, but then I would have to re-populate all of my existing primary keys (so I don't duplicate any existing ones) which I prefer not to do. Anyone have any ideas?

Tim

* Program...........: NETID.PRG
* Author............: Bill House
* Project...........: COMMON
* Created...........: 04/16/93 12:53:15
* Copyright.........: (c) Flash Creative Management, 1993
*) Description.......: Driver for ID generation. Uses no network I/O
* Calling Samples...: m.cID = NetID()
* Parameter List....:
* Major change list.:

* gcSession - Login session ID number generated by Next207().
* Set in TRAFICOP()
* lnPlaces - Time resolution for IDs. 0-3 (seconds to milliseconds).
* lnCodeLen - Time code length
* lnDCodeLen - Day code length
* ldSeedDate - Day to start counting days from using Julian daynumbers
ldSeedDate = {01/01/80} && Set day to start counting from
lnPlaces = 2 && Set time resolution to 1/100th of a second
lnCodeLen = 3 && Set time code length
lnDCodeLen = 2 && Set day code length

PRIVATE lcResult
lcResult = gcSession + ;
Dec2B207(VAL(SYS(1))-VAL(SYS(11,ldSeedDate)),lnDCodeLen) + ;
Dec2B207(TimeNum(lnPlaces),lnCodeLen)
RETURN lcResult

*------------------------------------------------------------------------

************************************************
FUNCTION Dec2B207
************************************************

*) Function..........: Dec2B207
* Author............: Bill House
* Project...........: COMMON
* Created...........: 04/16/93 13:09:17
* Copyright.........: (c) Flash Creative Management, 1993
*) Description.......: Converts a number or numeric string tnParm
*) : into base 207 code. Left pads the result with
*) : "0" chars to the length of param tnLen.
* Calling Samples...: lcCode = Dec2B207(lcNum,lnLen)
* Parameter List....: tnParm - number to be converted
* : tnLen - left-pad with "0" to this length if needed
* Major change list.:
PARAMETERS tnParm, tnLen
PRIVATE lnPower, lcArray, i, lcResult

* Convert to number if char parameter
IF TYPE("tnParm") = "C"
tnParm = VAL(tnParm)
ENDIF

* Size and declare work buffer
STORE 1 TO lnPower
DO WHILE tnParm / 207^lnPower >= 1
lnPower = lnPower + 1
ENDDO
DECLARE lcArray[lnPower]

* Convert decimal to base 207 number
FOR i = lnPower TO 2 step -1
lcArray[i] = INT( tnParm / 207^(i-1))
tnParm = tnParm - (lcArray[i] * 207^(i-1))
lcArray[i] = CHR(48+lcArray[i])
ENDFOR
lcArray[1] = CHR(48+tnParm)

* Initialize and build result variable
lcResult = ''
FOR i = lnPower TO 1 step -1
lcResult = lcResult + lcArray[i]
ENDFOR

* Format returned result
RETURN PADL(lcResult,tnLen,'0')

*------------------------------------------------------------------------

************************************************
FUNCTION TimeNum
************************************************

*) Function..........: TimeNum
* Author............: Bill House
* Project...........: COMMON
* Created...........: 04/16/93 13:13:14
* Copyright.........: (c) Flash Creative Management, 1993
*) Description.......: Returns seconds since midnight as a code
*) : with no decimal. If 200.123 seconds has
*) : passed and TimeNum(2) is called,
*) : 20012 will be returned.
* Calling Samples...: ? TimeNum(2)
* Parameter List....: tnPlaces - # of places to be moved
* Major change list.:
PARAMETER tnPlaces
PRIVATE lcResult
lcResult = LTRIM(STR(SECONDS(),10,3))
IF tnPlaces = 0
lcResult = LEFT(lcResult,AT('.',lcResult)-1)
ELSE
IF tnPlaces > 3
tnPlaces = 3
ENDIF
lcResult = SUBS(lcResult,1,AT('.',lcResult)-1)+;
SUBS(lcResult,AT('.',lcResult)+1,tnPlaces)
ENDIF
RETURN lcResult
Next
Reply
Map
View

Click here to load this message in the networking platform