Page 1 of 2

Blob data

Posted: Mon Aug 19, 2013 5:53 pm
by Gautami
Hi all,
Sorry to bother. I have a sqlite file with some data stored as blob.
I am not very familiar with this type of data and am currently reading up on it.
But is there any way for me to be able to display the data??

There is a column called thumb_image as well, which looks... well, odd.
I am wondering if they have anything to do with each other.
I have attached an image for you guys to view.

Any help will be appreciated!!

Thank you!

Gautami

Re: Blob data

Posted: Mon Aug 19, 2013 6:35 pm
by dunbarx
From what I see, BLOB is just a string, though sometimes quite long, and may contain any sort of data. The SQL server does not interpret this string.

So there should be no issue with displaying such data, apart from possible length issues. But if the string contains characters that you might want to use as itemdelimiters, such as tab or comma, this might make the display unmanageable.

What does the raw_data in line 1 of your example look like? It seems like tabs and returns worked in that example.

Craig Newman

Re: Blob data

Posted: Mon Aug 19, 2013 7:02 pm
by Gautami
Hi,

Thanks for the reply.
So the {BLOB} itself contains some long string of data that I can't view in the sql browser.. I see.

*enlightened*

Well, the raw_data of line 1 looks as in the picture.
Is there some kind of decoding I have to do for blob data?


Gautami

Re: Blob data

Posted: Wed Aug 21, 2013 5:01 pm
by MaxV
the problem is: how do you store the data of the image?
the imageData of an image is the data (binary) of an image that you should store and recover from a BLOB value of a database.
When you create the database the column containing data must be BLOB type, otherwise data will be converted and corrupted.

Re: Blob data

Posted: Wed Aug 21, 2013 7:11 pm
by bn
the imageData of an image is the data (binary) of an image that you should store and recover from a BLOB value of a database.
careful: imageData is not the complete binary representation of the image, it it just a binary representation of all the pixel.
There is more to an image than imageData.

You could store

Code: Select all

the text of image "myImage"
this is the whole image with width and height and possibly alphaChanel information and more.

if you just store the imageData you would have to provide an image object of exactly the same size and height as the original image and then set the imageData of that image object to your blob stuff.


Kind regards
Bernd

Re: Blob data

Posted: Fri Aug 23, 2013 8:07 am
by Gautami
Hi,
thank you for the reply :)
However, I am still not getting it;
when i

put the text of image "myImage" to pix
put "myImage" into img "image01"

I am getting nothing.

i am not familiar with images stored in the sqlite files and am struggling with it. It has 3 columns of interest: media_url, thumb_image and raw_data. The first column is a expired url, the second has some characters in it and the third says {blob}....

When the sqlite db is run through a python script, the html file generated is somehow able to extract and display the image, which is through this :

"data:image/jpg;base64,\n" + base64.b64encode(y.media_thumb).decode("utf-8")

i have tried to replicate it in livecode by getting the image data, base64encode it and then decode it using utf-8. Still nothing......

Any suggestions will be welcome..

exhausted,
G

Re: Blob data

Posted: Fri Aug 23, 2013 12:12 pm
by bn
Hi Gautami,

sorry I was not very explicit in my previous post, I mainly wanted to make you aware of the imageData as used in LIveCode and the binary representation of the whole image.

I made a small script that shows the syntax for getting images and setting images to binary data.

Make a new stack and 1 field. Drag drop an image from your hard disk to the field and the path will be in the field (you could also use answer file)
1 button with the following script:

Code: Select all

