28using namespace Qt::StringLiterals;
30QgsSQLiteExpressionCompiler::QgsSQLiteExpressionCompiler(
const QgsFields &fields,
bool ignoreStaticNodes )
38 if ( staticRes != Fail )
57 if ( compileNode( op->
opLeft(), opL ) != Complete ||
58 compileNode( op->
opRight(), opR ) != Complete )
61 result = u
"lower(%1) %2 lower(%3) ESCAPE '\\'"_s
80 if ( fd->
name() ==
"make_datetime"_L1 || fd->
name() ==
"make_date"_L1 || fd->
name() ==
"make_time"_L1 )
82 const auto constList = n->
args()->
list();
100QString QgsSQLiteExpressionCompiler::quotedIdentifier(
const QString &identifier )
105QString QgsSQLiteExpressionCompiler::quotedValue(
const QVariant &value,
bool &ok )
111QString QgsSQLiteExpressionCompiler::sqlFunctionFromFunctionName(
const QString &fnName )
const
113 static const QMap<QString, QString> FN_NAMES
117 {
"coalesce",
"coalesce" },
118 {
"lower",
"lower" },
119 {
"round",
"round" },
121 {
"upper",
"upper" },
122 {
"make_datetime",
"" },
127 return FN_NAMES.value( fnName, QString() );
130QStringList QgsSQLiteExpressionCompiler::sqlArgumentsFromFunctionName(
const QString &fnName,
const QStringList &fnArgs )
const
132 QStringList args( fnArgs );
133 if ( fnName ==
"make_datetime"_L1 )
135 args = QStringList( u
"'%1-%2-%3T%4:%5:%6Z'"_s.arg( args[0].rightJustified( 4,
'0' ) )
136 .arg( args[1].rightJustified( 2,
'0' ) )
137 .arg( args[2].rightJustified( 2,
'0' ) )
138 .arg( args[3].rightJustified( 2,
'0' ) )
139 .arg( args[4].rightJustified( 2,
'0' ) )
140 .arg( args[5].rightJustified( 2,
'0' ) ) );
142 else if ( fnName ==
"make_date"_L1 )
144 args = QStringList( u
"'%1-%2-%3'"_s.arg( args[0].rightJustified( 4,
'0' ) )
145 .arg( args[1].rightJustified( 2,
'0' ) )
146 .arg( args[2].rightJustified( 2,
'0' ) ) );
148 else if ( fnName ==
"make_time"_L1 )
150 args = QStringList( u
"'%1:%2:%3'"_s.arg( args[0].rightJustified( 2,
'0' ) )
151 .arg( args[1].rightJustified( 2,
'0' ) )
152 .arg( args[2].rightJustified( 2,
'0' ) ) );
157QString QgsSQLiteExpressionCompiler::castToReal(
const QString &value )
const
159 return u
"CAST((%1) AS REAL)"_s.arg( value );
162QString QgsSQLiteExpressionCompiler::castToInt(
const QString &value )
const
164 return u
"CAST((%1) AS INTEGER)"_s.arg( value );
167QString QgsSQLiteExpressionCompiler::castToText(
const QString &value )
const
169 return u
"CAST((%1) AS TEXT)"_s.arg( value );
An abstract base class for defining QgsExpression functions.
QString name() const
The name of the function.
A binary expression operator, which operates on two values.
QgsExpressionNode * opLeft() const
Returns the node to the left of the operator.
QgsExpressionNode * opRight() const
Returns the node to the right of the operator.
QgsExpressionNodeBinaryOperator::BinaryOperator op() const
Returns the binary operator.
An expression node for expression functions.
int fnIndex() const
Returns the index of the node's function.
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
QList< QgsExpressionNode * > list()
Gets a list of all the nodes.
Abstract base class for all nodes that can appear in an expression.
virtual QgsExpressionNode::NodeType nodeType() const =0
Gets the type of this node.
static const QList< QgsExpressionFunction * > & Functions()
Container of fields for a vector layer.
Generic expression compiler for translation to provider specific SQL WHERE clauses.
virtual Result compileNode(const QgsExpressionNode *node, QString &str)
Compiles an expression node and returns the result of the compilation.
Result
Possible results from expression compilation.
static QString quotedIdentifier(const QString &identifier)
Returns a properly quoted version of identifier.
static QString quotedValue(const QVariant &value)
Returns a properly quoted and escaped version of value for use in SQL strings.