#include <stdlib.h>
#include <stdarg.h>
#include "postgres.h"
+#include "executor/spi.h"
#include "liblwgeom.h"
#include "lwgeom_pg.h"
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;
+}
// 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);