Re: [NOVICE] Re: [GENERAL] Postgres superuser priviledges - Mailing list pgsql-general
| From | Konstantinos Vassiliadis |
|---|---|
| Subject | Re: [NOVICE] Re: [GENERAL] Postgres superuser priviledges |
| Date | |
| Msg-id | Pine.LNX.3.95.980721184410.28715A-400000@p05.cs.man.ac.uk Whole thread |
| In response to | Re: [GENERAL] Postgres superuser priviledges ("Gene Selkov, Jr." <selkovjr@mcs.anl.gov>) |
| List | pgsql-general |
Thanks in advance for your help.
I had a look at your defined type. I have some questions:
a) I don't really understand the syntax of the Makefile. I understand it
is required to do the job and I simply substituted your files with mine.
b) Do I need to place my directory with all the files under $PGROOT/src/
where $PGROOT is the postgres directory?
I have issued
%make
from the directory where all my files are and gave
make: *** ..: Is a directory. Stop.
I attach the C source, the SQL definitions and my Makefile.
Thanks again
Kostas
On Tue, 21 Jul 1998, Gene Selkov, Jr. wrote:
> Konstantinos Vassiliadis wrote:
> >
> > Hi
> > I am new to Postgres. I am trying to load a C function in Postgres under
> > Red Hat Linux.
> > I compile using
> > gcc -I$PGROOT -I$PGROOT/include -I$PGROOT/src/include -c phone.c
> > to produce the object file 'phone.o'
> > Then I link using
> > ld -Bdynamic -o phone.so phone.o -lc
> > to produce the shared object 'phone.so'.
> > (Assuming I am doing things right so far) Then from psql:
> >
> > => CREATE FUNCTION phone_in(opaque)
> > RETURNS phone
> > AS '/home/M97/acs/vassilik/protein/phone.so'
> > LANGUAGE 'c';
> > NOTICE: ProcedureCreate: type 'phone' is not yet defined
> > CREATE
> >
> > Same for the output function, the type itself and a table that uses the
> > type.
> > Then
> > test=> INSERT INTO test_phone VALUES ('01483-827294','0161-2242394');
> > PQexec() -- Request was sent to backend, but backend closed the channel
> > before responding.
>
> There more than one thing that can go wrong. You are welcome to send me
> your c source and sql to create the type. I will check.
>
> > Can somebody help me? Anybody used Postgres under Linux Red Hat before?
>
> That's how is used most often, I think. You could also try to build one
> of my own extensions, found at
>
> http://wit.mcs.anl.gov/~selkovjr/
>
> ec-type.tgz is the easiest of these.
>
>
> Gene
>
>
#include <stdio.h>
/* In the FAQ section 4.2 it says not to include this header
file when writing user-defined functions #include "libpq-fe.h"*/
/* #include "libpq-fe.h"*/
#include "postgres.h"
#include "utils/palloc.h"
#include "utils/mcxt.h"
typedef struct {
char natcode[6]; /* one extra for the NUL character to fit*/
char number[8];} /* one extra for the NUL character to fit*/
phone;
/* These prototypes declare the requirements that Postgres places on these
user written functions.
*/
phone *phone_in(char *outphone);
char *phone_out(phone *inphone);
/*****************************************************************************
* Input/Output functions
*****************************************************************************/
phone *
phone_in(char *outphone)
{
char nat[6],num[8]; /* one extra for the NUL character to fit*/
phone *result;
int arguments,i;
arguments=sscanf(outphone,"%[0-9]-%[0-9]",nat,num);/* the input string stops at white space or at the maximum field
width,whichever occurs first*/
printf("The function returned %d arguments\n",arguments);
printf("national code:%s\nnumber:%s\n",nat,num);
if (arguments!=2)
return NULL;
result=(phone *) palloc(sizeof(phone));
i=0;
while (nat[i]!='\0')
{
result->natcode[i]=nat[i];
i++;
}
i=0;
while (num[i]!='\0')
{
result->number[i]=num[i];
i++;
}
return (result);
}
char *
phone_out(phone *inphone)
{
char *result;
if (inphone==NULL)
return NULL;
result=(char *)palloc(60);
sprintf(result,"%s-%-s",inphone->natcode,inphone->number);
return result;
}
main()
{
phone *a,*b,*c;
a = phone_in("01483-827294");
printf("a = %s\n", phone_out(a));
b = phone_in("0161-2242394");
printf("b = %s\n", phone_out(b));
c = phone_in("01189-887762");
printf("c = %s\n", phone_out(c));
}
CREATE FUNCTION phone_in(opaque)
RETURNS phone
AS '/home/postgres/linux/src/phone/phone.so'
LANGUAGE 'c';
CREATE FUNCTION phone_out(opaque)
RETURNS opaque
AS '/home/postgres/linux/src/phone/phone.so'
LANGUAGE 'c';
CREATE TYPE phone (
internallength =8,
input = phone_in,
output = phone_out);
CREATE TABLE test_phone (
mynumber phone,
hernumber phone);
INSERT INTO test_phone VALUES ('01483-827294','0161-2242394');
INSERT INTO test_phone VALUES ('0171-8235465','01189-887762');
SELECT * FROM test_phone;
DROP FUNCTION phone_in(opaque);
DROP FUNCTION phone_out(opaque);
DROP TYPE phone;
DROP TABLE test_phone;
SRCDIR= ..
include ../Makefile.global
CFLAGS+= -I$(LIBPQDIR) -I../../include
#
# DLOBJS is the dynamically-loaded object files.
#
DLOBJS= phone$(DLSUFFIX)
ifdef EXPSUFF
DLOBJS+=$(DLOBJS:.o=$(EXPSUFF))
all: $(DLOBJS)
$(DLOBJS): phone.o
gcc -shared -o phone.so phone.o
clean:
rm -f $(DLOBJS)
rm -f *.o *~ *#
pgsql-general by date: