I am looking to store a GUID in my SQLite database using C # and python clients.
Creating a database and inserting a string, saving the GUID as a string:
conn = sqlite3.connect(filename) c = conn.cursor()
Fetching:
# ... c.execute('SELECT * FROM test WHERE guid = "c1332103-6031-4ff7-b610-f8f3b940fa66"') print c.fetchone()
Everything works perfectly. Using the default Python __str__
view for UUIDs works well.
C:\Users\Jonathon>makedb.py test.db c1332103-6031-4ff7-b610-f8f3b940fa66 C:\Users\Jonathon>opendb.py test.db (u'c1332103-6031-4ff7-b610-f8f3b940fa66', u'foo')
My doubts arise due to the use of SQLite Expert . It seems that SQLite Expert is pleased with the declaration of the GUID data type:
But if I edit the line:
it seems like it is changing the data type! My SELECT
with a crop of None
, and if I SELECT *
, I see that this is no longer a simple Unicode string:
C:\Users\Jonathon>opendb.py test.db (<read-write buffer ptr 0x02239520, size 16 at 0x02239500>, u'foo')
Looking at the data on the disk, you can see that the GUID is stored in binary format after SQLite Expert touched it:
Before - GUID is ASCII text:
After - the previous data is garbage, and there is a binary version of the GUID:
So, what is the “right” way to store GUIDs in SQLite, specifically using Python? Later I will have C # code interacting with this, and also want me to do things “correctly”.