Search code examples
sqlsqliteguidsql.js

SELECT GUID using sql.js returns no result


I am trying to return a specific row of my sqlite table by using its GUID.

The table "Reference" is defined as

CREATE TABLE "Reference" ( `ID` GUID, [...], PRIMARY KEY(`ID`) )

When returning all rows via SELECT ID FROM Reference I get the GUID values as comma-separated decimals (plus one number (probably zero) is missing, the one before the last block), e.g. one of my result GUIDs is 20,129,73,9,133,47,79,7,80,130,247,254,95,40,35,29.

Now, if I try to select the whole row using this GUID, I don't get any result.

Example query:

SELECT * FROM Reference WHERE ID = '20,129,73,9,133,47,79,7,80,130,247,254,95,40,35,29'

Further, I already tried converting the decimals to hex or ascii values and used them instead - without success though.


Solution

  • It looks like the GUIDs are stored as 16-byte blobs, and that JavaScript code is converting them to an array of integers representing the bytes. But the syntax that SQLite uses for blob literals is an X-prefixed hex string, like this:

    SELECT * FROM Reference WHERE ID = X'14814909852F4F075082F7FE5F28231D'