General information
Forum:
Microsoft SQL Server
Here is the code to create a GUID in VFP. Use it to generate your primary keys on client. There is also added benefit of saving a round trip to server by doing it this way.
Charlie
LOCAL lcOS
lcOS = OS(1)
IF 'NT' $ lcOS .or. 'Windows 5.00' $ lcOS
*- Windows NT
DECLARE INTEGER UuidCreate IN C:\Winnt\System32\RPCRT4.DLL ;
STRING @ UUID
ELSE
*- Windows 95\98
DECLARE INTEGER UuidCreate IN C:\Windows\System\RPCRT4.DLL ;
STRING @ UUID
ENDIF
*- Create a buffer
lcUUID = SPACE(16)
*- Generate the key
= UuidCreate(@lcUUID)
*- Convert the binaries to hex values
lcPart1 = BinAsHex(SUBSTR(lcUUID,1,4))
lcPart2 = BinAsHex(SUBSTR(lcUUID,5,4))
lcPart3 = BinAsHex(SUBSTR(lcUUID,8,4))
lcPart4 = BinAsHex(SUBSTR(lcUUID,13,4))
LOCAL lcRetVal
lcRetVal = lcPart1 + lcPart2 + lcPart3 + lcPart4
RETURN LEFT(lcRetVal,8) + "-" + SUBSTR(lcRetVal,9,4) + "-" + SUBSTR(lcRetVal,13,4) + "-" + ;
SUBSTR(lcRetVal,17,4) + "-" + RIGHT(lcRetVal,12)
PROCEDURE BinAsHex
PARAMETERS lcBin
*- Translates a binary string into character string of hex
LOCAL lcChars, lnBin
lcChars = ""
FOR lnDigit = 1 TO LEN(lcBin)
lnBin = ASC(SUBSTR(lcBin, lnDigit, 1))
lcChars = lcChars + Hex2Char(INT(lnBin/16)) + ;
Hex2Char(MOD(lnBin,16))
ENDFOR
RETURN(lcChars)
PROCEDURE Hex2Char
*- takes a hex digit value and returns a character from 0-9 & A-F
LPARAMETERS lnHex
DO CASE
CASE BETWEEN(lnHex,0,9) && 0-9 maps to numbers where asc 48 = '0'
lnAsc = 48 + lnHex
CASE BETWEEN(lnHex,10,15) && 10-15 maps to letters where asc 65 = 'A'
lnAsc = 65 + lnHex - 10
ENDCASE
RETURN(CHR(lnAsc))
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only