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
  • Loading branch information
nyalldawson committed May 29, 2017
1 parent db86b73 commit 8dec70c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/providers/mssql/qgsmssqlexpressioncompiler.cpp
Expand Up @@ -77,3 +77,12 @@ QString QgsMssqlExpressionCompiler::quotedValue( const QVariant& value, bool& ok
return QgsSqlExpressionCompiler::quotedValue( value, ok );
}
}

QString QgsMssqlExpressionCompiler::quotedIdentifier( const QString &identifier )
{
QString quoted = identifier;
quoted.replace( '[', "[[" );
quoted.replace( ']', "]]" );
quoted = quoted.prepend( '[' ).append( ']' );
return quoted;
}
1 change: 1 addition & 0 deletions src/providers/mssql/qgsmssqlexpressioncompiler.h
Expand Up @@ -29,6 +29,7 @@ class QgsMssqlExpressionCompiler : public QgsSqlExpressionCompiler
protected:
virtual Result compileNode( const QgsExpression::Node* node, QString& result ) override;
virtual QString quotedValue( const QVariant& value, bool& ok ) override;
virtual QString quotedIdentifier( const QString& identifier ) override;

};

Expand Down
4 changes: 2 additions & 2 deletions src/providers/mssql/qgsmssqlfeatureiterator.cpp
Expand Up @@ -109,7 +109,7 @@ void QgsMssqlFeatureIterator::BuildStatement( const QgsFeatureRequest& request )
mStatement += QString( ",[%1]" ).arg( mSource->mGeometryColName );
}

mStatement += QString( "FROM [%1].[%2]" ).arg( mSource->mSchemaName, mSource->mTableName );
mStatement += QString( " FROM [%1].[%2]" ).arg( mSource->mSchemaName, mSource->mTableName );

bool filterAdded = false;
// set spatial filter
Expand Down Expand Up @@ -247,7 +247,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 8dec70c

Please sign in to comment.