]> granicus.if.org Git - postgis/commitdiff
Added a geometry type OID extractor and caching function.
authorSandro Santilli <strk@keybit.net>
Fri, 7 Jan 2005 14:20:14 +0000 (14:20 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 7 Jan 2005 14:20:14 +0000 (14:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1256 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_pg.c
lwgeom/lwgeom_pg.h

index 411d06d517f0e046a00d5e165ce09f53a7e26cc9..00246f72abeb7c024baf336147defbb817f7d2b1 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include "postgres.h"
+#include "executor/spi.h"
 #include "liblwgeom.h"
 #include "lwgeom_pg.h"
 
@@ -126,3 +127,35 @@ pglwgeom_serialize(LWGEOM *in)
 
        return result;
 }
+
+Oid
+getGeometryOID()
+{
+       static Oid OID = InvalidOid;
+       int SPIcode;
+       bool isnull;
+       char *query = "select OID from pg_type where typname = 'geometry'";     
+
+       if ( OID != InvalidOid ) return OID;
+       
+       SPIcode = SPI_connect();
+       if (SPIcode  != SPI_OK_CONNECT) {
+               lwerror("getGeometryOID(): couldn't connection to SPI");
+       }
+
+       SPIcode = SPI_exec(query, 0); 
+       if (SPIcode != SPI_OK_SELECT ) {
+               lwerror("getGeometryOID(): error querying geometry oid");
+       }
+       if (SPI_processed != 1) {
+               lwerror("getGeometryOID(): error querying geometry oid");
+       }
+
+       OID = (Oid)SPI_getbinval(SPI_tuptable->vals[0],
+               SPI_tuptable->tupdesc, 1, &isnull);
+
+       if (isnull) 
+               lwerror("getGeometryOID(): couldn't find geometry oid");
+
+       return OID;
+}
index bb920b7177934d023a93837513da84553f90904d..832e52060135c84ac0aa159eedb9a47ace1ae039 100644 (file)
@@ -19,6 +19,7 @@ void pg_notice(const char *msg, ...);
 
 // Serialize an LWGEOM into a PG_LWGEOM (postgis datatype)
 PG_LWGEOM *pglwgeom_serialize(LWGEOM *lwgeom);
+extern Oid getGeometryOID(void);
 
 // call this as first thing of any PG function
 void init_pg_func(void);