I had problems in getting GUID on Mac, Windows and Linux
I found a solution:
[code]Function Method_Generate_GUID() As String
Dim db As New SQLiteDatabase
Dim Sql_instruction As String= "select hex( randomblob(4)) " _
- "|| ‘-’ || hex( randomblob(2)) " _
- "|| ‘-’ || ‘4’ || substr( hex( randomblob(2)), 2) " _
- "|| ‘-’ || substr(‘AB89’, 1 + (abs(random()) % 4) , 1) " _
- "|| substr(hex(randomblob(2)), 2) " _
- “|| ‘-’ || hex(randomblob(6)) AS GUID”
If db.Connect Then
Dim GUID As String = db.SQLSelect(Sql_instruction).Field(“GUID”)
Perhaps it might be helpful to someone else
Not sure if this is “fair” adding a comment to a 4 year old post – but it’s a little dissapointing there is no built in class for handling GUID/UUID. I see where people can generate them, but other “handling” operations for different versions of GUIDS are also “some assembly required”. I need to get the TIMESTAMP out of a Version 1 (date/time based GUID). I know the algorithm for generating that part of the GUID from a Mac/Linux EPOCH date. – this can be reversed so that the GUID can reveal the EPOCH date. – but there is no built in class. Bummer. in some environments you can just (Pseudo) Dim myGUID as new GUID. GUID.text = “b54adc00-67f9-11d9-9669-0800200c9a66” Dim myDate as Date = GUID.date. – Y’all are gonna make me code to accomplish this. People often need a GUID and it just strikes me as off that each and every person needs to learn the design and how to roll their own GUID class. This kind of lower level stuff pulls people away from “the big picture”. So happy that so many on the board here are willing to share what they’ve learned.
Why not make one in xojo directly?
Or use UUIDMBS class in MBS Plugin?
FYI, my M_Crypto, M_Text, and M_String modules all have this built in using system calls.
I’m accessing a database (not built by me) with tens of millions of rows…and for any given row…one of the things I need is a “date”. Turns out that the original database designers opted to include multiple dates within the database…but not the date I need. That particular date is encapsulated in the Version1 GUID. as the number of 100 nanosecond intervals since Oct 15th 1582 – Seriously? Ok…well that’s the official creation date of the Gregorian calendar. Anyway…once I discovered where the date I need was “stored” (embedded in the record ID) – there is a “built in method” on a GUID object in .Net to fetch it with complicated syntax like: guidObject.date — alas the implementation of a GUID class in Xojo is left to the programmers (or enterprising 3rd parties like Christian) to figure out. Ok, so really it’s not that complicated…a little bit of string manipulation and hex to Int64 with a constant adjustment for jan 1st 1900 and no problem. I’m just whining I had to do it. :-P. I think Christians class will generate Random type GUIDs (probably Type 4 or something) – but I didn’t have a choice over what kind of I needed to work with and the the glorious Idea of embedding a critical date field in the GUID.
bad bad bad bad bad … stuff like that always comes back to bite you in the ass
the dba who designed that should be shot
and left out in the desert for the vultures
ok spaghetti whipped at the very least