@@ -3604,7 +3604,7 @@ QSet<QVariant> QgsOgrProvider::uniqueValues( int index, int limit ) const
36043604 sql += " WHERE " + textEncoding ()->fromUnicode ( mSubsetString );
36053605 }
36063606
3607- sql += " ORDER BY " + textEncoding ()->fromUnicode ( fld.name () ) + " ASC" ; // quoting of fieldname produces a syntax error
3607+ sql += " ORDER BY " + quotedIdentifier ( textEncoding ()->fromUnicode ( fld.name () ) ) + " ASC" ;
36083608
36093609 QgsDebugMsg ( QStringLiteral ( " SQL: %1" ).arg ( textEncoding ()->toUnicode ( sql ) ) );
36103610 QgsOgrLayerUniquePtr l = mOgrLayer ->ExecuteSQL ( sql );
@@ -3649,7 +3649,7 @@ QStringList QgsOgrProvider::uniqueStringsMatching( int index, const QString &sub
36493649 sql += " AND (" + textEncoding ()->fromUnicode ( mSubsetString ) + ' )' ;
36503650 }
36513651
3652- sql += " ORDER BY " + textEncoding ()->fromUnicode ( fld.name () ) + " ASC" ; // quoting of fieldname produces a syntax error
3652+ sql += " ORDER BY " + quotedIdentifier ( textEncoding ()->fromUnicode ( fld.name () ) ) + " ASC" ;
36533653
36543654 QgsDebugMsg ( QStringLiteral ( " SQL: %1" ).arg ( textEncoding ()->toUnicode ( sql ) ) );
36553655 QgsOgrLayerUniquePtr l = mOgrLayer ->ExecuteSQL ( sql );
@@ -3681,7 +3681,7 @@ QVariant QgsOgrProvider::minimumValue( int index ) const
36813681 QgsField fld = mAttributeFields .at ( index );
36823682
36833683 // Don't quote column name (see https://trac.osgeo.org/gdal/ticket/5799#comment:9)
3684- QByteArray sql = " SELECT MIN(" + textEncoding ()->fromUnicode ( fld.name () );
3684+ QByteArray sql = " SELECT MIN(" + quotedIdentifier ( textEncoding ()->fromUnicode ( fld.name () ) );
36853685 sql += " ) FROM " + quotedIdentifier ( mOgrLayer ->name () );
36863686
36873687 if ( !mSubsetString .isEmpty () )
@@ -3715,7 +3715,7 @@ QVariant QgsOgrProvider::maximumValue( int index ) const
37153715 QgsField fld = mAttributeFields .at ( index );
37163716
37173717 // Don't quote column name (see https://trac.osgeo.org/gdal/ticket/5799#comment:9)
3718- QByteArray sql = " SELECT MAX(" + textEncoding ()->fromUnicode ( fld.name () );
3718+ QByteArray sql = " SELECT MAX(" + quotedIdentifier ( textEncoding ()->fromUnicode ( fld.name () ) );
37193719 sql += " ) FROM " + quotedIdentifier ( mOgrLayer ->name () );
37203720
37213721 if ( !mSubsetString .isEmpty () )
0 commit comments