Page 1 of 1

Read an image from SqlLite database

Posted: Fri Jul 01, 2011 3:34 pm
by info26
I already posted this topic at the Summer Academy, now closed

Or often I have been using this code to save and return an image in a blob SqlLite

Code: Select all

    ---This is for inserting a blob
    --get the text of the image
    set the text of image "SelectedImage" to gPicData
    --base64encode the text of the image
    put base64encode(gPicData) into gPicData
    --build the insert sql
    put "INSERT INTO tblImages (ImageFile) VALUES (:1)" into theSQL
    --execute the insert, note the '*b' in front of the variable name, that's important
    revExecuteSQL dbConnID, theSQL, "*bgPicData"


    --This is for retrieving a blob
    --build the select sql
    put "SELECT ImageFile FROM tblImages WHERE Image_Key = 1" into tSQL
    --execute the select
       put revQueryDatabase(dbConnID, tSQL) into tRecordSet
    -- Retrieve the binary data from the record set.
    put revDatabaseColumnNamed(tRecordSet, "ImageFile") into theImage
    --we encoded the data when we put it in, so we have to decode it when we take it out
    put base64decode(theImage) into theImage
    --setting the text puts the image in the image area
    set the text of image "RetrievedImage" to theImage

But the suggestion does not work, or rather I need to run an UPDATE but I can not write code utille. With a tool I see that the blob field contains something but I can not then redisplay it as in the image field

Thank's to all

Mimmo

Re: Read an image from SqlLite database

Posted: Fri Jul 01, 2011 3:36 pm
by dglass
I'm pretty sure there's a later post in that thread the explains how to do it 'properly', i.e. without the need to base64 the imagedata.

Re: Read an image from SqlLite database

Posted: Mon Jul 04, 2011 4:10 pm
by info26
I resolve my problem.
Now I can put an image in a new record and update it

Thank' all

Mimmo

Re: Read an image from SqlLite database

Posted: Mon Jul 04, 2011 4:42 pm
by Klaus
Hi mimmo,

could you please share your experiences?
Thanks!


Best

Klaus

Re: Read an image from SqlLite database

Posted: Fri Jul 08, 2011 4:54 am
by observ3
Yes, more about how you got it to work would be great!