Skip to content
Permalink
Browse files

Fix WFS SortBy support for OGR layers (#4878)

  • Loading branch information
rouault committed Mar 4, 2014
1 parent 88ec351 commit 05c1a777c0165f77d6c2c09e6b25c49b42397e6d
Showing with 28 additions and 2 deletions.
  1. +28 −2 mapogr.cpp
@@ -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 ");
}
@@ -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);
}

/* ------------------------------------------------------------------

0 comments on commit 05c1a77

Please sign in to comment.
You can’t perform that action at this time.