>Could you please give me a step by step on how to do that? Not via a
>small program written in a programming language, but only via the
>sqlite3 shell, as both you and I agree that was the implied intent of
>the OP's question.

Sorry, I'm no vxWorks, Unix, Linux, MacOS, Windows, AS400, Symbian, 
you_name_it ... guru.  I just can't cite you a portable combination of 
command-line tools to do that.

I took the question differently, don't read me backwards.  I didn't 
think of  manual input on individual sqlite3 command line, but rather 
building some SQL input file.  That one has to use a complex 
combination of dump, grep, awk, sed, emacs,  whatever_tool_exists, to 
have lines like:

insert into pics(id, pic) values ($id$, x'$pic$');

built and replacing $id$ by the required id and $pic$ by a hex dump 
doesn't seem unfeasible.  I took the question to mean: "Is it necessary 
to write a dedicated SQLite program to insert pics or other binary data 
into an SQLite base".  My answer was that no, suitable combination of 
command-line style tools can do it, with a short example of what needs 
to be done.  That a particular environment doesn't offer a ready to use 
facility and one has to make a generic "utility" corresponding to the 
pseudo-code:

open argument filename as binary
foreach byte b  fprintf to stdout b as %02x
close files

is not in my view "SQLite development".  No SQLite header needed for 
that, no SQLite API or wrapper.  If ever such utility doesn't readily 
exist and can't be simulated on a particular platform is something 
else.  That utility can be used on any base and does only depend on the 
OS used.

Look, to come up with a working example, here's what I did:

Local $h = FileOpen("D:\2009-12-07_024519.bmp", 16)
Local $v = FileRead($h)
FileClose($h)
ConsoleWrite("x'" & Hex($v) & "'" & @lf)

Then I copied the console output and used it inside my favorite SQLite 
manager thusly:

insert into t (d) values 
(x'424D3E0000000000000036000000280000000200000001000000010018000000000008000000C40E0000C40E00000000000000000001FFFFFFFFFFFF0000');

I wrote the four line "utility"  above in [Windows] AutoIt just because 
I was lazy enough to question myself about what available command-line 
utility or combination thereof could produce the same result quickly, 
DOS, Windows or MinGW or else.

Now, just by curiosity, I just tried to dig out a _really_ dusty 
dump.exe dated ... 24/10/1987 from the brave DOS time and it produces:

D:\>dump test.bmp
0000H  42 4D 3E 00 00 00 00 00 00 00 36 00 00 00 28 00   'BM>.......6...(.'
0010H  00 00 02 00 00 00 01 00 00 00 01 00 18 00 00 00   '................'
0020H  00 00 08 00 00 00 C4 0E 00 00 C4 0E 00 00 00 00   '......D...D.....'
0030H  00 00 00 00 00 01 FF FF FF FF FF FF 00 00         '..............'

Name and contents differ because I dropped the initial test file from 
yesterday.

Nevertheless, I believe it's easy to use a less prehistoric "dump" (or 
equivalent) then grep (or equivalent) the output to produce what's needed.

That subsequent regexp should be considered "programmatic" or not is up 
to the reader.  But then, even entering _anything_ on any shell of any 
OS can be considered "programmatic", whatever that means.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to