Skip to content

Commit

Permalink
[oracle] Fixes for oracle expression compilation
Browse files Browse the repository at this point in the history
On behalf of Faunalia, sponsored by ENEL
  • Loading branch information
nyalldawson committed Jul 6, 2016
1 parent d785b90 commit 64bfbaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/providers/oracle/qgsoracleexpressioncompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ QgsSqlExpressionCompiler::Result QgsOracleExpressionCompiler::compileNode( const

switch ( bin->op() )
{
case QgsExpression::boConcat:
// oracle's handling of || WRT null is not standards compliant
return Fail;

case QgsExpression::boPow:
case QgsExpression::boRegexp:
case QgsExpression::boILike:
case QgsExpression::boNotILike:
case QgsExpression::boMod:
{
QString op1, op2;

Expand All @@ -48,6 +55,18 @@ QgsSqlExpressionCompiler::Result QgsOracleExpressionCompiler::compileNode( const
result = QString( "regexp_like(%1,%2)" ).arg( op1, op2 );
return Complete;

case QgsExpression::boILike:
result = QString( "lower(%1) LIKE lower(%2)" ).arg( op1, op2 );
return Complete;

case QgsExpression::boNotILike:
result = QString( "NOT lower(%1) LIKE lower(%2)" ).arg( op1, op2 );
return Complete;

case QgsExpression::boMod :
result = QString( "MOD(%1,%2)" ).arg( op1, op2 );
return Complete;

default:
break;
}
Expand All @@ -70,5 +89,14 @@ QString QgsOracleExpressionCompiler::quotedIdentifier( const QString& identifier
QString QgsOracleExpressionCompiler::quotedValue( const QVariant& value, bool& ok )
{
ok = true;
return QgsOracleConn::quotedValue( value );

switch ( value.type() )
{
case QVariant::Bool:
//no boolean literal support in Oracle, so fake it
return value.toBool() ? "(1=1)" : "(1=0)";

default:
return QgsOracleConn::quotedValue( value );
}
}
1 change: 1 addition & 0 deletions tests/src/python/providertestbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def testGetFeaturesFidTests(self):

def testGetFeaturesFidsTests(self):
fids = [f.id() for f in self.provider.getFeatures()]
self.assertEqual(len(fids), 5)

request = QgsFeatureRequest().setFilterFids([fids[0], fids[2]])
result = set([f.id() for f in self.provider.getFeatures(request)])
Expand Down

0 comments on commit 64bfbaa

Please sign in to comment.