@@ -73,6 +73,24 @@ QgsSqlExpressionCompiler::Result QgsOgrExpressionCompiler::compileNode( const Qg
73
73
}
74
74
75
75
case QgsExpressionNode::ntFunction:
76
+ {
77
+ const QgsExpressionNodeFunction *n = static_cast <const QgsExpressionNodeFunction *>( node );
78
+ QgsExpressionFunction *fd = QgsExpression::Functions ()[n->fnIndex ()];
79
+
80
+ if ( fd->name () == QLatin1String ( " make_datetime" ) || fd->name () == QLatin1String ( " make_date" ) || fd->name () == QLatin1String ( " make_time" ) )
81
+ {
82
+ const auto constList = n->args ()->list ();
83
+ for ( const QgsExpressionNode *ln : constList )
84
+ {
85
+ if ( ln->nodeType () != QgsExpressionNode::ntLiteral )
86
+ return Fail;
87
+ }
88
+ return QgsSqlExpressionCompiler::compileNode ( node, result );
89
+ }
90
+ // generally not support by OGR
91
+ return Fail;
92
+ }
93
+
76
94
case QgsExpressionNode::ntCondition:
77
95
// not support by OGR
78
96
return Fail;
@@ -88,6 +106,45 @@ QgsSqlExpressionCompiler::Result QgsOgrExpressionCompiler::compileNode( const Qg
88
106
return QgsSqlExpressionCompiler::compileNode ( node, result );
89
107
}
90
108
109
+ QString QgsOgrExpressionCompiler::sqlFunctionFromFunctionName ( const QString &fnName ) const
110
+ {
111
+ static const QMap<QString, QString> FN_NAMES
112
+ {
113
+ { " make_datetime" , " " },
114
+ { " make_date" , " " },
115
+ { " make_time" , " " },
116
+ };
117
+
118
+ return FN_NAMES.value ( fnName, QString () );
119
+ }
120
+
121
+ QStringList QgsOgrExpressionCompiler::sqlArgumentsFromFunctionName ( const QString &fnName, const QStringList &fnArgs ) const
122
+ {
123
+ QStringList args ( fnArgs );
124
+ if ( fnName == QLatin1String ( " make_datetime" ) )
125
+ {
126
+ args = QStringList ( QStringLiteral ( " '%1-%2-%3T%4:%5:%6Z'" ).arg ( args[0 ].rightJustified ( 4 , ' 0' ) )
127
+ .arg ( args[1 ].rightJustified ( 2 , ' 0' ) )
128
+ .arg ( args[2 ].rightJustified ( 2 , ' 0' ) )
129
+ .arg ( args[3 ].rightJustified ( 2 , ' 0' ) )
130
+ .arg ( args[4 ].rightJustified ( 2 , ' 0' ) )
131
+ .arg ( args[5 ].rightJustified ( 2 , ' 0' ) ) );
132
+ }
133
+ else if ( fnName == QLatin1String ( " make_date" ) )
134
+ {
135
+ args = QStringList ( QStringLiteral ( " '%1-%2-%3'" ).arg ( args[0 ].rightJustified ( 4 , ' 0' ) )
136
+ .arg ( args[1 ].rightJustified ( 2 , ' 0' ) )
137
+ .arg ( args[2 ].rightJustified ( 2 , ' 0' ) ) );
138
+ }
139
+ else if ( fnName == QLatin1String ( " make_time" ) )
140
+ {
141
+ args = QStringList ( QStringLiteral ( " '%1:%2:%3'" ).arg ( args[0 ].rightJustified ( 2 , ' 0' ) )
142
+ .arg ( args[1 ].rightJustified ( 2 , ' 0' ) )
143
+ .arg ( args[2 ].rightJustified ( 2 , ' 0' ) ) );
144
+ }
145
+ return args;
146
+ }
147
+
91
148
QString QgsOgrExpressionCompiler::quotedIdentifier ( const QString &identifier )
92
149
{
93
150
return QgsOgrProviderUtils::quotedIdentifier ( identifier.toUtf8 (), mSource ->mDriverName );
0 commit comments