Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Generate Version 1 UUIDs
Message
De
19/09/2017 10:10:16
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
19/09/2017 04:18:52
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
SAMBA Server
Database:
MySQL
Application:
Desktop
Divers
Thread ID:
01654423
Message ID:
01654432
Vues:
87
This message has been marked as the solution to the initial question of the thread.
>Hi Experts,
>
>For the longest time, I have been using CoCreateGuid and StringFromGUID2 to generate GUIDs. Problem with this is, whenever one simply does "select * from customer" from a MySQL Server, it does not show the customer rows in its sequential order of creation/insertion. I either need to add a column that is autoinc in nature to enforce sequential behavior.
>
>If one calls or invokes the UUID() of MySQL (or PHP), these GUID values can be spliced and reorganized to make the inserted rows sequential. This is possible due to the fact that the GUIDs they produced are of type "version 1", wherein the 4th and 5th segments are fixed. I won't be needing the added overhead of creating autoinc columns.
>
>This cannot be done however when one uses CoCreateGuid and StringFromGUID2 as the GUIDs they give are of type version 4 - wherein each segment is totally random.
>
>Aside from making a call to a MySQL server, "select uuid()" to populate my primary keys, is there another way to do this "natively"? Needless to say, this will save me a trip to the server.
>
>Thanks In Advance.

IMHO when the backend is not VFP, you shouldn't rely on insertion order and explicitly order by some column if you ever want the result ordered. Second, you shouldn't create clustered indexes for the primary key when the key is a GUID (I don't know if MySQL has it or if it has what it is called there-data is inserted in the order of the key and is default for primary keys unless otherwise specified).

Having said that, here is a code that use UuidCreateSequential instead:
*uniqueIDSequential.prg
Declare Integer CoCreateGuid In 'OLE32.dll' ;
  string @pguid
Declare Integer StringFromGUID2 In 'OLE32.dll' ;
  string rguid, String @lpsz, Integer cchMax
Declare Integer UuidCreateSequential In 'RPCRT4.dll'  String @ Uuid

Local pguid,rguid, lcOldError, lnResult
pguid=Replicate(Chr(0),16)
rguid=Replicate(Chr(0),80)
lcOldError = On('error')
On Error lnResult = CoCreateGuid(@pguid)
lnResult = UuidCreateSequential(@pguid)
On Error &lcOldError
Return ;
  Iif( InList(m.lnResult,0,1824) And ;
  StringFromGUID2(pguid,@rguid,40) # 0, ;
  StrConv(Left(rguid,76),10), "" )
Ç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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform