@@ -24,65 +24,90 @@ QgsOracleExpressionCompiler::QgsOracleExpressionCompiler( QgsOracleFeatureSource
24
24
25
25
QgsSqlExpressionCompiler::Result QgsOracleExpressionCompiler::compileNode ( const QgsExpressionNode *node, QString &result )
26
26
{
27
- if ( node->nodeType () == QgsExpressionNode::ntBinaryOperator )
27
+ switch ( node->nodeType () )
28
28
{
29
- const QgsExpressionNodeBinaryOperator *bin ( static_cast <const QgsExpressionNodeBinaryOperator *>( node ) );
30
-
31
- switch ( bin->op () )
29
+ case QgsExpressionNode::ntBinaryOperator:
32
30
{
33
- case QgsExpressionNodeBinaryOperator::boConcat:
34
- // oracle's handling of || WRT null is not standards compliant
35
- return Fail;
36
-
37
- case QgsExpressionNodeBinaryOperator::boPow:
38
- case QgsExpressionNodeBinaryOperator::boRegexp:
39
- case QgsExpressionNodeBinaryOperator::boILike:
40
- case QgsExpressionNodeBinaryOperator::boNotILike:
41
- case QgsExpressionNodeBinaryOperator::boMod:
42
- case QgsExpressionNodeBinaryOperator::boIntDiv:
43
- {
44
- QString op1, op2;
31
+ const QgsExpressionNodeBinaryOperator *bin ( static_cast <const QgsExpressionNodeBinaryOperator *>( node ) );
45
32
46
- if ( compileNode ( bin->opLeft (), op1 ) != Complete ||
47
- compileNode ( bin->opRight (), op2 ) != Complete )
33
+ switch ( bin->op () )
34
+ {
35
+ case QgsExpressionNodeBinaryOperator::boConcat:
36
+ // oracle's handling of || WRT null is not standards compliant
48
37
return Fail;
49
38
50
- switch ( bin->op () )
39
+ case QgsExpressionNodeBinaryOperator::boPow:
40
+ case QgsExpressionNodeBinaryOperator::boRegexp:
41
+ case QgsExpressionNodeBinaryOperator::boILike:
42
+ case QgsExpressionNodeBinaryOperator::boNotILike:
43
+ case QgsExpressionNodeBinaryOperator::boMod:
44
+ case QgsExpressionNodeBinaryOperator::boIntDiv:
51
45
{
52
- case QgsExpressionNodeBinaryOperator::boPow:
53
- result = QStringLiteral ( " power(%1,%2)" ).arg ( op1, op2 );
54
- return Complete;
46
+ QString op1, op2;
47
+
48
+ if ( compileNode ( bin->opLeft (), op1 ) != Complete ||
49
+ compileNode ( bin->opRight (), op2 ) != Complete )
50
+ return Fail;
51
+
52
+ switch ( bin->op () )
53
+ {
54
+ case QgsExpressionNodeBinaryOperator::boPow:
55
+ result = QStringLiteral ( " power(%1,%2)" ).arg ( op1, op2 );
56
+ return Complete;
55
57
56
- case QgsExpressionNodeBinaryOperator::boRegexp:
57
- result = QStringLiteral ( " regexp_like(%1,%2)" ).arg ( op1, op2 );
58
- return Complete;
58
+ case QgsExpressionNodeBinaryOperator::boRegexp:
59
+ result = QStringLiteral ( " regexp_like(%1,%2)" ).arg ( op1, op2 );
60
+ return Complete;
59
61
60
- case QgsExpressionNodeBinaryOperator::boILike:
61
- result = QStringLiteral ( " lower(%1) LIKE lower(%2) ESCAPE '\\ '" ).arg ( op1, op2 );
62
- return Complete;
62
+ case QgsExpressionNodeBinaryOperator::boILike:
63
+ result = QStringLiteral ( " lower(%1) LIKE lower(%2) ESCAPE '\\ '" ).arg ( op1, op2 );
64
+ return Complete;
63
65
64
- case QgsExpressionNodeBinaryOperator::boNotILike:
65
- result = QStringLiteral ( " NOT lower(%1) LIKE lower(%2) ESCAPE '\\ '" ).arg ( op1, op2 );
66
- return Complete;
66
+ case QgsExpressionNodeBinaryOperator::boNotILike:
67
+ result = QStringLiteral ( " NOT lower(%1) LIKE lower(%2) ESCAPE '\\ '" ).arg ( op1, op2 );
68
+ return Complete;
67
69
68
- case QgsExpressionNodeBinaryOperator::boIntDiv:
69
- result = QStringLiteral ( " FLOOR(%1 / %2)" ).arg ( op1, op2 );
70
- return Complete;
70
+ case QgsExpressionNodeBinaryOperator::boIntDiv:
71
+ result = QStringLiteral ( " FLOOR(%1 / %2)" ).arg ( op1, op2 );
72
+ return Complete;
71
73
72
74
73
- case QgsExpressionNodeBinaryOperator::boMod :
74
- result = QStringLiteral ( " MOD(%1,%2)" ).arg ( op1, op2 );
75
- return Complete;
75
+ case QgsExpressionNodeBinaryOperator::boMod :
76
+ result = QStringLiteral ( " MOD(%1,%2)" ).arg ( op1, op2 );
77
+ return Complete;
76
78
77
- default :
78
- break ;
79
+ default :
80
+ break ;
81
+ }
82
+ break ; // no warnings
79
83
}
80
- break ; // no warnings
84
+
85
+ default :
86
+ break ;
81
87
}
88
+ break ;
89
+ }
82
90
83
- default :
84
- break ;
91
+ case QgsExpressionNode::ntFunction:
92
+ {
93
+ const QgsExpressionNodeFunction *n = static_cast <const QgsExpressionNodeFunction *>( node );
94
+ QgsExpressionFunction *fd = QgsExpression::Functions ()[n->fnIndex ()];
95
+
96
+ if ( fd->name () == QLatin1String ( " make_datetime" ) )
97
+ {
98
+ const auto constList = n->args ()->list ();
99
+ for ( const QgsExpressionNode *ln : constList )
100
+ {
101
+ if ( ln->nodeType () != QgsExpressionNode::ntLiteral )
102
+ return Fail;
103
+ }
104
+ }
105
+ return QgsSqlExpressionCompiler::compileNode ( node, result );
106
+ break ;
85
107
}
108
+
109
+ default :
110
+ break ;
86
111
}
87
112
88
113
// fallback to default handling
@@ -127,9 +152,25 @@ static const QMap<QString, QString> FUNCTION_NAMES_SQL_FUNCTIONS_MAP
127
152
{ " ceil" , " ceil" },
128
153
{ " lower" , " lower" },
129
154
{ " upper" , " upper" },
155
+ { " make_datetime" , " " },
130
156
};
131
157
132
158
QString QgsOracleExpressionCompiler::sqlFunctionFromFunctionName ( const QString &fnName ) const
133
159
{
134
160
return FUNCTION_NAMES_SQL_FUNCTIONS_MAP.value ( fnName, QString () );
135
161
}
162
+
163
+ QStringList QgsOracleExpressionCompiler::sqlArgumentsFromFunctionName ( const QString &fnName, const QStringList &fnArgs ) const
164
+ {
165
+ QStringList args ( fnArgs );
166
+ if ( fnName == QLatin1String ( " make_datetime" ) )
167
+ {
168
+ args = QStringList ( QStringLiteral ( " TIMESTAMP '%1-%2-%3 %4:%5:%6'" ).arg ( args[0 ].rightJustified ( 4 , ' 0' ) )
169
+ .arg ( args[1 ].rightJustified ( 2 , ' 0' ) )
170
+ .arg ( args[2 ].rightJustified ( 2 , ' 0' ) )
171
+ .arg ( args[3 ].rightJustified ( 2 , ' 0' ) )
172
+ .arg ( args[4 ].rightJustified ( 2 , ' 0' ) )
173
+ .arg ( args[5 ].rightJustified ( 2 , ' 0' ) ) );
174
+ }
175
+ return args;
176
+ }
0 commit comments