Answer the question
In order to leave comments, you need to log in
How to add file to BLOB in sqlite(python)?
I read somewhere that BLOB files are stored simply in hex. Accordingly, I converted the file I needed to hex, tried to insert it into a BLOB and got an error:
file = open(f'/Users/vladimirkorsunov/Downloads/bot_pdf/{pdf_file_id}.pdf', 'rb')
bin_file = file.read()
hex_file = binascii.hexlify(bin_file)
conn = sqlite3.connect("orders_list.db")
c = conn.cursor()
c.execute(f"INSERT INTO orders (student_id, subject, pdf_file, exercises, price) VALUES ({student_id}, '{subject}', {hex_file}, '{exercises}', {price})")
conn.commit()
(printf "INSERT INTO test(id, name, blob_field) VALUES(NULL, 'Bob', 0x" ; \
hexdump -v -e '/1 "%02x"' 001.png ; printf ");" ) | sqlite3 my.db
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question