I made a small utility class in Xojo that generates RFC 4122-compliant UUID v4 values.
Nothing fancy, but it might be useful if you need unique identifiers for things like databases, files, API keys, etc.
It supports:
Standard hexadecimal format (with or without hyphens)
I ran a test on a Mac Mini M2 Pro — this class takes 11 seconds to generate one million UUIDs, which I think is more than fast enough. Also, just because something looks more complex doesn’t mean it’s more efficient or robust — nothing beats simplicity.
I don’t understand why we should make it more complicated than that…
I didn’t. I don’t typically use it this way. I include SELECT next FROM uuid7 in my database insertion statements to generate row IDs using UUIDv7 values. Thought it would make a fun and interesting contribution, though.
Here’s an example of using it in a query and returning the generated UUIDv7 ID value:
Private Function writeName(name as String) As String
var rs as RowSet = db.SelectSQL( "INSERT INTO names (id, name) VALUES ((SELECT next FROM uuid7), ?) RETURNING id;", name )
if rs <> nil and rs.AfterLastRow = False then Return rs.Column( "id" ).StringValue
End Function
names table schema:
CREATE TABLE "names" ("id" TEXT PRIMARY KEY NOT NULL UNIQUE, "name" TEXT NOT NULL)
Just extract the SQL from the kTrigger constant and add that view to your database. Used in this way, it may be faster than generating the UUID in Xojo code then inserting the row as everything is offloaded to the DB.