3

using GDAL 3.0.4 on windows.

Running an ExecuteSQL command on various datasets (shapefiles, geodatabases, ...) works in almost all cases except when i have an SQL query with an ORDER BY containing multiple fields.

For example either of these succeed:

"SELECT * FROM cities ORDER BY CITY_NAME"

"SELECT * FROM cities ORDER BY COUNTRY_NAME"

But this fails:

"SELECT * FROM cities ORDER BY CITY_NAME, COUNTRY_NAME"

The problem in the failure case, is no error is generated, and the returned OGRLayer is not null. The OGRLayer is just in a bad state, and calling any methods on the OGRLAyer causes a crash. (eg. null pointer access) For example, calling GetFeatureCount() on the returned OGRLayer causes crash.

It is not clear from the GDAL documentation if multiple fields in ORDER BY is supported or not. But even if not, it should return an error and a null OGRLayer.

7
  • 1
    Which SQL dialect? OGR, SQLite or some native (PostgreSQL, Oracle etc?)?
    – user30184
    Commented May 28, 2020 at 14:19
  • 1
    OGR dialect. Also forget to mention I'm using the C++ interface. I will put together a testset, was just wondering if this was a known issue or not.
    – spar
    Commented May 28, 2020 at 14:49
  • 1
    First test to do is naturally to sort your data with ogrinfo and see if it works.
    – user30184
    Commented May 28, 2020 at 15:00
  • 1
    must be data specific. I will do some more tests to narrow it down.
    – spar
    Commented May 28, 2020 at 15:03
  • 1
    You may have found a bug in GDAL. When you have a compact description about the issue write mail to gdal-dev.
    – user30184
    Commented May 28, 2020 at 15:07

2 Answers 2

3

This was a bug in GDAL. Has been verified and fixed in future version by the GDAL devs.

https://github.com/OSGeo/gdal/issues/3249

https://github.com/OSGeo/gdal/pull/3252

2

No problem for me with ogrinfo from GDAL 3.1.0 and the states.shp shapefile from the demo dataset that comes with GeoServer. Both the default OGR dialect and SQLite dialect work as supposed. I add the output from the test withj SQLite dialect because OGR dialect selects always geometry which makes the output noisy.

ogrinfo -dialect SQLite -sql "select state_name, state_fips, families from states order by state_name, state_fips" states.shp
INFO: Open of `states.shp'
      using driver `ESRI Shapefile' successful.

Layer name: SELECT
Geometry: None
Feature Count: 49
Layer SRS WKT:
(unknown)
STATE_NAME: String (0.0)
STATE_FIPS: String (0.0)
FAMILIES: Real (0.0)
OGRFeature(SELECT):0
  STATE_NAME (String) = Alabama
  STATE_FIPS (String) = 01
  FAMILIES (Real) = 1103835

OGRFeature(SELECT):1
  STATE_NAME (String) = Arizona
  STATE_FIPS (String) = 04
  FAMILIES (Real) = 940106

OGRFeature(SELECT):2
  STATE_NAME (String) = Arkansas
  STATE_FIPS (String) = 05
  FAMILIES (Real) = 651555

OGRFeature(SELECT):3
  STATE_NAME (String) = California
  STATE_FIPS (String) = 06
  FAMILIES (Real) = 7139394

OGRFeature(SELECT):4
  STATE_NAME (String) = Colorado
  STATE_FIPS (String) = 08
  FAMILIES (Real) = 854214

OGRFeature(SELECT):5
  STATE_NAME (String) = Connecticut
  STATE_FIPS (String) = 09
  FAMILIES (Real) = 864493

OGRFeature(SELECT):6
  STATE_NAME (String) = Delaware
  STATE_FIPS (String) = 10
  FAMILIES (Real) = 175867
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.