Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is faster: insert from memvar or insert fields?
Message
From
25/07/2006 13:33:57
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01139366
Message ID:
01139827
Views:
15
>>>We're using GUID for PK, so they had to be calculated on each insert using SP. That's time spent, of course, but there is nothing I can do about it.
>>
>>To add to what Cetin said. If you have an army of PCs generating their own GUIDs that's got to be better than having 1 database server trying to generate GUIDs for everybody. It's like waiting for the subway versus taking a taxi.
>
>We didn't find a problem with application yet. The users work with the particular account and add one record in a time.
>
>For the long process such as LoadNewTRans I see the benefit of Cetin's idea.
>
>I haven't yet worked it out, was busy with some other stuff.
>
>Here is what we're using (hopefully no copyright is violated). Any ideas of speeding this up?
>
>*==============================================================================
>* Procedure:		GUID
>* Purpose:			Generates a Universally Unique 16 Character Binary Id
>* Author:			F1 Technologies
>* Parameters:
>* Returns:			lcGuid, the unique id
>* Notes:			If the results of this function are stored in a field the
>*					field should be a Character Binary field with a size of 16.
>* Added:			11/10/99
>*==============================================================================
>function GUID
>
>local lcGUID, lcString1, lcString2, lcString3, lcString4
>
>lcGUID = UUID()
>*--Convert the binaries to hex values
>lcString1 = BINTOHEX(substr(m.lcGUID, 1, 4))
>lcString2 = BINTOHEX(substr(m.lcGUID, 5, 4))
>lcString3 = BINTOHEX(substr(m.lcGUID, 9, 4))
>lcString4 = BINTOHEX(substr(m.lcGUID, 13, 4))
>
>lcGUID = m.lcString1 + m.lcString2 + m.lcString3 + m.lcString4
>
>lcGUID = left(m.lcGUID, 8) + ;
>	substr(m.lcGUID, 10, 4) + substr(m.lcGUID, 15, 4)
>
>return m.lcGUID
>
>endfunc
>
>*===========================================================================
>* End: GUID
>*===========================================================================
>
>*==============================================================================
>* Procedure:		BINTOHEX
>* Purpose:			Converts a binary string to character string of hex.
>* Author:			F1 Technologies
>* Parameters:		lcBin
>* Returns:			The converted character string
>*==============================================================================
>procedure BINTOHEX
>
>lparameters lcBIN
>
>local lcChars, lnBin, lnDigit
>
>lcChars = ""
>
>for lnDigit = 1 to len(m.lcBIN)
>	lnBin = asc(substr(m.lcBIN, m.lnDigit, 1))
>	lcChars = m.lcChars + ;
>		HEXTOCHAR(int(m.lnBin/16)) + ;
>		HEXTOCHAR(mod(m.lnBin,16))
>endfor
>
>return m.lcChars
>
>endproc
>*===========================================================================
>* End: BINTOHEX
>*===========================================================================
>
>*==============================================================================
>* Procedure:		HEXTOCHAR
>* Purpose:			Converts a hex number to a character
>* Author:			F1 Technologies
>* Parameters:		lnHex, the hex number
>* Returns:			lnHex
>*==============================================================================
>procedure HEXTOCHAR
>lparameters tnHex
>
>local lnAsc
>
>do case
>case between(m.tnHex,0,9)  && 0-9 maps to numbers where ASC48 = 'O'
>	lnAsc = 48 + m.tnHex
>
>case between(m.tnHex,10,15) && 10-15 maps tp letters where ASC65 = "A"
>	lnAsc = 65 + m.tnHex - 10
>
>endcase
>
>return (chr(m.lnAsc))
>
>endproc
>*===========================================================================
>* End: HEXTOCHAR
>*===========================================================================
>function UUID
>
>local lcUUID
>
>declare integer UuidCreate in rpcrt4.dll string @ UUID
>
>lcUUID = space(16)
>
>* Pass lcGUID to the UUIdCreate function
>UuidCreate(@lcUUID)
>
>return m.lcUUID
>
>endfunc
>*===========================================================================
>* End: UUID
>
Oh my! Good I asked to change your GUID generation.
* Try moving declaration into myGuid when you really have time to wait
Declare Integer UuidCreate In 'RPCRT4.dll' String @pguid
Declare Integer StringFromGUID2 In 'Ole32.dll' ;
  string rguid, String @lpsz, Integer cchMax

start = SECONDS()
FOR ix=1 TO 100000
	x=myGUID()
ENDFOR
? SECONDS()-m.start

FUNCTION myGUID
Local pGUID,rGUID

pGUID=Replicate(Chr(0),16)
rGUID=Replicate(Chr(0),80)

UuidCreate(@pGUID)
RETURN pGUID && 16 chars version - comment this and uncomment below for 38 version
*StringFromGUID2(pGUID,@rGUID,40)
*RETURN Strconv(Left(rGUID,76),6) && 38 chars version
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform