Skip to content

Commit

Permalink
[mssql] Small fixes to expression compilation
Browse files Browse the repository at this point in the history
- Use [] to correctly quote field names instead of ""
- Don't invalidate provider side limit when not required

Forward port of 8dec70c, because I'm only human and forgot
  • Loading branch information
nyalldawson committed Oct 8, 2018
1 parent 794583e commit 84a8219
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/providers/mssql/qgsmssqlexpressioncompiler.cpp
Expand Up @@ -91,6 +91,15 @@ QString QgsMssqlExpressionCompiler::quotedValue( const QVariant &value, bool &ok
}
}

QString QgsMssqlExpressionCompiler::quotedIdentifier( const QString &identifier )
{
QString quoted = identifier;
quoted.replace( '[', "[[" );
quoted.replace( ']', "]]" );
quoted = quoted.prepend( '[' ).append( ']' );
return quoted;
}

QString QgsMssqlExpressionCompiler::castToReal( const QString &value ) const
{
return QStringLiteral( "CAST((%1) AS REAL)" ).arg( value );
Expand Down
1 change: 1 addition & 0 deletions src/providers/mssql/qgsmssqlexpressioncompiler.h
Expand Up @@ -29,6 +29,7 @@ class QgsMssqlExpressionCompiler : public QgsSqlExpressionCompiler
protected:
Result compileNode( const QgsExpressionNode *node, QString &result ) override;
QString quotedValue( const QVariant &value, bool &ok ) override;
QString quotedIdentifier( const QString& identifier ) override;
QString castToReal( const QString &value ) const override;
QString castToInt( const QString &value ) const override;
QString sqlFunctionFromFunctionName( const QString &fnName ) const override;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqlfeatureiterator.cpp
Expand Up @@ -265,7 +265,7 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest &request )
mOrderByCompiled = false;
}

if ( !mOrderByCompiled )
if ( !mOrderByCompiled && !request.orderBy().isEmpty() )
limitAtProvider = false;

if ( request.limit() >= 0 && limitAtProvider )
Expand Down

0 comments on commit 84a8219

Please sign in to comment.