Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] oracle provider: initial expression compiler support
- Loading branch information
Showing
7 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*************************************************************************** | ||
qgsoracleexpressioncompiler.cpp | ||
---------------------------------------------------- | ||
date : December 2015 | ||
copyright : (C) 2015 by Juergen E. Fischer | ||
email : jef at norbit dot de | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsoracleexpressioncompiler.h" | ||
#include "qgssqlexpressioncompiler.h" | ||
|
||
QgsOracleExpressionCompiler::QgsOracleExpressionCompiler( QgsOracleFeatureSource* source ) | ||
: QgsSqlExpressionCompiler( source->mFields ) | ||
{ | ||
} | ||
|
||
QgsSqlExpressionCompiler::Result QgsOracleExpressionCompiler::compileNode( const QgsExpression::Node* node, QString& result ) | ||
{ | ||
if ( node->nodeType() == QgsExpression::ntBinaryOperator ) | ||
{ | ||
const QgsExpression::NodeBinaryOperator *bin( static_cast<const QgsExpression::NodeBinaryOperator*>( node ) ); | ||
|
||
switch ( bin->op() ) | ||
{ | ||
case QgsExpression::boPow: | ||
case QgsExpression::boRegexp: | ||
{ | ||
QString op1, op2; | ||
|
||
if ( compileNode( bin->opLeft(), op1 ) != Complete || | ||
compileNode( bin->opRight(), op2 ) != Complete ) | ||
return Fail; | ||
|
||
switch ( bin->op() ) | ||
{ | ||
case QgsExpression::boPow: | ||
result = QString( "power(%1,%2)" ).arg( op1, op2 ); | ||
return Complete; | ||
|
||
case QgsExpression::boRegexp: | ||
result = QString( "regexp_like(%1,%2)" ).arg( op1, op2 ); | ||
return Complete; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
//fallback to default handling | ||
return QgsSqlExpressionCompiler::compileNode( node, result ); | ||
} | ||
|
||
QString QgsOracleExpressionCompiler::quotedIdentifier( const QString& identifier ) | ||
{ | ||
return QgsOracleConn::quotedIdentifier( identifier ); | ||
} | ||
|
||
QString QgsOracleExpressionCompiler::quotedValue( const QVariant& value ) | ||
{ | ||
return QgsOracleConn::quotedValue( value ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*************************************************************************** | ||
qgsoracleexpressioncompiler.h | ||
---------------------------------------------------- | ||
date : December 2015 | ||
copyright : (C) 2015 by Jürgen E. Fischer | ||
email : jef at norbit dot de | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSORACLEEXPRESSIONCOMPILER_H | ||
#define QGSORACLEEXPRESSIONCOMPILER_H | ||
|
||
#include "qgssqlexpressioncompiler.h" | ||
#include "qgsexpression.h" | ||
#include "qgsoraclefeatureiterator.h" | ||
|
||
class QgsOracleExpressionCompiler : public QgsSqlExpressionCompiler | ||
{ | ||
public: | ||
|
||
explicit QgsOracleExpressionCompiler( QgsOracleFeatureSource* source ); | ||
|
||
protected: | ||
virtual Result compileNode( const QgsExpression::Node* node, QString& result ) override; | ||
virtual QString quotedIdentifier( const QString& identifier ) override; | ||
virtual QString quotedValue( const QVariant& value ) override; | ||
}; | ||
|
||
#endif // QGSORACLEEXPRESSIONCOMPILER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65ee183
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jef-n great to see this! Can i suggest you also implement the provider test for Oracle, as it was designed to accompany expression compilation and identify if any special handling needs to be done wrt case sensitivity/etc.
It's really simple, see: https://github.com/qgis/QGIS/blob/master/tests/testdata/provider/testdata.sql
and https://github.com/qgis/QGIS/blob/master/tests/src/python/test_provider_postgres.py up to line 56