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/14444/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

Reply via email to