Inserting images as BLOBs - any way to avoid using base64encode?

Jan Schenkel janschenkel at
Mon Aug 6 13:56:59 EDT 2007

--- Terry Judd <tsj at> wrote:
> Hi - I'm about to use SQLite to store all the
> resources for a large ed
> application I'm about to start building and was
> wondering whether there was
> any way to get images into and out of the database
> without having to
> base64encode/decode them. It looks like the encoding
> process adds about 30%
> to the file size, which for this project could add
> an extra 100 MB or more
> to the database file.
> Terry...

Hi Terry,

You can try and use the "query with placeholder" style
to push binary data into the database:
put URL("binfile:" & tFilePath) into tBinaryData
put "INSERT INTO images (:1, :2)" into tQuery
revExecuteSQL gConnection, tQuery, "tFilePath", "*b" &
put the result into tResult
if char 1 to 8 of tResult is "revdberr" then
  answer error tResult
  -- insert succeeded
end if

If the images are large, you'll want to use the
revQueryDatabaseBLOB function to get the data out as a
cursor. Then you can use the function
'revDatabaseColumnNamed' to extract the binary data.
put "SELECT * FROM images" into tQuery
put revDatabaseQueryBLOB(gConnection, tQuery) into
if tCursor is not a number then
  answer error tCursor
  put revDatabaseColumnNamed(tCursor,"binData") into
  -- do what you need to do
  -- ...
  -- clean up the cursor afterwards!
  revCloseCursor tCursor
end if

Base64Encoding is great if you have to move stuff
accross platforms and technologies; but the above may
do the trick for you.

Hope this helped,

Jan Schenkel.

Quartam Reports & PDF Library for Revolution

"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.

More information about the use-livecode mailing list