@@ -1376,7 +1376,32 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,
1376
1376
}
1377
1377
else
1378
1378
{
1379
- pszLayerDef = msStringConcatenate (pszLayerDef, " SELECT * FROM \" " );
1379
+ const char * pszGeometryColumn;
1380
+ int i;
1381
+ pszLayerDef = msStringConcatenate (pszLayerDef, " SELECT " );
1382
+ for (i = 0 ; i < layer->numitems ; i++)
1383
+ {
1384
+ if ( i > 0 )
1385
+ pszLayerDef = msStringConcatenate (pszLayerDef, " , " );
1386
+ pszLayerDef = msStringConcatenate (pszLayerDef, " \" " );
1387
+ pszLayerDef = msStringConcatenate (pszLayerDef, layer->items [i]);
1388
+ pszLayerDef = msStringConcatenate (pszLayerDef, " \" " );
1389
+ }
1390
+
1391
+ pszLayerDef = msStringConcatenate (pszLayerDef, " , " );
1392
+ pszGeometryColumn = OGR_L_GetGeometryColumn (psInfo->hLayer );
1393
+ if ( pszGeometryColumn != NULL && pszGeometryColumn[0 ] != ' \0 ' )
1394
+ {
1395
+ pszLayerDef = msStringConcatenate (pszLayerDef, " \" " );
1396
+ pszLayerDef = msStringConcatenate (pszLayerDef, pszGeometryColumn);
1397
+ pszLayerDef = msStringConcatenate (pszLayerDef, " \" " );
1398
+ }
1399
+ else
1400
+ {
1401
+ /* Add ", *" so that we still have an hope to get the geometry */
1402
+ pszLayerDef = msStringConcatenate (pszLayerDef, " *" );
1403
+ }
1404
+ pszLayerDef = msStringConcatenate (pszLayerDef, " FROM \" " );
1380
1405
pszLayerDef = msStringConcatenate (pszLayerDef, OGR_FD_GetName (OGR_L_GetLayerDefn (psInfo->hLayer )));
1381
1406
pszLayerDef = msStringConcatenate (pszLayerDef, " \" ORDER BY " );
1382
1407
}
@@ -1395,15 +1420,16 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect,
1395
1420
1396
1421
ACQUIRE_OGR_LOCK;
1397
1422
psInfo->hLayer = OGR_DS_ExecuteSQL ( psInfo->hDS , pszLayerDef, NULL , NULL );
1398
- msFree (pszLayerDef);
1399
1423
RELEASE_OGR_LOCK;
1400
1424
if ( psInfo->hLayer == NULL ) {
1401
1425
msSetError (MS_OGRERR,
1402
1426
" ExecuteSQL(%s) failed.\n %s" ,
1403
1427
" msOGRFileWhichShapes()" ,
1404
1428
pszLayerDef, CPLGetLastErrorMsg () );
1429
+ msFree (pszLayerDef);
1405
1430
return MS_FAILURE;
1406
1431
}
1432
+ msFree (pszLayerDef);
1407
1433
}
1408
1434
1409
1435
/* ------------------------------------------------------------------
0 commit comments