Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#5879 closed defect (fixed)

GeoPackage driver fails to prepare SQL to read vector feature

Reported by: Mike Taves Owned by: warmerdam
Priority: normal Milestone: 1.11.3
Component: OGR_SF Version: 1.11.1
Severity: normal Keywords: gpkg
Cc:

Description

With GDAL 1.11.1, I can normally use the GeoPackage driver to read files with OGR. However with one file landonline-land-district.gpkg, I cannot. For example:

$ ogrinfo landonline-land-district.gpkg landonline_land_district
INFO: Open of `landonline-land-district.gpkg'
      using driver `GPKG' successful.

Layer name: landonline_land_district
Geometry: Multi Polygon
Feature Count: 12
Extent: (1066760.000000, 4700190.000000) - (2523320.000000, 6237680.000000)
Layer SRS WKT:
PROJCS["NZGD2000 / New Zealand Transverse Mercator 2000",
    GEOGCS["NZGD2000",
        DATUM["New_Zealand_Geodetic_Datum_2000",
            SPHEROID["GRS 1980",6378137,298.257222101,
                AUTHORITY["EPSG","7019"]],
            TOWGS84[0,0,0,0,0,0,0],
            AUTHORITY["EPSG","6167"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.01745329251994328,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4167"]],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",173],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",1600000],
    PARAMETER["false_northing",10000000],
    AUTHORITY["EPSG","2193"],
    AXIS["Northing",NORTH],
    AXIS["Easting",EAST]]
FID Column = fid
Geometry Column = geom
loc_id: Integer (0.0)
off_code: String (0.0)
default: String (0.0)
audit_id: Integer (0.0)
se_row_id: Integer (0.0)
usr_tm_id: String (0.0)
ERROR 1: failed to prepare SQL: SELECT fid, geom, loc_id, off_code, default, audit_id, se_row_id, usr_tm_id FROM landonline_land_district

The exact same error message is shown if I use a -sql option with one column loc_id, so I can't seem to limit querying all columns.

When opening the same file from Python, GetFeatureCount() shows 12 for the layer, but GetFeature(2) raises a similar error:

RuntimeError: failed to prepare SQL: SELECT fid, geom, loc_id, off_code, default, audit_id, se_row_id, usr_tm_id FROM landonline_land_district WHERE fid = 2


My best guess is that the bare SQL keyword default is used as a field name. This normally raises a syntax or operational, unless quoted in an SQL statement, i.e. "default". So this works:

SELECT fid, geom, loc_id, off_code, "default", audit_id, se_row_id, usr_tm_id FROM landonline_land_district

Change History (4)

comment:1 by Mike Taves, 9 years ago

I've attempted to attach the 5.8 MB file to this ticket, but it is too large for the 1 MB limit. For the moment, you can unofficially get it from here (it normally requires a login to download from LINZ). It is licensed under Creative Commons Attribution 3.0 New Zealand.

comment:2 by Even Rouault, 9 years ago

Component: defaultOGR_SF
Keywords: gpkg added
Milestone: 1.11.3
Resolution: fixed
Status: newclosed

branches/1.11 r28742 "GPKG: escape column names on reading/insert/update (backport from trunk, #5879)"

comment:3 by Kyle Shannon, 9 years ago

EvenR,

Is #5520 related here?

in reply to:  3 comment:4 by Even Rouault, 9 years ago

Replying to kyle:

EvenR,

Is #5520 related here?

Yes those are the same issue indeed

Note: See TracTickets for help on using tickets.