pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: Registring a C function in PostgreSQL
4+ messages / 3 participants
[nested] [flat]
* Re: Registring a C function in PostgreSQL
@ 1970-01-01 00:00 Haller Christoph <ch@rodos.fzk.de>
parent: Miguel González <iafmgc@unileon.es>
1 sibling, 1 reply; 4+ messages in thread
From: Haller Christoph @ 1970-01-01 00:00 UTC (permalink / raw)
To: iafmgc@unileon.es; +Cc: pgsql-sql
Did you use the compiler option for generating
position independent code (PIC) for use in building
shared libraries.
Did you use the linker option for creating
a shared library - I think you did, the file
suffix .so looks that way.
I did it several times successfully using commands
like
CREATE FUNCTION byteatostr(bytea) RETURNS text
AS './byteatostr.sl' LANGUAGE 'c';
and it worked.
Maybe you should add some more information about
what you did in detail.
Regards, Christoph
^ permalink raw reply [nested|flat] 4+ messages in thread
* Registring a C function in PostgreSQL
@ 2001-09-18 18:06 Miguel González <iafmgc@unileon.es>
0 siblings, 2 replies; 4+ messages in thread
From: Miguel González @ 2001-09-18 18:06 UTC (permalink / raw)
To: pgsql-sql
I have followed the instructions in the Bruje Momjian´s book to register a
function, and i got this message:
ERROR:/load of file /home/postgres/ctof.so failed: /home/postgres/ctof.so
ELF file´s phentsize not the expected size.
What is going on? I have tried to get more documentation about how to use C
functions in PostgreSQL, but I cant.
Many thanks in advance
Miguel
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Registring a C function in PostgreSQL
@ 2001-09-19 08:09 Peter Eisentraut <peter_e@gmx.net>
parent: Miguel González <iafmgc@unileon.es>
1 sibling, 0 replies; 4+ messages in thread
From: Peter Eisentraut @ 2001-09-19 08:09 UTC (permalink / raw)
To: Miguel González <iafmgc@unileon.es>; +Cc: pgsql-sql
Miguel González writes:
> ERROR:/load of file /home/postgres/ctof.so failed: /home/postgres/ctof.so
> ELF file´s phentsize not the expected size.
You probably didn't compile or link the code correctly. See the
PostgreSQL Programmer's Guide for information.
--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Registring a C function in PostgreSQL
@ 2001-09-19 10:41 Miguel González <iafmgc@unileon.es>
parent: Haller Christoph <ch@rodos.fzk.de>
0 siblings, 0 replies; 4+ messages in thread
From: Miguel González @ 2001-09-19 10:41 UTC (permalink / raw)
To: Haller Christoph <ch@rodos.fzk.de>; +Cc: pgsql-sql
Many thanks for your answers. The thing that in the Bruce´s book doesnt
explain how to compile this kind of functions, anyway I found how to compile
it.
Now, I am still having problems. I want to create a function to send an
email. I pass to the function two arguments: the email to send, and the text
to send.
First, I tried with pointers to char. It worked when I just create a
function called "sendemail()" with no arguments and set inside the text and
the email arguments.
When I read some more documentation about how to use strings in PostgreSQL,
I discovered that I have to use the text type in my C program I just try it
but
although it worked before, now I doesnt work.
This is what I have tried:
#include <stdio.h>
#include "postgres.h"
int sendemail(text *email,text *message)
{
char string_tosend [300];
sprintf(string_tosend,"echo \"%s\" >/tmp/mailtmp.txt
\n",VARDATA(message));
system(string_tosend);
sprintf(string_tosend,"mail -s \"message from PostgreSQL\" %s
</tmp/mailtmp.txt \n",VARDATA(message));
system(string_tosend);
system("rm /tmp/mailtmp.txt");
return 0;
}
and then in the back-end of PostgreSQL and I declared
CREATE FUNCTION sendemail(text,text)
RETURNS int4
AS '/home/postgres/libpginvuimail.so'
LANGUAGE 'c';
and then SELECT sendemail('postgres','test from backend');
and it didnt work. What am I doing wrong?
I have being testing and I guess is something to do with the text data type
and how to use it within a C program.
Many thanks in advance
Miguel
----- Original Message -----
From: "Haller Christoph" <ch@rodos.fzk.de>
To: "Miguel González" <iafmgc@unileon.es>
Cc: <pgsql-sql@postgresql.org>
Sent: Wednesday, September 19, 2001 12:24 PM
Subject: Re: [SQL] Registring a C function in PostgreSQL
> Did you use the compiler option for generating
> position independent code (PIC) for use in building
> shared libraries.
> Did you use the linker option for creating
> a shared library - I think you did, the file
> suffix .so looks that way.
> I did it several times successfully using commands
> like
> CREATE FUNCTION byteatostr(bytea) RETURNS text
> AS './byteatostr.sl' LANGUAGE 'c';
> and it worked.
> Maybe you should add some more information about
> what you did in detail.
> Regards, Christoph
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-09-19 10:41 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-09-18 18:06 Registring a C function in PostgreSQL Miguel González <iafmgc@unileon.es>
1970-01-01 00:00 ` Haller Christoph <ch@rodos.fzk.de>
2001-09-19 10:41 ` Miguel González <iafmgc@unileon.es>
2001-09-19 08:09 ` Peter Eisentraut <peter_e@gmx.net>
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