Convert UUID to BINARY(16) for storage

(NOT a database question, so please hang on)

I’m having some cross-dbase compatibility issues with built-in dbase functions for generating and storing a UUID. So I want to create my own UUID, convert it to BINARY(16), and insert it accordingly, e.g.,

some_id BINARY(16) PRIMARY KEY

With a UUID String in Xojo, (e.g., “EF2D3D66-3A95-4247-A3C2-EA2CBC99784B”) what is the easiest way to convert to BINARY(16) for storage in database?

---- in case you want to know the dbase incompatibility —

MySQL supports ‘UUID_TO_BIN’ for conversion during insert, but MariaDB doesn’t support this. Thus I need to create the UUID, convert it to BINARY(16), prior to insert.

Strip the dashes and use DecodeHex on the result to get the actual bytes.

1 Like

As you are creating your own, why not create it directly in binary not needing to convert, as the RFC defines?

Later, needing the hex string you create an UUID.ToString()

Hi @Rick_Araujo , one challenge is storing UUID’s from other sources. For instance, a GUID from an object imported from a WebService - a GUID produced elsewhere, but needing to be stored and referenced locally. Thanks for the pointer to the standard by the way :+1:t2:

1 Like

This is certainly straightforward - thx!