28using namespace Qt::StringLiterals;
30QgsSQLiteExpressionCompiler::QgsSQLiteExpressionCompiler(
const QgsFields &fields,
bool ignoreStaticNodes )
37 if ( staticRes != Fail )
56 if ( compileNode( op->
opLeft(), opL ) != Complete || compileNode( op->
opRight(), opR ) != Complete )
75 if ( fd->
name() ==
"make_datetime"_L1 || fd->
name() ==
"make_date"_L1 || fd->
name() ==
"make_time"_L1 )
77 const auto constList = n->
args()->
list();
95QString QgsSQLiteExpressionCompiler::quotedIdentifier(
const QString &identifier )
100QString QgsSQLiteExpressionCompiler::quotedValue(
const QVariant &value,
bool &ok )
106QString QgsSQLiteExpressionCompiler::sqlFunctionFromFunctionName(
const QString &fnName )
const
108 static const QMap<QString, QString> FN_NAMES {
111 {
"coalesce",
"coalesce" },
112 {
"lower",
"lower" },
113 {
"round",
"round" },
115 {
"upper",
"upper" },
116 {
"make_datetime",
"" },
121 return FN_NAMES.value( fnName, QString() );
124QStringList QgsSQLiteExpressionCompiler::sqlArgumentsFromFunctionName(
const QString &fnName,
const QStringList &fnArgs )
const
126 QStringList args( fnArgs );
127 if ( fnName ==
"make_datetime"_L1 )
129 args = QStringList( u
"'%1-%2-%3T%4:%5:%6Z'"_s.arg( args[0].rightJustified( 4,
'0' ) )
130 .arg( args[1].rightJustified( 2,
'0' ) )
131 .arg( args[2].rightJustified( 2,
'0' ) )
132 .arg( args[3].rightJustified( 2,
'0' ) )
133 .arg( args[4].rightJustified( 2,
'0' ) )
134 .arg( args[5].rightJustified( 2,
'0' ) ) );
136 else if ( fnName ==
"make_date"_L1 )
138 args = QStringList( u
"'%1-%2-%3'"_s.arg( args[0].rightJustified( 4,
'0' ) ).arg( args[1].rightJustified( 2,
'0' ) ).arg( args[2].rightJustified( 2,
'0' ) ) );
140 else if ( fnName ==
"make_time"_L1 )
142 args = QStringList( u
"'%1:%2:%3'"_s.arg( args[0].rightJustified( 2,
'0' ) ).arg( args[1].rightJustified( 2,
'0' ) ).arg( args[2].rightJustified( 2,
'0' ) ) );
147QString QgsSQLiteExpressionCompiler::castToReal(
const QString &value )
const
149 return u
"CAST((%1) AS REAL)"_s.arg( value );
152QString QgsSQLiteExpressionCompiler::castToInt(
const QString &value )
const
154 return u
"CAST((%1) AS INTEGER)"_s.arg( value );
157QString QgsSQLiteExpressionCompiler::castToText(
const QString &value )
const
159 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.