UUID on INSERT TRIGGER

  1. 7 weeks ago

    Dave S

    Jul 3 San Diego, California USA
    Edited 7 weeks ago

    Each record in a table must have a field with a UUID... .this value would be assigned when the record was first created (ie. INSERT INTO table)
    I have a trigger that already sets the createDate to "now", but is there a way I can create/insert a UUID also?

    I don't think SQLite has any UUID functions.... and right now I am manually adding a generated value into the INSERT SQL statement.
    but letting a trigger do it would be much easier,

    Orignially I was going to use UUID as the relation key between tables... but another required function (data Import/Export) require that those keys be <20 characters and UUID is 36

  2. Norman P

    Jul 3 Pre-Release Testers, Xojo Pro great-white-software.com/blog
    Edited 7 weeks ago

    Sure yu can get sqlite to generate a GUID for you

    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 ;

or Sign Up to reply!