Re: simple C function - Mailing list pgsql-general

From Ross J. Reedstrom
Subject Re: simple C function
Date
Msg-id 20000519121922.B9113@rice.edu
Whole thread Raw
In response to simple C function  (M.Mazurek@poznan.multinet.pl)
List pgsql-general
On Fri, May 19, 2000 at 05:54:55PM +0200, M.Mazurek@poznan.multinet.pl wrote:
> Hi,
> I'm trying to write a simple C function:
>
> char *pg_crypt (char *pass) {
>     char *salt="xyz";
>         char *res;
>     res = (char *) palloc(14);
>     res=crypt(pass,salt);
>     return res;
> }

you can't pass char pointers around like that for pgsql functions.
Here's my version of the above function. It includes random salt
selection if you don't supply it. (Hmm, I suppose I should put
this is contrib, eh? I did start with someone elses boilerplate,
so I'm not sure about the #define at the top.)

I compile it on linux with gcc as so:

gcc -fPIC -shared -I /usr/local/pgsql/include -L /usr/local/pgsql/lib \
    -o sqlcrypt.so sqlcrypt.c

And install it like so:

CREATE FUNCTION "sqlcrypt" (text,text ) RETURNS text AS '/usr/local/lib/sqlcrypt
.so' LANGUAGE 'C';

CREATE FUNCTION "sqlcrypt" (text ) RETURNS text AS 'select sqlcrypt($1,'''')' LA
NGUAGE 'SQL';

Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005

Attachment

pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Auto-uppercase inserted column
Next
From: davidb@vectormath.com
Date:
Subject: Re: beginner Table data type question