SQLite UUID extension
For the MBS Xojo SQL Plugin 25.5, we add a few extensions and include UUID, Base64 and CSV. The uuid extension allows us to make an uuid in a SQL query as the extension adds these functions:
uuid() | generate a version 4 UUID as a string |
uuid_str(X) | convert a UUID X into a well-formed UUID string |
uuid_blob(X) | convert a UUID X into a 16-byte blob |
Let's use this in an example project:
We activate our internal SQLite library via InternalSQLiteLibraryMBS module and turn on the extensions we need like, in our case the UUID one:
Next we connect to an in-memory database in this example. But if you use a real file path, it will open a file on disk. If connect doesn't report an error, we have an open database:
The decision which extensions register into a SQLite connection is made at the Connect call. You can enable extensions just before and disable them after to avoid having them available in other connections. Or you just enable all extensions you may need in app.Opening event.
Next we test the uuid() function and show the uuid in a dialog:
Time to create our sample table. We use the uuid as primary key and let SQLite automatically calculate a new row id each time a record is created. Please note that we need to provide the default in brackets, so SQLite knows where to start and end when parsing the statement.
When we insert rows, we just pass data. The id column is calculated automatically.
Now we query the table and add rows to a ListBox:
Finally we can use our new DumpToStrings function to dump the content of the database as SQL commands. This allows you to recreate the database again later or to take the SQL statements and e.g. move to MySQL to recreate it there.
Please try the new uuid function and let us know if you need other extensions.