1

How can I add image file, for example, with name '001.png' to sqlite3 database using its command prompt?

sqlite3> INSERT INTO test (id, name, blob_field) VALUES (NULL, 'Bob', ?????);

2 Answers 2

1

Depending on the OS you're using, you could convert the file into a hexdump and use that to construct an SQL command with a blob literal:

(printf "INSERT INTO test(id, name, blob_field) VALUES(NULL, 'Bob', 0x" ; \
 hexdump -v -e '/1 "%02x"' 001.png ; printf ");" ) | sqlite3 my.db
Sign up to request clarification or add additional context in comments.

Comments

0

Use hex literal like 0x123456789abcdef

so

INSERT INTO test (id, name, blob_field) VALUES (NULL, 'Bob', 0xB0B1);

4 Comments

How can I get hex literal of 001.png file?
Read the file into a byte array in your language, and then format each byte as a hex character. Are you doing this in C# or Java?
I have found examples how to do it in C and many other langueges, but I want to write *.sql file to fill database.
yes, but you can generate the SQL file with python or other programming, for example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.