Extending PostgreSQL Using C

From: Boulat Khakimov <boulat(at)inet-interactif(dot)com>
To: pgsql-sql(at)postgresql(dot)org, pgsql-docs(at)postgresql(dot)org
Subject: Extending PostgreSQL Using C
Date: 2001-03-05 22:00:31
Message-ID: 3AA40C7F.D56684AF@inet-interactif.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-sql

Hi,

Im writing a C function for PG to do one way encryption using crypt.
Here is the source code

#include <ctype.h>
#include <unistd.h>
#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

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2001-03-05 23:23:45 Re: Extending PostgreSQL Using C
Previous Message Bruce Momjian 2001-03-05 21:05:31 Re: [SQL] PL/SQL-to-PL/PgSQL-HOWTO beta Available

Browse pgsql-sql by date

  From Date Subject
Next Message Mathijs Brands 2001-03-05 22:03:56 Clustering (was Re: Optimizing Query)
Previous Message Justin Long 2001-03-05 21:59:47 Re: Optimizing Query