Ticket #2788 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Issues related to wildcard expansion in SQL result layer

Reported by: rouault Owned by: 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

Changed 3 years ago by rouault

  • status changed from new to closed
  • resolution set to fixed

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

Changed 3 years ago by rouault

  • status changed from closed to reopened
  • resolution fixed deleted

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

Changed 3 years ago by rouault

  • status changed from reopened to closed
  • resolution set to fixed

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

Changed 3 years ago by rouault

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' )

Changed 3 years ago by rouault

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

Note: See TracTickets for help on using tickets.