So I'm writing a script in Python(2.7) that converts files and then stores the results in a SQlite DB.
For the Primary key I'm using the last 29 bytes of the file(as it contains a unique identifier). The problem is these unique identifier's contain null btyes(x00) so when I try to insert "40 00 00 00 00 00 00 00 00 3F F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 05
" it just ends up as "40
"(@
).
How can I get SQlite to stop truncating this? I've tried to use the TEXT
, BLOB
, NULL
, NONE
, and sqlite3.binary
(when inserting) but all return just "@
".
Below is the statement I use for inserting and the test table I'm working with.
CREATE TABLE files (id blob PRIMARY KEY);
cur.execute("INSERT INTO files (id) VALUES (?)", (sqlite3.binary(tid), ))
EDIT: Okay so I'm just an idiot... it's all there I just never thought to SELECT statement it because in sqlite3 CLI it just looked like a "@"...(temp.txt contains just the last 29 bits of a file)
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> conn = sqlite3.connect('kp_trans.db')
>>> cur = conn.cursor()
>>> with open("temp.txt", 'rb') as f:
... cur.execute("SELECT * FROM files WHERE id = ?", (sqlite3.Binary(f.read()), ))
... for row in cur:
... print row[0]
...
<sqlite3.Cursor object at 0x02346920>
@ ?≡ ☺ ♣
>>>