My Object able solution.....?? - Mailing list pgsql-hackers

From alex@AvengerGear.com (Debian User)
Subject My Object able solution.....??
Date
Msg-id 20020312085642.A3026@AvengerGear.com
Whole thread Raw
Responses Re: My Object able solution.....??  ("Dave Cramer" <dave@fastcrypt.com>)
List 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 




pgsql-hackers by date:

Previous
From: "Luis Alberto Amigo Navarro"
Date:
Subject: Re: need help on tuning tpch
Next
From: mlw
Date:
Subject: pgbench consistency