pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
plperlu user function.
3+ messages / 3 participants
[nested] [flat]

* plperlu user function.
@ 2010-05-18 21:29 David Harel <hareldvd@gmail.com>
  2010-05-18 21:36 ` Re: plperlu user function. Alex Hunsaker <badalex@gmail.com>
  2010-05-19 05:38 ` Re: plperlu user function. silly sad <sad@bankir.ru>
  0 siblings, 2 replies; 3+ messages in thread

From: David Harel @ 2010-05-18 21:29 UTC (permalink / raw)
  To: pgsql-sql

Greetings,

I am trying to write a user function on the server to retrive image 
files. Currently I wrote the following:
CREATE OR REPLACE FUNCTION perl_getfile(text)
   RETURNS OID AS
$BODY$
     my $tmpfile = shift;
     open my $IFHAND, '<', $tmpfile
         or elog(ERROR, qq{could not open the file "$tmpfile": $!});
     binmode $IFHAND;
     my $result = '';
     while(my $buffer = <$IFHAND>)
     {
     $result .= $buffer;
     }
     return $result;
$BODY$
   LANGUAGE 'plperlu';

on the client I do (PHP sniplet):
$result = pg_query($dbcnx, "SELECT 
perl_getfile('/home/harel/Misc/At_work.jpg')");

and I get an error:
Warning: pg_query() [function.pg-query 
<http://localhost/mysqlImage1/function.pg-query;]: Query failed: ERROR: 
invalid input syntax for type oid: "ÿØÿà" in 
/home/harel/Prj/php/testImages/mysqlImage1/image.php

Any recommendation how to do it right?

-- 
Regards.

David Harel,

==================================

Home office +972 77 7657645
Cellular:   +972 54 4534502
Snail Mail: Amuka
             D.N Merom Hagalil
             13802
             Israel
Email:      hareldvd@ergolight-sw.com

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: plperlu user function.
  2010-05-18 21:29 plperlu user function. David Harel <hareldvd@gmail.com>
@ 2010-05-18 21:36 ` Alex Hunsaker <badalex@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Alex Hunsaker @ 2010-05-18 21:36 UTC (permalink / raw)
  To: David Harel <hareldvd@gmail.com>; +Cc: pgsql-sql

On Tue, May 18, 2010 at 15:29, David Harel <hareldvd@gmail.com> wrote:
> Greetings,
>
> I am trying to write a user function on the server to retrive image files.
> Currently I wrote the following:
> CREATE OR REPLACE FUNCTION perl_getfile(text)
>   RETURNS OID AS

I think you meant returns bytea or text or something... else



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: plperlu user function.
  2010-05-18 21:29 plperlu user function. David Harel <hareldvd@gmail.com>
@ 2010-05-19 05:38 ` silly sad <sad@bankir.ru>
  1 sibling, 0 replies; 3+ messages in thread

From: silly sad @ 2010-05-19 05:38 UTC (permalink / raw)
  To: pgsql-sql

On 05/19/10 01:29, David Harel wrote:

> I am trying to write a user function on the server to retrive image
> files. Currently I wrote the following:

> my $tmpfile = shift;
> open my $IFHAND, '<', $tmpfile

> Any recommendation how to do it right?

first of all, stop opening files at all,
return to a client a pathname,
then give to Caesar what is Caesar's, and to God what is God's.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2010-05-19 05:38 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-05-18 21:29 plperlu user function. David Harel <hareldvd@gmail.com>
2010-05-18 21:36 ` Alex Hunsaker <badalex@gmail.com>
2010-05-19 05:38 ` silly sad <sad@bankir.ru>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox