Upload image into SQL [Longblob]

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
jwtea
Posts: 65
Joined: Fri Mar 23, 2018 2:01 am

Upload image into SQL [Longblob]

Post by jwtea » Sat Dec 01, 2018 6:03 pm

Hello , i got trouble uploading image to my sqldatabase ; my column for the image in the database will longblob.

Anybody got any idea on this issue?

I uses this code below to select a image

Code: Select all

  on mouseup
  put "*.jpg;*.gif;*.png" into types
   if there is not an image "photo" then
      create image "photo"
   end if
   
   answer file "Select file" with type types
   if it is empty then exit mouseUp
   put it into fn
   
   if there is a file fn then
      set the fileName of image "photo" to fn
     end mouseup
   

Klaus
Posts: 10472
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Upload image into SQL [Longblob]

Post by Klaus » Sat Dec 01, 2018 7:22 pm

Hi jwtea,

something like this should do:

Code: Select all

on mouseup
   ## type is a reserved word!
   put "*.jpg;*.gif;*.png" into tTypes
   if there is not an image "photo" then
      create image "photo"
   end if   
   answer file "Select file" with type tTypes
   
   if it is empty then
      exit mouseUp
   end if
   put it into fn
   
   ##if there is a file fn then
   ## User HAS in fact selected a file! ;-)
   set the fileName of image "photo" to fn
   ## end if
   
   ## put binary image data into variable
   put url("binfile:" & fn) into MyImageVar
   
   revExecuteSQL Your_DB_ID_here, "insert into YourTable(YourLargeBlobDBField) values(:1)", "*bMyImageVar"
   ## the *b before the variable name indicates that you are passing binary data to the db.
   ## if the result... 
   ## errorchecking here...
end mouseup
Best

Klaus

jwtea
Posts: 65
Joined: Fri Mar 23, 2018 2:01 am

Re: Upload image into SQL [Longblob]

Post by jwtea » Sat Dec 01, 2018 7:57 pm

Hello Klaus ,

Thanks for your reply!

Actually i want to update the database instead of inserting, any idea how?

Klaus
Posts: 10472
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Upload image into SQL [Longblob]

Post by Klaus » Sun Dec 02, 2018 3:24 am

https://www.w3schools.com/sql/sql_update.asp

Get back when you get stuck. 8)

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 642
Joined: Fri Jun 27, 2008 9:00 pm

Re: Upload image into SQL [Longblob]

Post by Mikey » Sun Dec 02, 2018 4:31 pm

@jwtea
Just curious, whatcha cookin' with this project?

mrcoollion
Posts: 343
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Upload image into SQL [Longblob]

Post by mrcoollion » Sun Dec 02, 2018 5:33 pm

I use

Code: Select all

put base64encode(image "MugShot") into tBase64ImgData 
to first place the image in a variable and then add it to a column in the database. Works fine for me.
The SQLite Database Column type is GRAPHIC

In the below links you can find more about working with databases (SQLite)
http://lessons.livecode.com/m/4069/l/56 ... e-database
http://livecode.byu.edu/indexgeneric.php
Last edited by mrcoollion on Wed Dec 05, 2018 8:23 am, edited 1 time in total.

jwtea
Posts: 65
Joined: Fri Mar 23, 2018 2:01 am

Re: Upload image into SQL [Longblob]

Post by jwtea » Tue Dec 04, 2018 7:39 pm

Mikey wrote:
Sun Dec 02, 2018 4:31 pm
@jwtea
Just curious, whatcha cookin' with this project?
Hahahah i'm actually just trying out the function not cooking anything yet :D

Post Reply

Return to “Talking LiveCode”