Skip to content

Commit

Permalink
Fix WFS SortBy support for OGR layers (#4878)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 4, 2014
1 parent 88ec351 commit 05c1a77
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions mapogr.cpp
Expand Up @@ -1376,7 +1376,32 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,
}
else
{
pszLayerDef = msStringConcatenate(pszLayerDef, "SELECT * FROM \"");
const char* pszGeometryColumn;
int i;
pszLayerDef = msStringConcatenate(pszLayerDef, "SELECT ");
for(i = 0; i < layer->numitems; i++)
{
if( i > 0 )
pszLayerDef = msStringConcatenate(pszLayerDef, ", ");
pszLayerDef = msStringConcatenate(pszLayerDef, "\"");
pszLayerDef = msStringConcatenate(pszLayerDef, layer->items[i]);
pszLayerDef = msStringConcatenate(pszLayerDef, "\"");
}

pszLayerDef = msStringConcatenate(pszLayerDef, ", ");
pszGeometryColumn = OGR_L_GetGeometryColumn(psInfo->hLayer);
if( pszGeometryColumn != NULL && pszGeometryColumn[0] != '\0' )
{
pszLayerDef = msStringConcatenate(pszLayerDef, "\"");
pszLayerDef = msStringConcatenate(pszLayerDef, pszGeometryColumn);
pszLayerDef = msStringConcatenate(pszLayerDef, "\"");
}
else
{
/* Add ", *" so that we still have an hope to get the geometry */
pszLayerDef = msStringConcatenate(pszLayerDef, "*");
}
pszLayerDef = msStringConcatenate(pszLayerDef, " FROM \"");
pszLayerDef = msStringConcatenate(pszLayerDef, OGR_FD_GetName(OGR_L_GetLayerDefn(psInfo->hLayer)));
pszLayerDef = msStringConcatenate(pszLayerDef, "\" ORDER BY ");
}
Expand All @@ -1395,15 +1420,16 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,

ACQUIRE_OGR_LOCK;
psInfo->hLayer = OGR_DS_ExecuteSQL( psInfo->hDS, pszLayerDef, NULL, NULL );
msFree(pszLayerDef);
RELEASE_OGR_LOCK;
if( psInfo->hLayer == NULL ) {
msSetError(MS_OGRERR,
"ExecuteSQL(%s) failed.\n%s",
"msOGRFileWhichShapes()",
pszLayerDef, CPLGetLastErrorMsg() );
msFree(pszLayerDef);
return MS_FAILURE;
}
msFree(pszLayerDef);
}

/* ------------------------------------------------------------------
Expand Down

0 comments on commit 05c1a77

Please sign in to comment.