diff --git a/src/providers/postgres/qgspostgresfeatureiterator.cpp b/src/providers/postgres/qgspostgresfeatureiterator.cpp index 4a5b5d8e7b4..1cb611dcbe8 100644 --- a/src/providers/postgres/qgspostgresfeatureiterator.cpp +++ b/src/providers/postgres/qgspostgresfeatureiterator.cpp @@ -116,29 +116,38 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource mOrderByCompiled = true; - Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, request.orderBys() ) + if ( QSettings().value( "/qgis/compileExpressions", true ).toBool() ) { - QgsPostgresExpressionCompiler compiler = QgsPostgresExpressionCompiler( source ); - QgsExpression expression = clause.expression(); - if ( compiler.compile( &expression ) == QgsSqlExpressionCompiler::Complete ) + Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, request.orderBys() ) { - QString part; - part = compiler.result(); - part += clause.ascending() ? " ASC" : " DESC"; - part += clause.nullsFirst() ? " NULLS FIRST" : " NULLS LAST"; - orderByParts << part; - } - else - { - // Bail out on first non-complete compilation. - // Most important clauses at the beginning of the list - // will still be sent and used to pre-sort so the local - // CPU can use its cycles for fine-tuning. - mOrderByCompiled = false; - limitAtProvider = false; - break; + QgsPostgresExpressionCompiler compiler = QgsPostgresExpressionCompiler( source ); + QgsExpression expression = clause.expression(); + if ( compiler.compile( &expression ) == QgsSqlExpressionCompiler::Complete ) + { + QString part; + part = compiler.result(); + part += clause.ascending() ? " ASC" : " DESC"; + part += clause.nullsFirst() ? " NULLS FIRST" : " NULLS LAST"; + orderByParts << part; + } + else + { + // Bail out on first non-complete compilation. + // Most important clauses at the beginning of the list + // will still be sent and used to pre-sort so the local + // CPU can use its cycles for fine-tuning. + mOrderByCompiled = false; + break; + } } } + else + { + mOrderByCompiled = false; + } + + if ( !mOrderByCompiled ) + limitAtProvider = false; bool success = declareCursor( whereClause, limitAtProvider ? mRequest.limit() : -1, false, orderByParts.join( "," ) ); if ( !success && useFallbackWhereClause ) diff --git a/src/providers/spatialite/qgsspatialitefeatureiterator.cpp b/src/providers/spatialite/qgsspatialitefeatureiterator.cpp index 5211e41cddd..b43a84878d9 100644 --- a/src/providers/spatialite/qgsspatialitefeatureiterator.cpp +++ b/src/providers/spatialite/qgsspatialitefeatureiterator.cpp @@ -121,34 +121,43 @@ QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator( QgsSpatiaLiteFeature mOrderByCompiled = true; - Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, request.orderBys() ) + if ( QSettings().value( "/qgis/compileExpressions", true ).toBool() ) { - QgsSpatiaLiteExpressionCompiler compiler = QgsSpatiaLiteExpressionCompiler( source ); - QgsExpression expression = clause.expression(); - if ( compiler.compile( &expression ) == QgsSqlExpressionCompiler::Complete ) + Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, request.orderBys() ) { - QString part; - part = compiler.result(); + QgsSpatiaLiteExpressionCompiler compiler = QgsSpatiaLiteExpressionCompiler( source ); + QgsExpression expression = clause.expression(); + if ( compiler.compile( &expression ) == QgsSqlExpressionCompiler::Complete ) + { + QString part; + part = compiler.result(); - if ( clause.nullsFirst() ) - orderByParts << QString( "%1 IS NOT NULL" ).arg( part ); + if ( clause.nullsFirst() ) + orderByParts << QString( "%1 IS NOT NULL" ).arg( part ); + else + orderByParts << QString( "%1 IS NULL" ).arg( part ); + + part += clause.ascending() ? " COLLATE NOCASE ASC" : " COLLATE NOCASE DESC"; + orderByParts << part; + } else - orderByParts << QString( "%1 IS NULL" ).arg( part ); - - part += clause.ascending() ? " COLLATE NOCASE ASC" : " COLLATE NOCASE DESC"; - orderByParts << part; - } - else - { - // Bail out on first non-complete compilation. - // Most important clauses at the beginning of the list - // will still be sent and used to pre-sort so the local - // CPU can use its cycles for fine-tuning. - mOrderByCompiled = false; - limitAtProvider = false; - break; + { + // Bail out on first non-complete compilation. + // Most important clauses at the beginning of the list + // will still be sent and used to pre-sort so the local + // CPU can use its cycles for fine-tuning. + mOrderByCompiled = false; + break; + } } } + else + { + mOrderByCompiled = false; + } + + if ( !mOrderByCompiled ) + limitAtProvider = false; // preparing the SQL statement bool success = prepareStatement( whereClause, limitAtProvider ? mRequest.limit() : -1, orderByParts.join( "," ) );