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

Function msPostGISBuildSQL

mappostgis.c:1946–2001  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1944** Returns malloc'ed char* that must be freed by caller.
1945*/
1946char *msPostGISBuildSQL(layerObj *layer, rectObj *rect, long *uid) {
1947
1948 msPostGISLayerInfo *layerinfo = 0;
1949 char *strFrom = 0;
1950 char *strItems = 0;
1951 char *strWhere = 0;
1952 char *strSQL = 0;
1953 static char *strSQLTemplate0 = "select %s from %s where %s";
1954 static char *strSQLTemplate1 = "select %s from %s%s";
1955 char *strSQLTemplate = 0;
1956
1957 if (layer->debug) {
1958 msDebug("msPostGISBuildSQL called.\n");
1959 }
1960
1961 assert( layer->layerinfo != NULL);
1962
1963 layerinfo = (msPostGISLayerInfo *)layer->layerinfo;
1964
1965 strItems = msPostGISBuildSQLItems(layer);
1966 if ( ! strItems ) {
1967 msSetError(MS_MISCERR, "Failed to build SQL items.", "msPostGISBuildSQL()");
1968 return NULL;
1969 }
1970
1971 strFrom = msPostGISBuildSQLFrom(layer, rect);
1972
1973 if ( ! strFrom ) {
1974 msSetError(MS_MISCERR, "Failed to build SQL 'from'.", "msPostGISBuildSQL()");
1975 return NULL;
1976 }
1977
1978 /* If there's BOX hackery going on, we don't want to append a box index test at
1979 the end of the query, the user is going to be responsible for making things
1980 work with their hackery. */
1981 if ( strstr(layerinfo->fromsource, BOXTOKEN) )
1982 strWhere = msPostGISBuildSQLWhere(layer, NULL, uid);
1983 else
1984 strWhere = msPostGISBuildSQLWhere(layer, rect, uid);
1985
1986 if ( ! strWhere ) {
1987 msSetError(MS_MISCERR, "Failed to build SQL 'where'.", "msPostGISBuildSQL()");
1988 return NULL;
1989 }
1990
1991 strSQLTemplate = strlen(strWhere) ? strSQLTemplate0 : strSQLTemplate1;
1992
1993 strSQL = msSmallMalloc(strlen(strSQLTemplate) + strlen(strFrom) + strlen(strItems) + strlen(strWhere));
1994 sprintf(strSQL, strSQLTemplate, strItems, strFrom, strWhere);
1995 if (strItems) free(strItems);
1996 if (strFrom) free(strFrom);
1997 if (strWhere) free(strWhere);
1998
1999 return strSQL;
2000
2001}
2002
2003int msPostGISReadShape(layerObj *layer, shapeObj *shape) {

Callers 2

msPostGISLayerGetShapeFunction · 0.85

Calls 6

msDebugFunction · 0.85
msPostGISBuildSQLItemsFunction · 0.85
msSetErrorFunction · 0.85
msPostGISBuildSQLFromFunction · 0.85
msPostGISBuildSQLWhereFunction · 0.85
msSmallMallocFunction · 0.85

Tested by

no test coverage detected