Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Codebook 2.0 duplicate IDs
Message
From
18/09/2000 14:33:56
 
 
To
18/09/2000 12:33:57
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00417672
Message ID:
00417753
Views:
23
Tim:

There is nothing wrong with the NetID function except when you run it on anything much faster than a 386 <s>. There is a very simple way to handle this.

Take the standard NetID function and rename it something like NetID1. Then create a wrapper function called NetID. Create a public variable called "m.gcNetID". When you call the new NetID wrapper, it calls the original NetID (renamed NetID1). The return value from NetID1 is assigned to the public variable m.gcNetID. If the return value from NetID1 is the same as the value in m.gcNetID, you call NetID1 again and again until the return value is different to that contained in m.gcNetID. You then re-assign the different value from NetID1 to m.gcNetID and then return it to the calling process from the new NetID wrapper.

I hope I have explained myself clearly enough. It is very easy and works like a charm. If you have a problem with this, come back to me and I will provide the wrapper code. I use this in a very large, mission critical, production application. Remember that when you keep hitting NetID1 inside the wrapper NetID, that hit rate is happening in milliseconds and you just compare the return value to the public variable until it is different. No rewrite of NetID required at all.

HTH

>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
-=Gary
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform