[Gambas-user] escape a picture

richard terry rterry at ...1946...
Tue Nov 24 21:46:31 CET 2009


On Wednesday 25 November 2009 05:30:52 Jean-Yves F. Barbier wrote:
> Hi,
> 
> How can I escape a picture in order to insert it into a BYTEA
> postgresql data field?
> 
Having mucked around with this interminably looking at different ways, the 
solution is in the picture database sample file, but basically do something 
like this and you won't need to manually escape anything. You would use a 
different connection method like in the picture db not my function 
(modDbconnect), I've commented this for  you

Public Function Image_Save(ImagePath As String, Optional fk_Image As Integer = 
0) As Integer
  Dim newPicture As result
  Dim $Result As Result
  Dim img As Image
  Dim tempfile As String 
  Dim conn As Connection
 'get the connection to the backend
 conn = modDBConnect.Get_Connection()
'connect to the table
  newPicture = conn.Create("all_images")
'save the picture file to a tempory file
  img = Image.Load(ImagePath) 
  tempFile = Temp() & ".png"
  img.Save(tempFile)
'save to the database
  If Not fk_image Then
    newPicture["image"] = File.Load(tempFile)
    newPicture.Update()
'don't worry about this I just needed the pk, perhaps there is an easier way
    $Result = modDBConnect.exec_query("Select currval('all_images_pk_seq') as 
pk_image")
  End If 
  Return $Result!pk_image

End

Think that's ok, notify me if dosn't work, but follow the picture databas in 
samples line by line.

Regards

Richard




More information about the User mailing list