MCPcopy Index your code
hub / github.com/MapServer/MapServer / msPostGISBuildSQLWhere

Function msPostGISBuildSQLWhere

mappostgis.c:1829–1939  ·  view source on GitHub ↗

** msPostGISBuildSQLWhere() ** ** Returns malloc'ed char* that must be freed by caller. */

Source from the content-addressed store, hash-verified

1827** Returns malloc'ed char* that must be freed by caller.
1828*/
1829char *msPostGISBuildSQLWhere(layerObj *layer, rectObj *rect, long *uid) {
1830 char *strRect = 0;
1831 char *strFilter = 0;
1832 char *strUid = 0;
1833 char *strWhere = 0;
1834 char *strLimit = 0;
1835 size_t strRectLength = 0;
1836 size_t strFilterLength = 0;
1837 size_t strUidLength = 0;
1838 size_t strLimitLength = 0;
1839 size_t bufferSize = 0;
1840 int insert_and = 0;
1841 msPostGISLayerInfo *layerinfo;
1842
1843 if (layer->debug) {
1844 msDebug("msPostGISBuildSQLWhere called.\n");
1845 }
1846
1847 assert( layer->layerinfo != NULL);
1848
1849 layerinfo = (msPostGISLayerInfo *)layer->layerinfo;
1850
1851 if ( ! layerinfo->fromsource ) {
1852 msSetError(MS_MISCERR, "Layerinfo->fromsource is not initialized.", "msPostGISBuildSQLWhere()");
1853 return NULL;
1854 }
1855
1856 /* Populate strLimit, if necessary. */
1857 if( layer->maxfeatures >= 0 ) {
1858 static char *strLimitTemplate = " limit %d";
1859 strLimit = msSmallMalloc(strlen(strLimitTemplate) + 12);
1860 sprintf(strLimit, strLimitTemplate, layer->maxfeatures);
1861 strLimitLength = strlen(strLimit);
1862 }
1863
1864 /* Populate strRect, if necessary. */
1865 if ( rect && layerinfo->geomcolumn ) {
1866 char *strBox = 0;
1867 char *strSRID = 0;
1868 size_t strBoxLength = 0;
1869 static char *strRectTemplate = "%s && %s";
1870
1871 /* We see to set the SRID on the box, but to what SRID? */
1872 strSRID = msPostGISBuildSQLSRID(layer);
1873 if ( ! strSRID ) {
1874 return NULL;
1875 }
1876
1877 strBox = msPostGISBuildSQLBox(layer, rect, strSRID);
1878 if ( strBox ) {
1879 strBoxLength = strlen(strBox);
1880 }
1881 else {
1882 msSetError(MS_MISCERR, "Unable to build box SQL.", "msPostGISBuildSQLWhere()");
1883 return NULL;
1884 }
1885
1886 strRect = (char*)msSmallMalloc(strlen(strRectTemplate) + strBoxLength + strlen(layerinfo->geomcolumn));

Callers 1

msPostGISBuildSQLFunction · 0.85

Calls 6

msDebugFunction · 0.85
msSetErrorFunction · 0.85
msSmallMallocFunction · 0.85
msPostGISBuildSQLSRIDFunction · 0.85
msPostGISBuildSQLBoxFunction · 0.85
strlcatFunction · 0.85

Tested by

no test coverage detected