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

Function msMSSQL2008LayerRetrievePK

mapmssql2008.c:1665–1748  ·  view source on GitHub ↗

Get primary key column of table */

Source from the content-addressed store, hash-verified

1663
1664/* Get primary key column of table */
1665int msMSSQL2008LayerRetrievePK(layerObj *layer, char **urid_name, char* table_name, int debug)
1666{
1667
1668 char sql[1024];
1669 msMSSQL2008LayerInfo *layerinfo = 0;
1670 SQLRETURN rc;
1671
1672 snprintf(sql, sizeof(sql),
1673 "SELECT convert(varchar(50), sys.columns.name) AS ColumnName, sys.indexes.name "
1674 "FROM sys.columns INNER JOIN "
1675 " sys.indexes INNER JOIN "
1676 " sys.tables ON sys.indexes.object_id = sys.tables.object_id INNER JOIN "
1677 " sys.index_columns ON sys.indexes.object_id = sys.index_columns.object_id AND sys.indexes.index_id = sys.index_columns.index_id ON "
1678 " sys.columns.object_id = sys.index_columns.object_id AND sys.columns.column_id = sys.index_columns.column_id "
1679 "WHERE (sys.indexes.is_primary_key = 1) AND (sys.tables.name = N'%s') ",
1680 table_name);
1681
1682 if (debug)
1683 {
1684 msDebug("msMSSQL2008LayerRetrievePK: query = %s\n", sql);
1685 }
1686
1687 layerinfo = (msMSSQL2008LayerInfo *) layer->layerinfo;
1688
1689 if(layerinfo->conn == NULL)
1690 {
1691
1692 msSetError(MS_QUERYERR, "Layer does not have a MSSQL2008 connection.", "msMSSQL2008LayerRetrievePK()");
1693
1694 return(MS_FAILURE);
1695 }
1696
1697 /* error somewhere above here in this method */
1698
1699 if(!executeSQL(layerinfo->conn, sql))
1700 {
1701 char *tmp1;
1702 char *tmp2 = NULL;
1703
1704 tmp1 = "Error executing MSSQL2008 statement (msMSSQL2008LayerRetrievePK():";
1705 tmp2 = (char *)msSmallMalloc(sizeof(char)*(strlen(tmp1) + strlen(sql) + 1));
1706 strcpy(tmp2, tmp1);
1707 strcat(tmp2, sql);
1708 msSetError(MS_QUERYERR, tmp2, "msMSSQL2008LayerRetrievePK()");
1709 msFree(tmp2);
1710 return(MS_FAILURE);
1711 }
1712
1713 rc = SQLFetch(layerinfo->conn->hstmt);
1714
1715 if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
1716 {
1717 if(debug)
1718 {
1719 msDebug("msMSSQL2008LayerRetrievePK: No results found.\n");
1720 }
1721
1722 return MS_FAILURE;

Callers 1

Calls 6

msDebugFunction · 0.85
msSetErrorFunction · 0.85
executeSQLFunction · 0.85
msSmallMallocFunction · 0.85
msFreeFunction · 0.85
msStrdupFunction · 0.85

Tested by

no test coverage detected