From: | alex(at)AvengerGear(dot)com (Debian User) |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | My Object able solution.....?? |
Date: | 2002-03-12 14:56:42 |
Message-ID: | 20020312085642.A3026@AvengerGear.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Here is my short hack for the object reference ( tuple ) return
as int4 function.
Datum spycastoid(PG_FUNCTION_ARGS);
Datum spycastoidbyname(PG_FUNCTION_ARGS);
/* Composite types */
PG_FUNCTION_INFO_V1(spycastoid);
Datum
spycastoid(PG_FUNCTION_ARGS)
{
TupleTableSlot *t = (TupleTableSlot *) PG_GETARG_POINTER(0);
int32 slot = PG_GETARG_INT32(1);
int32 myid;
bool isnull;
myid = DatumGetInt32(GetAttributeByNum(t, slot, &isnull));
if (isnull)
PG_RETURN_INT32(0);
PG_RETURN_INT32(myid);
}
PG_FUNCTION_INFO_V1(spycastoidbyname);
Datum
spycastoidbyname(PG_FUNCTION_ARGS)
{
TupleTableSlot *t = (TupleTableSlot *) PG_GETARG_POINTER(0);
text *slot = PG_GETARG_TEXT_P(1);
int32 myid;
bool isnull;
/*printf( "cast -->%s<----", slot+VARHDRSZ );*/
myid = DatumGetInt32(GetAttributeByName(t, slot->vl_dat, &isnull));
if (isnull)
PG_RETURN_INT32(0);
PG_RETURN_INT32(myid);
}
***************FUNCTION A******************************
CREATE FUNCTION spycastoid( table_has_other_object, int4) RETURNS int4
AS '/usr/lib/postgresql/lib/castfunc.so'
LANGUAGE 'c';
***************FUNCTION A2******************************
CREATE FUNCTION castoid(table_has_other_object) RETURNS int4
AS 'select spycastoid($1, 1);' <---colnum
LANGUAGE 'sql';
***************FUNCTION B******************************
CREATE FUNCTION spycastoidbyname( table_has_other_object , text) RETURNS int4
AS '/usr/lib/postgresql/lib/castfunc.so'
LANGUAGE 'c';
***************FUNCTION B2*****************************
CREATE FUNCTION spycastoidbyname( table_has_other_object ) RETURNS int4
AS 'select spycastoidbyname( $1, \'colname\')'
LANGUAGE 'sql';
so now at lease you can do
select * from child where spycastoid(child, 1)=178120 or preset A2
select * from child where spycastoid(child)=178120
select * from child where spycastoidbyname(child, 'myfather')=178120 or preset B2
select * from child where spycastoidbyname( child )=178120
There may be some bug in between. I'm not sure. When the tuple get by name,
something the string compare is not correct. Let me know if that work.
I really want to see some real object action in PostgreSQL
I'm currently building a Java API for all database to enable object-relation
mapping for rapid application development. Let me know if you want to talk
about this also.
Alex
From | Date | Subject | |
---|---|---|---|
Next Message | mlw | 2002-03-12 15:29:17 | pgbench consistency |
Previous Message | Manuel Martin | 2002-03-12 14:52:03 | how to get info about spatial extension of pgsql? |