Skip to content
Permalink
Browse files

Add some more expression compilation tests, fix <> string for OGR

  • Loading branch information
nyalldawson committed Nov 18, 2015
1 parent 35d0dd3 commit 982490f6368617ec63635d8bec5ccb9d35abb04e
Showing with 19 additions and 0 deletions.
  1. +8 −0 src/core/qgssqlexpressioncompiler.cpp
  2. +11 −0 tests/src/python/providertestbase.py
@@ -94,6 +94,7 @@ QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compileNode( const Qg

QString op;
bool partialCompilation = false;
bool failOnPartialNode = false;
switch ( n->op() )
{
case QgsExpression::boEQ:
@@ -129,6 +130,7 @@ QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compileNode( const Qg

case QgsExpression::boIsNot:
op = "IS NOT";
failOnPartialNode = mFlags.testFlag( CaseInsensitiveStringMatch );
break;

case QgsExpression::boLike:
@@ -146,9 +148,11 @@ QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compileNode( const Qg
case QgsExpression::boNotLike:
op = "NOT LIKE";
partialCompilation = mFlags.testFlag( LikeIsCaseInsensitive );
failOnPartialNode = mFlags.testFlag( CaseInsensitiveStringMatch );
break;

case QgsExpression::boNotILike:
failOnPartialNode = mFlags.testFlag( CaseInsensitiveStringMatch );
if ( mFlags.testFlag( LikeIsCaseInsensitive ) )
op = "NOT LIKE";
else
@@ -164,6 +168,7 @@ QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compileNode( const Qg
break;

case QgsExpression::boNE:
failOnPartialNode = mFlags.testFlag( CaseInsensitiveStringMatch );
op = "<>";
break;

@@ -211,6 +216,9 @@ QgsSqlExpressionCompiler::Result QgsSqlExpressionCompiler::compileNode( const Qg
QString right;
Result rr( compileNode( n->opRight(), right ) );

if ( failOnPartialNode && ( lr == Partial || rr == Partial ) )
return Fail;

result = left + ' ' + op + ' ' + right;
if ( lr == Complete && rr == Complete )
return ( partialCompilation ? Partial : Complete );
@@ -41,7 +41,10 @@ def runGetFeatureTests(self, provider):
self.assert_query(provider, '"name" NOT ILIKE \'QGIS\'', [1, 2, 3, 4])
self.assert_query(provider, '"name" NOT ILIKE \'pEAR\'', [1, 2, 4])
self.assert_query(provider, 'name = \'Apple\'', [2])
self.assert_query(provider, 'name <> \'Apple\'', [1, 3, 4])
self.assert_query(provider, 'name = \'apple\'', [])
self.assert_query(provider, '"name" <> \'apple\'', [1, 2, 3, 4])
self.assert_query(provider, '(name = \'Apple\') is not null', [1, 2, 3, 4])
self.assert_query(provider, 'name LIKE \'Apple\'', [2])
self.assert_query(provider, 'name LIKE \'aPple\'', [])
self.assert_query(provider, 'name ILIKE \'aPple\'', [2])
@@ -84,6 +87,14 @@ def runGetFeatureTests(self, provider):
self.assert_query(provider, 'not true', [])
self.assert_query(provider, 'not false', [1, 2, 3, 4, 5])
self.assert_query(provider, 'not null', [])
#not
self.assert_query(provider, 'not name = \'Apple\'', [1, 3, 4])
self.assert_query(provider, 'not name IS NULL', [1, 2, 3, 4])
self.assert_query(provider, 'not name = \'Apple\' or name = \'Apple\'', [1, 2, 3, 4])
self.assert_query(provider, 'not name = \'Apple\' or not name = \'Apple\'', [1, 3, 4])
self.assert_query(provider, 'not name = \'Apple\' and pk = 4', [4])
self.assert_query(provider, 'not name = \'Apple\' and not pk = 4', [1, 3])
self.assert_query(provider, 'not pk IN (1, 2, 4, 8)', [3, 5])

def testGetFeaturesUncompiled(self):
try:

0 comments on commit 982490f

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