Page 1 of 1

Storing an image into a sqlite table

Posted: Thu Sep 11, 2014 8:30 pm
by jalz
Hi Guys,

I have an image object called logo and I have inserted an image inside of it. I want to press a save button and have that image stored in my sqlite database. I seem to be able to save text based items, but how do I do images. I have a field called logo in the database and it is of blob type.

This is the code I have so far.

Code: Select all

global gConnID

on mouseUp
   # Get the values
   put base64encode(img_logo) into tLogo64
   --put field "fld_logoposition" into tLogoPosition
   put field "fld_footer" into tFooter
   
   put "UPDATE stationary SET "& \
         "logo='" & tLogo64 &"'," & \
         "footer='" & tFooter & "'" &  \
         "WHERE stationaryID=1" into tTheSQLQuery
   
   revExecuteSQL gConnID, tTheSQLQuery
   
end mouseUp
Many thanks

Jalz

Re: Storing an image into a sqlite table

Posted: Thu Sep 11, 2014 9:48 pm
by Klaus
Hi Jalz,

try this:
...
put base64encode(the text of img "logo") into tLogo64
...
Base64Encode will however return a looooooong (text) string, so no need for (binary) BLOB.


Best

Klaus

Re: Storing an image into a sqlite table

Posted: Thu Sep 11, 2014 10:02 pm
by jalz
Hi Klaus,

I tried that, but my code doesn't seem to populate the blob field. It has nevertheless populated a footer field which is a text field. If I want to store a logo which is 300x300 px wide, do I store the base64 value in a blob field on a text field?

Code: Select all

   put base64encode(the text of img "img_logo") into tLogo64
   put "insert into stationary(logo, footer) values (:1, :1)" into tSQL
   revExecuteSQL gConnID,tSQL, "*b" & "tLogo64"

Thanks
Jalz

Re: Storing an image into a sqlite table

Posted: Thu Sep 11, 2014 10:19 pm
by Klaus
Looking at the dictionary, I would try:
...
## Since base64encode returns TEXT, I would simply pass the binary data:
put the text of img "img_logo" into tLogo64
put "insert into stationary(logo, footer) values (:1, :1)" into tSQL
revExecuteSQL gConnID,tSQL, "*btLogo64"
## "*b" & "tLogo64"
## maybe concatenating the variable name does not work here!?
...

Best

Klaus