on mouseUp
   put field 1 into tImagePath
   put url ("binfile:" & tImagePath) into tImage -- now tImagePath has the binary data of an image file, NOTE parenthesis ("binfile:" & variable) 
   if there is an image "myFirstImage" then 
      set the text of image "myFirstImage" to tImage
   else
      create image "myFirstImage"
      set the text of image "myFirstImage" to tImage
   end if
   set the topLeft of image "myFirstImage" to 40,40 -- just so the images dont pile up in the center of the card
   if there is an image "mySecondImage" then
      set the text of image "mySecondImage" to the text of image 1
   else
      create image "mySecondImage"
      set the text of image "mySecondImage" to the text of image 1
   end if
   set the topLeft of image "mySecondImage" to 80,80 -- just so the images dont pile up in the center of the card
   if there is an image "myThirdImage" then
      put image 1 into image "myThirdImage"
   else
      create image "myThirdImage"
      put image 1 into image "myThirdImage"
   end if
   set the topLeft of image "myThirdImage" to 120,120 -- just so the images dont pile up in the center of the card
end mouseUp
What this shows: first you load the binary data from the file into a variable.
Basically that is what you could strore in your blob after base64encoding. No UTF-8, this is binary data. To unload you would have to base64decode the blob into a variable and set the text of an image to that variable.

The script shows variants of the syntax.
If you use text of image you have to code

Code: Select all

set the text of image "myImage" to myVariable
since the text of an image is a PROPERTY, set works with properties.

you could say, as shown,

Code: Select all

put image 1 into image 2
in that case you treat image 2 as a CONTAINER, put works with containers.

Please have a look at the script, as far as I see it should get you going.

Kind regards
Bernd

Re: Blob data

Posted: Fri Aug 23, 2013 12:28 pm
by bn
HI Gautami,

in addition to my above post:
a variant that base64encodes and base64decodes the data.

Code: Select all

on mouseUp
   put field 1 into tImagePath
   put url ("binfile:" & tImagePath) into tImage -- now tImagePath has the binary data of an image file, NOTE parenthesis ("binfile:" & variable) 
   
   put base64encode(tImage) into tImageBase64 -- this is probably what you want to store in your blob
   
   -- get data out of your blob (not shown here)
   -- and base64decode it:
   put base64decode (tImageBase64) into tImageBinary
   
   if there is an image "myFirstImage" then 
      set the text of image "myFirstImage" to tImageBinary
   else
      create image "myFirstImage"
      set the text of image "myFirstImage" to tImageBinary
   end if
end mouseUp
Kind regards
Bernd

Re: Blob data

Posted: Fri Aug 23, 2013 4:07 pm
by MaxV
Use http://sourceforge.net/projects/sqlitebrowser/ (it's free) to edit, check, create SQLite db. Verify that the third column is of BLOB type.

Re: Blob data

Posted: Sat Aug 24, 2013 10:00 am
by Gautami
Hi Max and Bernd,
thank you so much!
I am now able to understand blob data better! :)

Thanks!!

G

Re: Blob data

Posted: Sat Aug 24, 2013 11:33 am
by Klaus
Hi Gautami,

great you got it working, but you also should really understand why this:
...
put the text of image "myImage" to pix
put "myImage" into img "image01"
...
CANNOT work at all (to say the least)! 8-)


Best

Klaus

Re: Blob data

Posted: Sun Aug 25, 2013 10:58 am
by Gautami
Hi Klaus,

LOL.

Ooops, haha
I got it.

This may be a better bet :

put the text of image "myImage" to pix
put pix into img "image01"

Gautami

Re: Blob data

Posted: Sun Aug 25, 2013 11:07 am
by Klaus
Hi Gautami,
Gautami wrote:This may be a better bet :
...
put the text of image "myImage" to pix
put pix into img "image01"
...
not at all, the first line will still throw an error! 8-)


Best

Klaus

Re: Blob data

Posted: Sun Aug 25, 2013 11:57 am
by Gautami
Really??

oh no..

i will figure it out later and get back to ya


8)
Gautami

Re: Blob data

Posted: Sun Aug 25, 2013 12:29 pm
by Klaus
OK, a little hint:
set whatever TO anothervalue
put whatever ? anothervalue

Replace the ? with the correct term :-)