[gdal-dev] Change in parsing of OGR where clause

Even Rouault even.rouault at spatialys.com
Wed Apr 6 13:57:19 PDT 2016


Le mercredi 06 avril 2016 22:48:38, Andrew Bell a écrit :
> On Wed, Apr 6, 2016 at 3:39 PM, Even Rouault <even.rouault at spatialys.com>
> 
> wrote:
> > Andrew,
> > 
> > > In version 1.X of GDAL, the following was accepted and worked:
> > > 
> > > std::string query = "LOCATION=\"some text\"";
> > > OGR_L_SetAttributeFilter(layer, query.c_str());
> > > 
> > > In version 2.X, this is no longer accepted and the double quotes must
> > > be replaced by single quotes:
> > > 
> > > std::string query = "LOCATION='some text'";
> > > OGR_L_SetAttributeFilter(layer, query.c_str());
> > > 
> > > This wouldn't be awful, but the error that occurs tells you nothing
> > > about the actual problem.  It yields:
> > > 
> > > "some text" not recognised as an available field.
> > 
> > Well, I find the message quite clear : "some text" isn't an recognized
> > field :-)
> 
> Is there a context where a double-quoted string would be acceptable here?
> If so, then fine (maybe).  But if not, it seems that something like
> "unexpected character '"' found in where clause" would make more sense than
> the current message.
> 

Well, there are cases where your datasource could have field names that require 
double quoting. It is generally not possible to distinguish the cases where 
the user wanted to specify a field name but get it wrong, from the cases where 
he wanted to specify a string literal. If you try with another SQL engine, 
you'd have similar messages :

$ ogrinfo pg:dbname=autotest -sql "select * from poly where eas_id = \"some 
text"" 
INFO: Open of `pg:dbname=autotest'
      using driver `PostgreSQL' successful.
ERROR 1: ERROR: the column « some text » does not exist
LINE 1: ...SQLCursor CURSOR for select * from poly where eas_id = "some text"

> 
> I'm not grumbling about the change, but it took me a while to track down :(
>   A different error message would have helped greatly.

Yes, I can understand that. I encourage everybody looking at the 
MIGRATION_GUIDE when they upgrade their version :
https://svn.osgeo.org/gdal/trunk/gdal/MIGRATION_GUIDE.TXT

> 
> Thanks,

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list