Обсуждение: plperlu user function.

Поиск
Список
Период
Сортировка

plperlu user function.

От
David Harel
Дата:
<tt><font size="+1">Greetings,<br /><br /> I am trying to write a user function on the server to retrive image files.
CurrentlyI wrote the following:<br /> CREATE OR REPLACE FUNCTION perl_getfile(text)<br />   RETURNS OID AS<br />
$BODY$<br/>     my $tmpfile = shift;<br />     open my $IFHAND, '<', $tmpfile<br />         or elog(ERROR, qq{could
notopen the file "$tmpfile": $!});<br />     binmode $IFHAND;<br />     my $result = '';<br />     while(my $buffer =
<$IFHAND>)<br/>     {<br />     $result .= $buffer;<br />     }<br />     return $result;<br /> $BODY$<br />  
LANGUAGE'plperlu';<br /><br /> on the client I do (PHP sniplet):<br /> $result = pg_query($dbcnx, "SELECT
perl_getfile('/home/harel/Misc/At_work.jpg')");<br/><br /> and I get an error:<br /></font><big>Warning: pg_query() [<a
href="http://localhost/mysqlImage1/function.pg-query">function.pg-query</a>]:Query failed: ERROR: invalid input syntax
fortype oid: "ÿØÿà" in /home/harel/Prj/php/testImages/mysqlImage1/image.php<br /><br /> Any recommendation how to do it
right?</big><br/></tt> <pre class="moz-signature" cols="72"><tt>-- 
 
Regards.

David Harel,

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

Home office +972 77 7657645
Cellular:   +972 54 4534502
Snail Mail: Amuka           D.N Merom Hagalil           13802           Israel
Email:      <a class="moz-txt-link-abbreviated" href="mailto:hareldvd@ergolight-sw.com">hareldvd@ergolight-sw.com</a>

</tt></pre>

Re: plperlu user function.

От
Alex Hunsaker
Дата:
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


Re: plperlu user function.

От
silly sad
Дата:
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.