Storing large images as BLOBs inside SQLite DB using Bash
I am creating a little script to import a large catalog of images inside a SQLite database.I understand perfectly well that SQLite is not an ideal place to store large drops, but I have to do it.
Actually, I'm trying to use hexdump:
sqlite3 name.db "INSERT INTO table (image) values(x'"$(hexdump -v -e '1/1 "%02x"' ./filename.jpg)"');"
But sometimes an error is returned on rather large images:
sqlite3: Argument list too long
How would you deal with this problem?
source to share
When an SQL command is given as a parameter sqlite3
, all output hexdump
must be generated before the parameter can actually be used.
The pipe has no size restrictions:
(echo -n "INSERT INTO table (image) values(x'"
hexdump -v -e '1/1 "%02x"' ./filename.jpg
echo "');") | sqlite3 name.db
Alternatively, you can write the command to a file and report sqlite3
<< 24>.
SQLite 3.8.6 or later has a readfile () function to read a file directly.
source to share