26QgsSQLiteExpressionCompiler::QgsSQLiteExpressionCompiler(
const QgsFields &fields,
bool ignoreStaticNodes )
34 if ( staticRes != Fail )
53 if ( compileNode( op->
opLeft(), opL ) != Complete ||
54 compileNode( op->
opRight(), opR ) != Complete )
57 result = QStringLiteral(
"lower(%1) %2 lower(%3) ESCAPE '\\'" )
76 if ( fd->
name() == QLatin1String(
"make_datetime" ) || fd->
name() == QLatin1String(
"make_date" ) || fd->
name() == QLatin1String(
"make_time" ) )
78 const auto constList = n->
args()->
list();
96QString QgsSQLiteExpressionCompiler::quotedIdentifier(
const QString &identifier )
101QString QgsSQLiteExpressionCompiler::quotedValue(
const QVariant &value,
bool &ok )
107QString QgsSQLiteExpressionCompiler::sqlFunctionFromFunctionName(
const QString &fnName )
const
109 static const QMap<QString, QString> FN_NAMES
113 {
"coalesce",
"coalesce" },
114 {
"lower",
"lower" },
115 {
"round",
"round" },
117 {
"upper",
"upper" },
118 {
"make_datetime",
"" },
123 return FN_NAMES.value( fnName, QString() );
126QStringList QgsSQLiteExpressionCompiler::sqlArgumentsFromFunctionName(
const QString &fnName,
const QStringList &fnArgs )
const
128 QStringList args( fnArgs );
129 if ( fnName == QLatin1String(
"make_datetime" ) )
131 args = QStringList( QStringLiteral(
"'%1-%2-%3T%4:%5:%6Z'" ).arg( args[0].rightJustified( 4,
'0' ) )
132 .arg( args[1].rightJustified( 2,
'0' ) )
133 .arg( args[2].rightJustified( 2,
'0' ) )
134 .arg( args[3].rightJustified( 2,
'0' ) )
135 .arg( args[4].rightJustified( 2,
'0' ) )
136 .arg( args[5].rightJustified( 2,
'0' ) ) );
138 else if ( fnName == QLatin1String(
"make_date" ) )
140 args = QStringList( QStringLiteral(
"'%1-%2-%3'" ).arg( args[0].rightJustified( 4,
'0' ) )
141 .arg( args[1].rightJustified( 2,
'0' ) )
142 .arg( args[2].rightJustified( 2,
'0' ) ) );
144 else if ( fnName == QLatin1String(
"make_time" ) )
146 args = QStringList( QStringLiteral(
"'%1:%2:%3'" ).arg( args[0].rightJustified( 2,
'0' ) )
147 .arg( args[1].rightJustified( 2,
'0' ) )
148 .arg( args[2].rightJustified( 2,
'0' ) ) );
153QString QgsSQLiteExpressionCompiler::castToReal(
const QString &value )
const
155 return QStringLiteral(
"CAST((%1) AS REAL)" ).arg( value );
158QString QgsSQLiteExpressionCompiler::castToInt(
const QString &value )
const
160 return QStringLiteral(
"CAST((%1) AS INTEGER)" ).arg( value );
163QString QgsSQLiteExpressionCompiler::castToText(
const QString &value )
const
165 return QStringLiteral(
"CAST((%1) AS TEXT)" ).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.