Read an image from SqlLite database

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Read an image from SqlLite database

Post by info26 » Fri Jul 01, 2011 3:34 pm

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

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Read an image from SqlLite database

Post by dglass » Fri Jul 01, 2011 3:36 pm

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.

info26
Posts: 47
Joined: Tue May 17, 2011 10:14 am

Re: Read an image from SqlLite database

Post by info26 » Mon Jul 04, 2011 4:10 pm

I resolve my problem.
Now I can put an image in a new record and update it

Thank' all

Mimmo

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Read an image from SqlLite database

Post by Klaus » Mon Jul 04, 2011 4:42 pm

Hi mimmo,

could you please share your experiences?
Thanks!


Best

Klaus

observ3
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 34
Joined: Mon Oct 11, 2010 11:05 pm

Re: Read an image from SqlLite database

Post by observ3 » Fri Jul 08, 2011 4:54 am

Yes, more about how you got it to work would be great!
Check out my LiveCode program, WriteSpire, on the App Store!

Post Reply