Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#2788 closed defect (fixed)

Issues related to wildcard expansion in SQL result layer

Reported by: Even Rouault Owned by: Even Rouault
Priority: normal Milestone: 1.6.1
Component: OGR_SF Version: unspecified
Severity: normal Keywords: sql wildcard
Cc:

Description

3 issues related to wildcard expansion :

  • Currently, the result of the GetFeatureCount() in the following snippet is always 1, whatever the number of features in the source layer. This is due to the fact that the source layer has no field (a shapefile without a .dbf, a memory datasource with no field, etc..). In OGRGenSQLResultsLayer::GetFeatureCount, psSelectInfo->query_mode must be set to SWQM_RECORDSET to return a value different from 1, so in swq_select_parse, we must set the query_mode to SWQM_RECORDSET when select_info->result_columns == 0.
###############################################################################
# Test query on layer without any field

def ogr_sql_20():

    mem_ds = ogr.GetDriverByName("Memory").CreateDataSource( "my_ds")
    mem_lyr = mem_ds.CreateLayer( "my_layer")

    feat = ogr.Feature(mem_lyr.GetLayerDefn() )
    feat.SetGeometry(ogr.CreateGeometryFromWkt("POINT(0 1)"))
    mem_lyr.CreateFeature( feat )

    feat = ogr.Feature(mem_lyr.GetLayerDefn() )
    feat.SetGeometry(ogr.CreateGeometryFromWkt("POINT(2 3)"))
    mem_lyr.CreateFeature( feat )

    sql_lyr = mem_ds.ExecuteSQL("SELECT * from my_layer")
    if sql_lyr.GetFeatureCount() != 2:
        return 'fail'
    mem_ds.ReleaseResultSet(sql_lyr)
    mem_ds = None

    return 'success'
  • Another related issue is that sql_lyr = mem_ds.ExecuteSQL("SELECT *, fid from my_layer") causes a crash when my_layer has no field
  • Another related issue is that multiple expansion of wildcard doesn't work, as in sql_lyr = mem_ds.ExecuteSQL("SELECT *, * from my_layer"). Only the first wildcard is expanded.

Change History (5)

comment:1 by Even Rouault, 15 years ago

Resolution: fixed
Status: newclosed

Fixed in trunk in r16116 and in branches/1.6 in r16117. Tests added in r16118

comment:2 by Even Rouault, 15 years ago

Resolution: fixed
Status: closedreopened

Other issue detected. OGRGenSQLResultsLayer::GetFeatureCount() doesn't work on a SELECT DISTINCT result.

comment:3 by Even Rouault, 15 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in trunk in r16135 and in branches/1.6 in r16136. Test added in r16137

comment:4 by Even Rouault, 15 years ago

One more problem detected. The following variant of ogr_join_3 causes memory corruption :

    sql_lyr = gdaltest.ds.ExecuteSQL( 	\
        'SELECT poly.* FROM poly ' \
        + 'LEFT JOIN idlink ON poly.eas_id = idlink.eas_id ' \
        + 'WHERE eas_id > 170' )

comment:5 by Even Rouault, 15 years ago

Fixed in trunk (r16929) and branches/1.6 (r16930). Test added in r16931

Note: See TracTickets for help on using tickets.