[sqlite] insert image into db - windows batch
For grins, and because I like scriptable DB operations, I've modified the SQLite shell.c source to make insertion of blobs from files, and extraction of blobs to files, work, efficiently, without extra tools and without changing the representation. The relevant section of the shell's help reads: .blobextract TABLE COLUMN ROW FILENAME ?DB? Extract DB blob to a file. DB defaults to 'main'. The table, column and row specify the alleged blob selected by: SELECT column FROM DB.table WHERE rowid = row .blobreplace TABLE COLUMN ROW FILENAME ?DB? Replace DB blob with file content, like reverse of .blobextract, except DB blob must have same size as the file, (created via zeroglob(filesize) or equivalent). In JPSoftware's TCC/LE batchfile language, some code using this facility might read: :: blob_demo.btm === @echo off :: Script for demonstration of SQLite blob I/O :: Written for TCC/LE by JPSoftware, http://jpsoft.com , (a usable CLI shell for Windows). setlocal pushd %TEMP% :: Set some image sources and names for them. set srcimg1=http://i.space.com/images/i/1/i02/supernova-remnant-snr-0509.jpg set sname1=stardregs set oname1=supernova-remnant.jpg set srcimg2=http://www.windows2universe.org/earth/Atmosphere/clouds/images/polar_stratospheric_1_big.jpg set sname2=poleclouds set oname2=polar-stratosphere-clouds.jpg set srcimg3=http://spaceweather.com/submissions/pics/e/Eric-Schandall-4-Nacreous-Clouds-13.01_1326475532_med.jpg set sname3=nacreous set oname3=nacreous-clouds.jpg if exist DemoBlobIO\stardregs.jpg (cd DemoBlobIO && goto havejpg) md DemoBlobIO cd DemoBlobIO echo Getting JPEGs for blob content. :: The wget utility is from http://sourceforge.net/projects/gnuwin32/files/wget/ do n = 1 to 3 (wget %[srcimg%n] && ren %@filename[%[srcimg%n]] %[sname%n].%@ext[%[srcimg%n]]) :havejpg :: Stuff the JPEGs into a SQLite DB. echo create table blobstore (rowid int, bag blob, source string); > blob_demo.sls do n = 1 to 3 set shortname=%[sname%n].%@ext[%[srcimg%n]] set length=%@filesize[%shortname] echo insert into blobstore values (%n, zeroblob(%length), '%[srcimg%n]'); >> blob_demo.sls echo .blobreplace blobstore bag %n ./%shortname >> blob_demo.sls enddo :: Sometime later, perhaps, extract them under new names. do n = 1 to 3 echo .blobextract blobstore bag %n ./%[oname%n] >> blob_demo.sls enddo :: Actually do said stuffing and extracting. set dbname=bagoblobs.sldb if exist %dbname del %dbname :: sqlite3m.exe, a modified version of the sqlite3.exe shell, is in the PATH. sqlite3m -batch %dbname < blob_demo.sls :: Compare input and output JPEGs, showing correct results or flagging bad ones. do n = 1 to 3 set shortname=%[sname%n].%@ext[%[srcimg%n]] set extname=%[oname%n] fc /B /LB1 %shortname %extname >nul iff ERRORLEVEL != 0 then echo JPEG %shortname did not survive blob transmogrification. else start mspaint %extname endiff enddo popd endlocal :: === This takes 146 lines of new code in shell.c, a little much to post. Anyone who is interested in this can decode my email address below and ask me for source or the sqlite3m.exe executable. Cheers, -- Larry Brasfield firstinitial.lastn...@something.org where my computer became something. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
> On Thu, Jan 19, 2012 at 1:49 AM, Kevin Bensonwrote: >> On Wed, Jan 18, 2012 at 8:16 PM, Simon Slavin wrote: >>> On 18 Jan 2012, at 11:13pm, Petr Lázňovský wrote: >>> > Look like script for different platform, but "od" and "tr" are >>> available also for Win so I will try... >>> I would probably look for a Windows version of 'hexdump'. >>> Simon. >>> ___ >> ...or maybe | xxd.exe | which seems to have a parameter to also "reverse" >> the operation: >> http://code.google.com/p/unix-cmd-win32/downloads/detail?name=xxd.exe >> -- >>-- >> -- >> --ô¿ô-- >> K e V i N > Another possibility is the Swiss File Knife utility which has a command for > conversion and back: > http://www.portablefreeware.com/forums/viewtopic.php?p=28023=fb6c6562cfe85a8ac7ecd8dd0b954cf9#p28023 I know this, but this tool is too big to packing inside of batch, xxd (35kb) is ten times smaller compare to sfk (370kb). ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On Thu, Jan 19, 2012 at 1:49 AM, Kevin Bensonwrote: > On Wed, Jan 18, 2012 at 8:16 PM, Simon Slavin wrote: > >> >> On 18 Jan 2012, at 11:13pm, Petr Lázňovský wrote: >> >> > Look like script for different platform, but "od" and "tr" are >> available also for Win so I will try... >> >> I would probably look for a Windows version of 'hexdump'. >> >> Simon. >> ___ >> > > > ...or maybe | xxd.exe | which seems to have a parameter to also "reverse" > the operation: > > http://code.google.com/p/unix-cmd-win32/downloads/detail?name=xxd.exe > > -- >-- > -- > --ô¿ô-- > K e V i N > Another possibility is the Swiss File Knife utility which has a command for conversion and back: http://www.portablefreeware.com/forums/viewtopic.php?p=28023=fb6c6562cfe85a8ac7ecd8dd0b954cf9#p28023 -- -- -- --ô¿ô-- K e V i N ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On Wed, Jan 18, 2012 at 8:16 PM, Simon Slavinwrote: > > On 18 Jan 2012, at 11:13pm, Petr Lázňovský wrote: > > > Look like script for different platform, but "od" and "tr" are available > also for Win so I will try... > > I would probably look for a Windows version of 'hexdump'. > > Simon. > ___ > ...or maybe | xxd.exe | which seems to have a parameter to also "reverse" the operation: http://code.google.com/p/unix-cmd-win32/downloads/detail?name=xxd.exe -- -- -- --ô¿ô-- K e V i N ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On Thu, 19 Jan 2012 01:16:26 +, Simon Slavinwrote: > >On 18 Jan 2012, at 11:13pm, Petr Láz?ovský wrote: > >> Look like script for different platform, but "od" and "tr" are available >> also for Win so I will try... > >I would probably look for a Windows version of 'hexdump'. Or use http://unxutils.sourceforge.net/ or http://www.cygwin.com/ (cygwin is much more intrusive). >Simon. -- Regards, Kees Nuyt ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On 18 Jan 2012, at 11:13pm, Petr Lázňovský wrote: > Look like script for different platform, but "od" and "tr" are available also > for Win so I will try... I would probably look for a Windows version of 'hexdump'. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
Look like script for different platform, but "od" and "tr" are available also for Win so I will try... > On Wed, 18 Jan 2012 13:30:49 +0100, Petr Láz?ovský> wrote: have windows batch working with sqlite, may I insert image into database and than read this images from? >>> Convert your image into a BLOB and store it as a BLOB. BLOBs are just runs >>> of bytes -- you can store anything you want as a BLOB. >>What you mean by "Convert image into a BLOB" is there some kind of SW to do >>this? Does SQLite offer some way to do this? Sorry for dumb question, but I >>googling about this some time with no luck.. >>I found only http://www.vive.net/products/image2db.htm but this is GUI tool, >>not suitable for scripting.. > Try this one liner demo (wrapped by mail) to insert file contents into a > database table: > d=test.db3 ; echo "CREATE TABLE Files (name TEXT PRIMARY KEY,contents > BLOB);" | sqlite3 $d ; for f in yourfiles* ; do echo "INSERT INTO Files > (name,contents) VALUES ('$f',X'$(od -v -A n -t x1 $f|tr -d '\r\n\t > ')');" | sqlite3 $d ; done > I'll leave the extraction from database to files as an exercise for the > reader. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On 18 Jan 2012 at 15:24, Petr Lázňovskýwrote: >> Sorry, 'windows batch' doesn't mean anything to me. > > http://en.wikipedia.org/wiki/Batch_file > > but wikipedia is reasonlessly turned off today > > > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users -- Cheers -- Tim ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
Hello Petr, You could Mime encode them to text, insert as a string. Pull them back out as strings, un-mime them. Should be able to do that from a batch file. I keep a bunch of images in Sqlite DB files. It's reasonably fast and I like having them all in one place. Some of the DB files are > 10 GB. C Wednesday, January 18, 2012, 10:14:17 AM, you wrote: PL> Because of packing. The script should be distributable as one PL> .cmd file, the database engine and database itself will be embeded PL> inside od script. Dealing with embeded files in the shell script PL> is not easy thus I want to minimize its number. PL> L. >> On Jan 18, 2012, at 12:00 PM, Petr Lázňovský wrote: >>> have windows batch working with sqlite, may I insert image into database >>> and than read this images from? >> As pointed out, you might want to use the 'blob' type to store binary data. >> That said, why bother storing these images inside the database itself? Any >> benefit in doing so? >> ___ >> sqlite-users mailing list >> sqlite-users@sqlite.org >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users PL> ___ PL> sqlite-users mailing list PL> sqlite-users@sqlite.org PL> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users -- Best regards, Tegmailto:t...@djii.com ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On Jan 18, 2012, at 4:24 PM, Petr Lázňovský wrote: > but wikipedia is reasonlessly turned off today On the contrary, they have pretty good reasons: http://en.wikipedia.org/wiki/Wikipedia:SOPA_initiative/Learn_more https://www.google.com/landing/takeaction/ http://www.tbray.org/ongoing/When/201x/2012/01/17/Not-Piracy So contact your representative if you have one. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On 18 Jan 2012 at 15:24, Petr Lázňovskýwrote: >> Sorry, 'windows batch' doesn't mean anything to me. > > http://en.wikipedia.org/wiki/Batch_file > > but wikipedia is reasonlessly turned off today Looks like you can get round this (at least on OS X / Safari 5.1) by pressing the escape key while the page is loading. -- Cheers -- Tim ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
> Sorry, 'windows batch' doesn't mean anything to me. http://en.wikipedia.org/wiki/Batch_file but wikipedia is reasonlessly turned off today ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
Because of packing. The script should be distributable as one .cmd file, the database engine and database itself will be embeded inside od script. Dealing with embeded files in the shell script is not easy thus I want to minimize its number. L. > On Jan 18, 2012, at 12:00 PM, Petr Lázňovský wrote: >> have windows batch working with sqlite, may I insert image into database and >> than read this images from? > As pointed out, you might want to use the 'blob' type to store binary data. > That said, why bother storing these images inside the database itself? Any > benefit in doing so? > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
You should be able to do it. We put a shot set of hex data in using a script. You likely want to load your file into a variable of hex (or binary) type, if you don't want to write a script that writes a script. Then insert into your_table (f1, blob) values ( your_f1_value , X'reference_to_your_hex_data' ) the X' ' to denotes your hex value. This is listed in the documentation. regards, Adam DeVita On Wed, Jan 18, 2012 at 10:02 AM, Petr Lázňovskýwrote: > > On 18 Jan 2012, at 12:30pm, Petr Lázňovský wrote: > > have windows batch working with sqlite, may I insert image into > database and than read this images from? > > >>> Convert your image into a BLOB and store it as a BLOB. BLOBs are just > runs of bytes -- you can store anything you want as a BLOB. > > >> What you mean by "Convert image into a BLOB" is there some kind of SW > to do this? Does SQLite offer some way to do this? Sorry for dumb question, > but I googling about this some time with no luck.. > > > If you don't already know how to use your programming language to store > integers and strings in a SQLite database, then learn that first. Once you > have software which can do that, read on: > > > An image (assuming you mean a file like a .jpeg or .png file) is just a > long run of bytes. You can store a long run of bytes in a SQLite database > as data of type 'BLOB'. This isn't a string, or a number, or a date, it's > just a long run of bytes which is stored exactly as supplied with no > interpretation. > > > So in your software, open the image file and read the contents of the > file into memory. Then use the SQLite library routine to create a new row, > and bind that piece of memory to a BLOB. When you want to retrieve that > data, read the BLOB back out of the database. Then if you want to make an > image file of it you can do that. If you want to display the image on the > screen without making a file of it, you can do that instead if your > programming language gives you way to do it. > > > The exact routines to use depends on the language your software is > written in: C, Python, PHP, whatever. That's all down to your personal > programming choice. But all the commonly-used interfaces to SQLite have > the ability to handle BLOBs. > > Simon, > > did you read the subject of my mail? I am use sqlite from Win batch > (shell) scripting by commands like: > > sqlite3.exe main.db "Insert into Table1 values('','','');" > > or > > sqlite3.exe main.db "select * from Table1 where Column='';" > > I am currently not a programmer (means Do not know any REAL language, only > partialy Win shell) and this is my first deal with databases at all. So > please be patient with me ;-) > > In Win shell AFAIK everything is a text, there are no data types. I spent > much time with google, but seems nobody uses this combination (Win shell + > sqlite) so there are very few informations on web :-/ > > L. > > > > > > > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- VerifEye Technologies Inc. 905-948-0015x245 151 Whitehall Dr, Unit 2 Markham ON, L3R 9T1 Canada ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On 18 Jan 2012, at 3:02pm, Petr Lázňovský wrote: > did you read the subject of my mail? I am use sqlite from Win batch (shell) > scripting by commands like: > > sqlite3.exe main.db "Insert into Table1 values('','','');" > > or > > sqlite3.exe main.db "select * from Table1 where Column='';" Sorry, 'windows batch' doesn't mean anything to me. > I am currently not a programmer (means Do not know any REAL language, only > partialy Win shell) and this is my first deal with databases at all. So > please be patient with me ;-) Okay, if you aren't a programmer you aren't going to be able to handle images that way. You could, technically do it using lots of scripting to turn an image file into hexadecimal but it would be slow, difficult and annoying. I think you might consider storing the name of the file the image is in rather than the image data itself. This is, I think, what Abeille was suggesting. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
> On 18 Jan 2012, at 12:30pm, Petr Lázňovský wrote: have windows batch working with sqlite, may I insert image into database and than read this images from? >>> Convert your image into a BLOB and store it as a BLOB. BLOBs are just runs >>> of bytes -- you can store anything you want as a BLOB. >> What you mean by "Convert image into a BLOB" is there some kind of SW to do >> this? Does SQLite offer some way to do this? Sorry for dumb question, but I >> googling about this some time with no luck.. > If you don't already know how to use your programming language to store > integers and strings in a SQLite database, then learn that first. Once you > have software which can do that, read on: > An image (assuming you mean a file like a .jpeg or .png file) is just a long > run of bytes. You can store a long run of bytes in a SQLite database as data > of type 'BLOB'. This isn't a string, or a number, or a date, it's just a > long run of bytes which is stored exactly as supplied with no interpretation. > So in your software, open the image file and read the contents of the file > into memory. Then use the SQLite library routine to create a new row, and > bind that piece of memory to a BLOB. When you want to retrieve that data, > read the BLOB back out of the database. Then if you want to make an image > file of it you can do that. If you want to display the image on the screen > without making a file of it, you can do that instead if your programming > language gives you way to do it. > The exact routines to use depends on the language your software is written > in: C, Python, PHP, whatever. That's all down to your personal programming > choice. But all the commonly-used interfaces to SQLite have the ability to > handle BLOBs. Simon, did you read the subject of my mail? I am use sqlite from Win batch (shell) scripting by commands like: sqlite3.exe main.db "Insert into Table1 values('','','');" or sqlite3.exe main.db "select * from Table1 where Column='';" I am currently not a programmer (means Do not know any REAL language, only partialy Win shell) and this is my first deal with databases at all. So please be patient with me ;-) In Win shell AFAIK everything is a text, there are no data types. I spent much time with google, but seems nobody uses this combination (Win shell + sqlite) so there are very few informations on web :-/ L. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On Jan 18, 2012, at 12:00 PM, Petr Lázňovský wrote: > have windows batch working with sqlite, may I insert image into database and > than read this images from? As pointed out, you might want to use the 'blob' type to store binary data. That said, why bother storing these images inside the database itself? Any benefit in doing so? ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On 18 Jan 2012, at 12:30pm, Petr Lázňovský wrote: >>> have windows batch working with sqlite, may I insert image into database >>> and than read this images from? > >> Convert your image into a BLOB and store it as a BLOB. BLOBs are just runs >> of bytes -- you can store anything you want as a BLOB. > > What you mean by "Convert image into a BLOB" is there some kind of SW to do > this? Does SQLite offer some way to do this? Sorry for dumb question, but I > googling about this some time with no luck.. If you don't already know how to use your programming language to store integers and strings in a SQLite database, then learn that first. Once you have software which can do that, read on: An image (assuming you mean a file like a .jpeg or .png file) is just a long run of bytes. You can store a long run of bytes in a SQLite database as data of type 'BLOB'. This isn't a string, or a number, or a date, it's just a long run of bytes which is stored exactly as supplied with no interpretation. So in your software, open the image file and read the contents of the file into memory. Then use the SQLite library routine to create a new row, and bind that piece of memory to a BLOB. When you want to retrieve that data, read the BLOB back out of the database. Then if you want to make an image file of it you can do that. If you want to display the image on the screen without making a file of it, you can do that instead if your programming language gives you way to do it. The exact routines to use depends on the language your software is written in: C, Python, PHP, whatever. That's all down to your personal programming choice. But all the commonly-used interfaces to SQLite have the ability to handle BLOBs. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
>> have windows batch working with sqlite, may I insert image into database and >> than read this images from? > Convert your image into a BLOB and store it as a BLOB. BLOBs are just runs > of bytes -- you can store anything you want as a BLOB. What you mean by "Convert image into a BLOB" is there some kind of SW to do this? Does SQLite offer some way to do this? Sorry for dumb question, but I googling about this some time with no luck.. I found only http://www.vive.net/products/image2db.htm but this is GUI tool, not suitable for scripting.. L. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] insert image into db - windows batch
On 18 Jan 2012, at 11:00am, Petr Lázňovský wrote: > have windows batch working with sqlite, may I insert image into database and > than read this images from? Convert your image into a BLOB and store it as a BLOB. BLOBs are just runs of bytes -- you can store anything you want as a BLOB. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] insert image into db - windows batch
have windows batch working with sqlite, may I insert image into database and than read this images from? L. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users