Extending PostgreSQL Using C
Extending PostgreSQL Using C
От:
Boulat Khakimov <boulat@inet-interactif.com>
Дата:
Hi,
Im writing a C function for PG to do one way encryption using crypt.
Here is the source code
#include
#include
#include "postgres.h"
#include "utils/builtins.h"
text *encrypt(text *string){
text *ret;
int m;
if ((string == (text *) NULL) || ((m = VARSIZE(string) -
VARHDRSZ) <= 0))
return string;
ret = (text *) palloc(20);
ret = (text *) crypt(string,"AB");
return ret;
}
then I compile it like so:
gcc -I/usr/src/postgresql-7.0.3/src/include \
-I/usr/src/postgresql-7.0.3/src/backend -O2 -Wall
-Wmissing-prototypes \
-Wmissing-declarations \
-I/usr/src/postgresql-7.0.3/src/interfaces/libpq \
-I/usr/src/postgresql-7.0.3/src/include -fpic -c -o encrypt.o
encrypt.c
gcc -shared -o encrypt.so encrypt.o
rm encrypt.o
then in PG, I do the following
test=> CREATE FUNCTION encrypt(text)
test->RETURNS text
test->AS '/[full path here]/encrypt.so'
test->LANGUAGE 'C';
CREATE
Now when I try
test=> SELECT encrypt('Blah');
it gives me this error
ERROR: Can't find function encrypt in file /[full path here]/encrypt.so
Why do I get this error????
Any ideas?
Regards,
Boulat Khakimov
--
Nothing Like the Sun
Re: Extending PostgreSQL Using C
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Boulat Khakimov writes: > ERROR: Can't find function encrypt in file /[full path here]/encrypt.so > Why do I get this error???? Offhand I see nothing wrong with your procedure. Try running 'nm' on the .so file to see what symbols it says the .so defines. What platform is this on, anyway? regards, tom lane
Re: Extending PostgreSQL Using C
От:
Boulat Khakimov <boulat@inet-interactif.com>
Дата:
Tom Lane wrote:
>
> Boulat Khakimov writes:
> > ERROR: Can't find function encrypt in file /[full path here]/encrypt.so
> > Why do I get this error????
>
> Offhand I see nothing wrong with your procedure. Try running 'nm' on
> the .so file to see what symbols it says the .so defines.
>
> What platform is this on, anyway?
Linux 2.2.18 #23 Tue Feb 6 13:21:15 EST 2001 i686 unknown
Regards,
Boulat
--
Nothing Like the Sun
Re: Extending PostgreSQL Using C
От:
Hannu Krosing <hannu@tm.ee>
Дата:
Boulat Khakimov wrote: > Hi, > > Im writing a C function for PG to do one way encryption using crypt. > Here is the source code > > it gives me this error > > ERROR: Can't find function encrypt in file /[full path here]/encrypt.so > > > Why do I get this error???? > Any ideas? Can _postgres_ user read /[full path here]/encrypt.so ? --------------- Hannu
Re: Extending PostgreSQL Using C
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Hannu Krosing writes: > Boulat Khakimov wrote: >> ERROR: Can't find function encrypt in file /[full path here]/encrypt.so > Can _postgres_ user read /[full path here]/encrypt.so ? Presumably so. If he were unable to load the .so file, he'd be getting a different error message. This message indicates that he got past the load step, but dl_sym is unable to resolve the symbol "encrypt". I asked about the symbol names shown by nm(1), but got no answer ... regards, tom lane
Re: Extending PostgreSQL Using C
От:
Nishad Prakash <prakashn@uci.edu>
Дата:
On Wed, 7 Mar 2001, Tom Lane wrote: > Hannu Krosing writes: > > Boulat Khakimov wrote: > >> ERROR: Can't find function encrypt in file /[full path here]/encrypt.so > > > Can _postgres_ user read /[full path here]/encrypt.so ? > > Presumably so. If he were unable to load the .so file, he'd be getting > a different error message. This message indicates that he got past the > load step, but dl_sym is unable to resolve the symbol "encrypt". > > I asked about the symbol names shown by nm(1), but got no answer ... It should be noted that encrypt() is a function already declared in unistd.h, which the OP is including. Could that be causing some problem since the OP is using the same name? Nishad -- "Underneath the concrete, the dream is still alive" -- Talking Heads