On 30 May 2017, at 6:30pm, t682993 <gerard.coppej...@telenet.be> wrote:

> I am testing sqlite and find it very versatile and good.
> I am just missing 1 thing: from a table column i would like that the 
> sql-engine could generate new UUID or GUID per row. format 
> XXXXXXXX-XXXX-4XXX-XXXX-XXXXXXXXXXXX.
> I have the c-source files of the function.
> Could you integrate this new type of column in the engine and could i define 
> it as a Primary Key ?

Using your C code, you can create an external function to SQLite which 
generates the new UUID.  You can then have SQLite use this function when 
inserting a new row, or make the function a DEFAULT value for the column.

<https://sqlite.org/c3ref/create_function.html>

<https://stackoverflow.com/questions/7867099/how-can-i-create-a-user-defined-function-in-sqlite>

<https://stackoverflow.com/questions/9035649/bitmask-grouping-using-sqlite>

You can then do

        INSERT INTO MyTable VALUES (NULL, makeNewUUID(), 'Lenny')

Or

        CREATE TABLE MyTable(id INTEGER PRIMARY KEY,
                             uuid TEXT DEFAULT makeNewUUID(),
                             name TEXT);

(At least I think you can use external functions as defaults.  Can’t check it 
right now.)

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to