From: Sandro Santilli Date: Thu, 14 Sep 2017 14:30:57 +0000 (+0000) Subject: Only prepare statements on first run X-Git-Tag: 2.4.0rc2~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=164586f09b2afa98eeeac931d657bc399ce87722;p=postgis Only prepare statements on first run git-svn-id: http://svn.osgeo.org/postgis/trunk@15728 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/topology/postgis_topology.c b/topology/postgis_topology.c index 5ec7cfab3..5718b8874 100644 --- a/topology/postgis_topology.c +++ b/topology/postgis_topology.c @@ -169,22 +169,24 @@ cb_loadTopologyByName(const LWT_BE_DATA* be, const char *name) Oid argtypes[1]; static SPIPlanPtr plan = NULL; - // prepare - sql = "SELECT id,srid,precision,null::geometry" - " FROM topology.topology " - "WHERE name = $1::varchar"; argtypes[0] = CSTRINGOID; - plan = SPI_prepare(sql, 1, argtypes); - if ( ! plan ) + if ( ! plan ) /* prepare on first call */ { - cberror(be, "unexpected return (%d) from query preparation: %s", - SPI_result, sql); - return NULL; + sql = "SELECT id,srid,precision,null::geometry" + " FROM topology.topology " + "WHERE name = $1::varchar"; + plan = SPI_prepare(sql, 1, argtypes); + if ( ! plan ) + { + cberror(be, "unexpected return (%d) from query preparation: %s", + SPI_result, sql); + return NULL; + } + SPI_keepplan(plan); + /* SPI_freeplan to free, eventually */ } - SPI_keepplan(plan); - // SPI_freeplan to free, eventually - // execute + /* execute */ values[0] = CStringGetDatum(name); spi_result = SPI_execute_plan(plan, values, NULL, !be->data_changed, 1); MemoryContextSwitchTo( oldcontext ); /* switch back */ @@ -194,7 +196,6 @@ cb_loadTopologyByName(const LWT_BE_DATA* be, const char *name) } if ( ! SPI_processed ) { - //cberror(be, "no topology named '%s' was found", name); if ( be->topoLoadFailMessageFlavor == 1 ) { cberror(be, "No topology with name \"%s\" in topology.topology", name); } else {