[Gambas-user] escape a picture

Jean-Yves F. Barbier 12ukwn at ...626...
Tue Nov 24 22:19:14 CET 2009


richard terry a écrit :

No Richard, I can't do that for:

* I already have a connection, and I wanna keep connection number as low 
   as possible,

* I do things as they should be done, so not any direct user permission 
   on any DB schema/table/index/sequence/etc; So I can't insert anything
   directly,

* I already have a big trigger on this table (ON INSERT) and I don't
   wanna bloat it (and this wouldn't solve the PB.)

So I *really* need to send an escaped string to my procedure.

Regards

JY

> 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.
-- 
A watched clock never boils.




More information about the User mailing list