Skip to content

Commit

Permalink
Don't force use of SQL dialect when running ogr queries (fix #14407)
Browse files Browse the repository at this point in the history
Using "SQL" dialect is not recommended as it forces use of the sometimes
buggy SDK query engines. This was breaking the uniqueValues method for
ESRI gdb files.

See https://trac.osgeo.org/gdal/ticket/6415 for GDAL dev recommendation
to use default OGR dialect in place of "SQL" dialect.

(cherry picked from commit 8d9443b)
  • Loading branch information
nyalldawson authored and jef-n committed Mar 23, 2016
1 parent 5278003 commit 31c914d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ bool QgsOgrProvider::createSpatialIndex()
{
QByteArray sql = "CREATE SPATIAL INDEX ON " + quotedIdentifier( layerName ); // quote the layer name so spaces are handled
QgsDebugMsg( QString( "SQL: %1" ).arg( FROM8( sql ) ) );
OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), OGR_L_GetSpatialFilter( ogrOrigLayer ), "" );
OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), OGR_L_GetSpatialFilter( ogrOrigLayer ), nullptr );
}

QFileInfo fi( mFilePath ); // to get the base name
Expand All @@ -1369,9 +1369,9 @@ bool QgsOgrProvider::createAttributeIndex( int field )
{
QByteArray quotedLayerName = quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) ) );
QByteArray dropSql = "DROP INDEX ON " + quotedLayerName;
OGR_DS_ExecuteSQL( ogrDataSource, dropSql.constData(), OGR_L_GetSpatialFilter( ogrOrigLayer ), "SQL" );
OGR_DS_ExecuteSQL( ogrDataSource, dropSql.constData(), OGR_L_GetSpatialFilter( ogrOrigLayer ), nullptr );
QByteArray createSql = "CREATE INDEX ON " + quotedLayerName + " USING " + mEncoding->fromUnicode( fields()[field].name() );
OGR_DS_ExecuteSQL( ogrDataSource, createSql.constData(), OGR_L_GetSpatialFilter( ogrOrigLayer ), "SQL" );
OGR_DS_ExecuteSQL( ogrDataSource, createSql.constData(), OGR_L_GetSpatialFilter( ogrOrigLayer ), nullptr );

QFileInfo fi( mFilePath ); // to get the base name
//find out, if the .idm file is there
Expand Down Expand Up @@ -2434,7 +2434,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
sql += " ORDER BY " + mEncoding->fromUnicode( fld.name() ) + " ASC"; // quoting of fieldname produces a syntax error

QgsDebugMsg( QString( "SQL: %1" ).arg( mEncoding->toUnicode( sql ) ) );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, "SQL" );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, nullptr );
if ( !l )
{
QgsDebugMsg( "Failed to execute SQL" );
Expand Down Expand Up @@ -2472,7 +2472,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
sql += " WHERE " + mEncoding->fromUnicode( mSubsetString );
}

OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, "SQL" );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, nullptr );
if ( !l )
{
QgsDebugMsg( QString( "Failed to execute SQL: %1" ).arg( mEncoding->toUnicode( sql ) ) );
Expand Down Expand Up @@ -2511,7 +2511,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
sql += " WHERE " + mEncoding->fromUnicode( mSubsetString );
}

OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, "SQL" );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, sql.constData(), nullptr, nullptr );
if ( !l )
{
QgsDebugMsg( QString( "Failed to execute SQL: %1" ).arg( mEncoding->toUnicode( sql ) ) );
Expand Down

0 comments on commit 31c914d

Please sign in to comment.