Skip to content
Permalink
Browse files

[FEATURE] Compilation support for unary - operation

  • Loading branch information
nyalldawson committed Apr 14, 2016
1 parent 92a1808 commit 0672abbaed506d96ffa5f3a6d3e51109e442ec5b
@@ -93,7 +93,19 @@ QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compileNode( const Qg
}

case QgsExpression::uoMinus:
break;
{
if ( mFlags.testFlag( NoUnaryMinus ) )
return Fail;

QString right;
if ( compileNode( n->operand(), right ) == Complete )
{
result = "( - (" + right + "))";
return Complete;
}

return Fail;
}
}

break;
@@ -50,6 +50,7 @@ class CORE_EXPORT QgsSqlExpressionCompiler
CaseInsensitiveStringMatch = 0x01, //!< Provider performs case-insensitive string matching for all strings
LikeIsCaseInsensitive = 0x02, //!< Provider treats LIKE as case-insensitive
NoNullInBooleanLogic = 0x04, //!< Provider does not support using NULL with boolean logic, eg "(...) OR NULL"
NoUnaryMinus = 0x08, //!< Provider does not unary minus, eg " -( 100 * 2 ) = ..."
};
Q_DECLARE_FLAGS( Flags, Flag )

@@ -17,7 +17,8 @@
#include "qgsogrprovider.h"

QgsOgrExpressionCompiler::QgsOgrExpressionCompiler( QgsOgrFeatureSource* source )
: QgsSqlExpressionCompiler( source->mFields, QgsSqlExpressionCompiler::CaseInsensitiveStringMatch | QgsSqlExpressionCompiler::NoNullInBooleanLogic )
: QgsSqlExpressionCompiler( source->mFields, QgsSqlExpressionCompiler::CaseInsensitiveStringMatch | QgsSqlExpressionCompiler::NoNullInBooleanLogic
| QgsSqlExpressionCompiler::NoUnaryMinus )
, mSource( source )
{
}
@@ -119,14 +119,19 @@ def runGetFeatureTests(self, provider):
self.assert_query(provider, 'name ILIKE \'aPple\'', [2])
self.assert_query(provider, 'name ILIKE \'%pp%\'', [2])
self.assert_query(provider, 'cnt > 0', [1, 2, 3, 4])
self.assert_query(provider, '-cnt > 0', [5])
self.assert_query(provider, 'cnt < 0', [5])
self.assert_query(provider, '-cnt < 0', [1, 2, 3, 4])
self.assert_query(provider, 'cnt >= 100', [1, 2, 3, 4])
self.assert_query(provider, 'cnt <= 100', [1, 5])
self.assert_query(provider, 'pk IN (1, 2, 4, 8)', [1, 2, 4])
self.assert_query(provider, 'cnt = 50 * 2', [1])
self.assert_query(provider, 'cnt = 99 + 1', [1])
self.assert_query(provider, 'cnt = 101 - 1', [1])
self.assert_query(provider, 'cnt - 1 = 99', [1])
self.assert_query(provider, '-cnt - 1 = -101', [1])
self.assert_query(provider, '-(-cnt) = 100', [1])
self.assert_query(provider, '-(cnt) = -(100)', [1])
self.assert_query(provider, 'cnt + 1 = 101', [1])
self.assert_query(provider, 'cnt = 1100 % 1000', [1])
self.assert_query(provider, '"name" || \' \' || "name" = \'Orange Orange\'', [1])
@@ -99,7 +99,12 @@ def uncompiledFilters(self):
'not name = \'Apple\' or not name = \'Apple\'',
'not name = \'Apple\' and pk = 4',
'not name = \'Apple\' and not pk = 4',
'num_char IN (2, 4, 5)'])
'num_char IN (2, 4, 5)',
'-cnt > 0',
'-cnt < 0',
'-cnt - 1 = -101',
'-(-cnt) = 100',
'-(cnt) = -(100)'])

def partiallyCompiledFilters(self):
return set(['name = \'Apple\'',

0 comments on commit 0672abb

Please sign in to comment.
You can’t perform that action at this time.