Blob data

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Gautami
Posts: 35
Joined: Tue Aug 06, 2013 5:25 am

Blob data

Post by Gautami » Mon Aug 19, 2013 5:53 pm

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
Attachments
Untitled1.png
Untitled1.png (22.74 KiB) Viewed 10919 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Blob data

Post by dunbarx » Mon Aug 19, 2013 6:35 pm

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

Gautami
Posts: 35
Joined: Tue Aug 06, 2013 5:25 am

Re: Blob data

Post by Gautami » Mon Aug 19, 2013 7:02 pm

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
Attachments
Untitled.png
Untitled.png (6.92 KiB) Viewed 10897 times

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Blob data

Post by MaxV » Wed Aug 21, 2013 5:01 pm

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.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Blob data

Post by bn » Wed Aug 21, 2013 7:11 pm

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

Gautami
Posts: 35
Joined: Tue Aug 06, 2013 5:25 am

Re: Blob data

Post by Gautami » Fri Aug 23, 2013 8:07 am

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Blob data

Post by bn » Fri Aug 23, 2013 12:12 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Blob data

Post by bn » Fri Aug 23, 2013 12:28 pm

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

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Blob data

Post by MaxV » Fri Aug 23, 2013 4:07 pm

Use http://sourceforge.net/projects/sqlitebrowser/ (it's free) to edit, check, create SQLite db. Verify that the third column is of BLOB type.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Gautami
Posts: 35
Joined: Tue Aug 06, 2013 5:25 am

Re: Blob data

Post by Gautami » Sat Aug 24, 2013 10:00 am

Hi Max and Bernd,
thank you so much!
I am now able to understand blob data better! :)

Thanks!!

G

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

Re: Blob data

Post by Klaus » Sat Aug 24, 2013 11:33 am

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

Gautami
Posts: 35
Joined: Tue Aug 06, 2013 5:25 am

Re: Blob data

Post by Gautami » Sun Aug 25, 2013 10:58 am

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

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

Re: Blob data

Post by Klaus » Sun Aug 25, 2013 11:07 am

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

Gautami
Posts: 35
Joined: Tue Aug 06, 2013 5:25 am

Re: Blob data

Post by Gautami » Sun Aug 25, 2013 11:57 am

Really??

oh no..

i will figure it out later and get back to ya


8)
Gautami

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

Re: Blob data

Post by Klaus » Sun Aug 25, 2013 12:29 pm

OK, a little hint:
set whatever TO anothervalue
put whatever ? anothervalue

Replace the ? with the correct term :-)

Post Reply