jeudi 10 mars 2016

How can we store a GUID in SqliIte?

As Datatype Guid is not allowed in Sqllite Db, what is the best alternate datatype for saving Guid in Sqlite dB? Also How can I generate a newGuid in SqlLite db?

Below is my code to generate Guid in sqlite

select substr(u,1,8)||'-'||substr(u,9,4)||'-4'||substr(u,13,3)||
  '-'||v||substr(u,17,3)||'-'||substr(u,21,12) from (
    select lower(hex(randomblob(16))) as u, substr('89ab',abs(random()) % 4 + 1, 1) as v);

Is this a right method? Is this will be globally unique?

Aucun commentaire:

Enregistrer un commentaire