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

Function msMSSQL2008LayerGetShape

mapmssql2008.c:1467–1559  ·  view source on GitHub ↗

Execute a query on the DB based on the query result. */

Source from the content-addressed store, hash-verified

1465
1466/* Execute a query on the DB based on the query result. */
1467int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record)
1468{
1469 char *query_str;
1470 char *columns_wanted = 0;
1471
1472 msMSSQL2008LayerInfo *layerinfo;
1473 int t;
1474 char buffer[32000] = "";
1475 long shapeindex = record->shapeindex;
1476 long resultindex = record->resultindex;
1477
1478 if(layer->debug) {
1479 msDebug("msMSSQL2008LayerGetShape called for shapeindex = %i\n", shapeindex);
1480 }
1481
1482 layerinfo = getMSSQL2008LayerInfo(layer);
1483
1484 if(!layerinfo) {
1485 /* Layer not open */
1486 msSetError(MS_QUERYERR, "msMSSQL2008LayerGetShape called on unopened layer (layerinfo = NULL)", "msMSSQL2008LayerGetShape()");
1487
1488 return MS_FAILURE;
1489 }
1490
1491 if (resultindex >= 0 && layerinfo->sql)
1492 {
1493 /* trying to provide the result from the current resultset (single-pass query) */
1494 if( resultindex < layerinfo->row_num)
1495 {
1496 /* re-issue the query */
1497 if (!executeSQL(layerinfo->conn, layerinfo->sql))
1498 {
1499 msSetError(MS_QUERYERR, "Error executing MSSQL2008 SQL statement: %s\n-%s\n", "msMSSQL2008LayerGetShape()", layerinfo->sql, layerinfo->conn->errorMessage);
1500
1501 return MS_FAILURE;
1502 }
1503 layerinfo->row_num = 0;
1504 }
1505 while( layerinfo->row_num < resultindex )
1506 {
1507 /* move forward until we reach the desired index */
1508 if (msMSSQL2008LayerGetShapeRandom(layer, shape, &(layerinfo->row_num)) != MS_SUCCESS)
1509 return MS_FAILURE;
1510 }
1511
1512 return msMSSQL2008LayerGetShapeRandom(layer, shape, &(layerinfo->row_num));
1513 }
1514
1515 /* non single-pass case, fetch the record from the database */
1516
1517 if(layer->numitems == 0)
1518 {
1519 snprintf(buffer, sizeof(buffer), "%s.STAsBinary(), convert(varchar(36), %s)", layerinfo->geom_column, layerinfo->urid_name);
1520 columns_wanted = msStrdup(buffer);
1521 }
1522 else
1523 {
1524 for(t = 0; t < layer->numitems; t++) {

Callers

nothing calls this directly

Calls 7

msDebugFunction · 0.85
getMSSQL2008LayerInfoFunction · 0.85
msSetErrorFunction · 0.85
executeSQLFunction · 0.85
msStrdupFunction · 0.85
msFreeFunction · 0.85

Tested by

no test coverage detected