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

Function msMSSQL2008LayerGetItems

mapmssql2008.c:1562–1637  ·  view source on GitHub ↗

Query the DB for info about the requested table */

Source from the content-addressed store, hash-verified

1560
1561/* Query the DB for info about the requested table */
1562int msMSSQL2008LayerGetItems(layerObj *layer)
1563{
1564 msMSSQL2008LayerInfo *layerinfo;
1565 char *geom_column_name = 0;
1566 char sql[1000];
1567 int t;
1568 char found_geom = 0;
1569 int item_num;
1570 SQLSMALLINT cols = 0;
1571
1572 if(layer->debug)
1573 {
1574 msDebug("in msMSSQL2008LayerGetItems (find column names)\n");
1575 }
1576
1577 layerinfo = getMSSQL2008LayerInfo(layer);
1578
1579 if(!layerinfo)
1580 {
1581 /* layer not opened yet */
1582 msSetError(MS_QUERYERR, "msMSSQL2008LayerGetItems called on unopened layer", "msMSSQL2008LayerGetItems()");
1583
1584 return MS_FAILURE;
1585 }
1586
1587 if(!layerinfo->conn)
1588 {
1589 msSetError(MS_QUERYERR, "msMSSQL2008LayerGetItems called on MSSQL2008 layer with no connection to DB.", "msMSSQL2008LayerGetItems()");
1590
1591 return MS_FAILURE;
1592 }
1593
1594 snprintf(sql, sizeof(sql), "SELECT top 0 * FROM %s", layerinfo->geom_table);
1595
1596 if (!executeSQL(layerinfo->conn, sql))
1597 {
1598 msFree(geom_column_name);
1599
1600 return MS_FAILURE;
1601 }
1602
1603 SQLNumResultCols (layerinfo->conn->hstmt, &cols);
1604
1605 layer->numitems = cols - 1; /* dont include the geometry column */
1606
1607 layer->items = msSmallMalloc(sizeof(char *) * (layer->numitems + 1)); /* +1 in case there is a problem finding goeometry column */
1608 /* it will return an error if there is no geometry column found, */
1609 /* so this isnt a problem */
1610
1611 found_geom = 0; /* havent found the geom field */
1612 item_num = 0;
1613
1614 for(t = 0; t < cols; t++)
1615 {
1616 char colBuff[256];
1617
1618 columnName(layerinfo->conn, t + 1, colBuff, sizeof(colBuff));
1619

Callers

nothing calls this directly

Calls 8

msDebugFunction · 0.85
getMSSQL2008LayerInfoFunction · 0.85
msSetErrorFunction · 0.85
executeSQLFunction · 0.85
msFreeFunction · 0.85
msSmallMallocFunction · 0.85
columnNameFunction · 0.85

Tested by

no test coverage detected