Skip to content
Permalink
Browse files

[oracle] Fixes for oracle expression compilation

On behalf of Faunalia, sponsored by ENEL

(cherry-picked from 64bfbaa)
  • Loading branch information
nyalldawson committed Jul 6, 2016
1 parent 0307495 commit 3c6c32d5cdcfcc1ffc97228b37556f1a69cb55c4
Showing with 30 additions and 1 deletion.
  1. +29 −1 src/providers/oracle/qgsoracleexpressioncompiler.cpp
  2. +1 −0 tests/src/python/providertestbase.py
@@ -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;

@@ -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;
}
@@ -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 );
}
}
@@ -339,6 +339,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)])

0 comments on commit 3c6c32d

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