[Solved] Advise Needed - Saving Image to Database
Posted
#1
(In Topic #1469)
Enthusiast

A while ago one of you was kind enough to show me the following code
Code (gambas)
- Obj.Text = "" ' make sure Obj has not got text
- ' use Paint.class to draw the icon and text to the picture
- Paint.Begin(p)
- Paint.DrawPicture(hIcon, (Obj.W - hIcon.W) / 2, 4, hIcon.Width, hIcon.Height)
- Paint.End
and this work great when loading images from the local drive (like Icons for onscreen buttons etc but now I have moved onto a section where I need to Display images and save them to a database and display them when they are recalled (these are images for products on a Choice screen)
below is the code I am working with at the moment (and this is experiment and if it needs to change then I can change it no problem)
Code (gambas)
- ImageString = Global.pc.ToString("PNG", 100)
- $Query = Null
- $Query &= "update plumenu "
- $Query &= "SET "
- $Query &= "button_image ='" & ImageString & "' "
- $Query &= "where "
- $Query &= "plulistid='" & labSubMenuID.Caption & "' and "
- $Query &= "button_number ='" & labButtonNumber.Caption & "';"
but when it tries to save to the database i get the following error message
Query failed: you have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''?PNG \001A' at line 1
if I need to use another method of saving and displaying images from a database then I am open to recommendations (i did before use BASE64 to encode my images when I was using VB.net so if someone could tell me how I can encode and decode and display a decoded BASE64 image file that could be the way forward)
I am sure there is a VERY Simple slution for this but at the moment My brain is not coming up with one.
Kind regards to any who are willing to help me
Andy
Posted
Banned
FromBase64()
Posted
Administrator

Posted
Enthusiast

BruceSteers said
Base64()
FromBase64()
Thanks for that I had a feeling it was that one but I was not sure how to use them
I assume to save to the database I would use
Dbfeild = Global.pc.tostring(base64)
And to convert back I would use
Global.pc = Picture.FromString(frombase64(dbfeild))
sholzy said
Why save an image to a db? Why not save the image in a folder and save the image's location in the db. Db size will be smaller. The downside could be a possibility of a missing image in the folder.
I don't want the systems to relay on the network as I could have anything from 1 PoS Terminal to 100 PoS Terminals working. I feel using the database would be better as each terminal has its own local copy and works with that (so it never hits the network database server only to pull updates) so if a network goes down the PoS Terminals keep on running
Posted
Banned
Dbfeild = Base64(Global.pc.tostring())
Posted
Enthusiast

BruceSteers said
Close…
Dbfeild = Base64(Global.pc.tostring())
Thank you Bruce I assume Global.pc = Picture.FromString(frombase64(dbfeild)) is correct
Posted
Regular

b
Posted
Enthusiast

thatbruce said
I don't know how Mariadb stores blobs. However the disadvantage of storing pictures in databases, as previously mentioned is size. All it would take is one person to update this weeks special on bananas with a 7Gpixel photo and blam! Your database refreshes are going to take hours. I had a similar thing happen some years ago when phones only took 1GB pictures but the effect was not pleasant.
b
I am telling customers that the MAX size image is 1MB if they go over this then its their own fault i am also saying to cutomer they must use a PNG or jpeg file as they are the smallest sized files via qulity.
Posted
Enthusiast

Once again thank you all for the support you have given me over the course of this EPoS project.
1 guest and 0 members have just viewed this.




