]> granicus.if.org Git - postgis/commitdiff
Checked connection to SPI manager in ST_MapAlgebraExpr
authorDavid Zwarg <dzwarg@azavea.com>
Mon, 6 Feb 2012 18:36:07 +0000 (18:36 +0000)
committerDavid Zwarg <dzwarg@azavea.com>
Mon, 6 Feb 2012 18:36:07 +0000 (18:36 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9042 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rt_pg.c

index 3c71cb93b56455f9bc6302681f68a38dab733809..1e4ef01d43bb3c66c3f89db55e0a5068921852c6 100644 (file)
@@ -2522,14 +2522,15 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS)
     char *newexpr = NULL;
     char *initexpr = NULL;
     char *expression = NULL;
-               int hasnodataval = 0;
-               double nodataval = 0.;
+    int hasnodataval = 0;
+    double nodataval = 0.;
     rt_pixtype newpixeltype;
     int skipcomputation = 0;
     char strnewval[50];
     int len = 0;
     int ret = -1;
     TupleDesc tupdesc;
+    SPIPlanPtr spi_plan = NULL;
     SPITupleTable * tuptable = NULL;
     HeapTuple tuple;
     char * strFromText = NULL;
@@ -2824,8 +2825,12 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS)
      * [rast)
      **/
     if (initexpr != NULL && strstr(initexpr, "[rast") == NULL) {
-
-        SPI_connect();
+        ret = SPI_connect();
+        if (ret != SPI_OK_CONNECT) {
+            elog(ERROR, "RASTER_mapAlgebraExpr: Unable to connect to the SPI manager."
+                " Aborting");
+            PG_RETURN_NULL();
+        };
 
         /* Execute the expresion into newval */
         ret = SPI_execute(initexpr, FALSE, 0);