MCPcopy Create free account
hub / github.com/MapServer/MapServer / msPostGISLayerWhichShapes

Function msPostGISLayerWhichShapes

mappostgis.c:2402–2503  ·  view source on GitHub ↗

** msPostGISLayerWhichShapes() ** ** Registered vtable->LayerWhichShapes function. */

Source from the content-addressed store, hash-verified

2400** Registered vtable->LayerWhichShapes function.
2401*/
2402int msPostGISLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery) {
2403#ifdef USE_POSTGIS
2404 msPostGISLayerInfo *layerinfo = NULL;
2405 char *strSQL = NULL;
2406 PGresult *pgresult = NULL;
2407 char** layer_bind_values = (char**)msSmallMalloc(sizeof(char*) * 1000);
2408 char* bind_value;
2409 char* bind_key = (char*)msSmallMalloc(3);
2410
2411 int num_bind_values = 0;
2412
2413 /* try to get the first bind value */
2414 bind_value = msLookupHashTable(&layer->bindvals, "1");
2415 while(bind_value != NULL) {
2416 /* put the bind value on the stack */
2417 layer_bind_values[num_bind_values] = bind_value;
2418 /* increment the counter */
2419 num_bind_values++;
2420 /* create a new lookup key */
2421 sprintf(bind_key, "%d", num_bind_values+1);
2422 /* get the bind_value */
2423 bind_value = msLookupHashTable(&layer->bindvals, bind_key);
2424 }
2425
2426 assert(layer != NULL);
2427 assert(layer->layerinfo != NULL);
2428
2429 if (layer->debug) {
2430 msDebug("msPostGISLayerWhichShapes called.\n");
2431 }
2432
2433 /* Fill out layerinfo with our current DATA state. */
2434 if ( msPostGISParseData(layer) != MS_SUCCESS) {
2435 return MS_FAILURE;
2436 }
2437
2438 /*
2439 ** This comes *after* parsedata, because parsedata fills in
2440 ** layer->layerinfo.
2441 */
2442 layerinfo = (msPostGISLayerInfo*) layer->layerinfo;
2443
2444 /* Build a SQL query based on our current state. */
2445 strSQL = msPostGISBuildSQL(layer, &rect, NULL);
2446 if ( ! strSQL ) {
2447 msSetError(MS_QUERYERR, "Failed to build query SQL.", "msPostGISLayerWhichShapes()");
2448 return MS_FAILURE;
2449 }
2450
2451 if (layer->debug) {
2452 msDebug("msPostGISLayerWhichShapes query: %s\n", strSQL);
2453 }
2454
2455 if(num_bind_values > 0) {
2456 pgresult = PQexecParams(layerinfo->pgconn, strSQL, num_bind_values, NULL, (const char**)layer_bind_values, NULL, NULL, 1);
2457 } else {
2458 pgresult = PQexecParams(layerinfo->pgconn, strSQL,0, NULL, NULL, NULL, NULL, 0);
2459 }

Callers

nothing calls this directly

Calls 6

msSmallMallocFunction · 0.85
msLookupHashTableFunction · 0.85
msDebugFunction · 0.85
msPostGISParseDataFunction · 0.85
msPostGISBuildSQLFunction · 0.85
msSetErrorFunction · 0.85

Tested by

no test coverage detected