34 "=",
"<>",
"<=",
">=",
"<",
">",
"LIKE",
"NOT LIKE",
"ILIKE",
"NOT ILIKE",
"IS",
"IS NOT",
35 "+",
"-",
"*",
"/",
"//",
"%",
"^",
48 "",
"LEFT",
"LEFT OUTER",
"RIGHT",
"RIGHT OUTER",
"CROSS",
"INNER",
"FULL" 64 return tr(
"(no root)" );
77 static const char*
const reservedKeyWords[] =
79 "AND",
"OR",
"NOT",
"LIKE",
"IN",
"IS",
"BETWEEN",
"NULL",
"SELECT",
"ALL",
"DISTINCT",
"CAST",
"AS",
80 "FROM",
"JOIN",
"ON",
"USING",
"WHERE",
"ORDER",
"BY",
"ASC",
"DESC",
81 "LEFT",
"RIGHT",
"INNER",
"OUTER",
"CROSS",
"FULL",
"NATURAL",
"UNION",
82 "OFFSET",
"LIMIT",
"GROUP",
"HAVING" 85 for (
size_t i = 0; i <
sizeof( reservedKeyWords ) /
sizeof( reservedKeyWords[0] ); ++i )
87 if ( name.
compare(
QString( reservedKeyWords[i] ), Qt::CaseInsensitive ) == 0 )
97 if ( text.
length() >= 2 && text[0] ==
'"' && text[text.
length()-1] ==
'"' )
131 if ( &other !=
this )
228 errorMsgOut = tr(
"No root node" );
240 errorMsgOut +=
QString( tr(
"Table %1 is referenced by column %2, but not selected in FROM / JOIN." ) ).
arg( pair.first ).
arg( pair.second );
253 Q_FOREACH (
Node* node, mList )
265 Q_FOREACH (
Node* n, mList )
267 if ( !first ) msg +=
", ";
330 Q_ASSERT( 0 &&
"unexpected binary operator" );
365 Q_ASSERT( 0 &&
"unexpected binary operator" );
375 QString rdump( mOpRight->dump() );
384 if ( leftAssociative() )
386 fmt += lOp && ( lOp->
precedence() < precedence() ) ?
"(%1)" :
"%1";
388 fmt += rOp && ( rOp->
precedence() <= precedence() ) ?
"(%3)" :
"%3";
392 fmt += lOp && ( lOp->
precedence() <= precedence() ) ?
"(%1)" :
"%1";
394 fmt += rOp && ( rOp->
precedence() < precedence() ) ?
"(%3)" :
"%3";
409 return QString(
"%1 %2IN (%3)" ).
arg( mNode->dump(), mNotIn ?
"NOT " :
"", mList->dump() );
414 return new NodeInOperator( mNode->clone(), mList->clone(), mNotIn );
421 return QString(
"%1 %2BETWEEN %3 AND %4" ).
arg( mNode->dump(), mNotBetween ?
"NOT " :
"", mMinVal->dump(), mMaxVal->dump() );
426 return new NodeBetweenOperator( mNode->clone(), mMinVal->clone(), mMaxVal->clone(), mNotBetween );
438 return new NodeFunction( mName, mArgs ? mArgs->clone() : nullptr );
445 if ( mValue.isNull() )
448 switch ( mValue.type() )
452 case QVariant::LongLong:
454 case QVariant::Double:
456 case QVariant::String:
459 return mValue.toBool() ?
"TRUE" :
"FALSE";
461 return tr(
"[unsupported type;%1; value:%2]" ).
arg( mValue.typeName(), mValue.toString() );
477 if ( !mTableName.isEmpty() )
503 ret += mColumnNode->dump();
504 if ( !mAlias.isEmpty() )
529 if ( !mAlias.isEmpty() )
554 bool bFirstColumn =
true;
559 bFirstColumn =
false;
560 ret += column->
dump();
563 bool bFirstTable =
true;
569 ret += table->
dump();
576 if ( mWhere !=
nullptr )
579 ret += mWhere->dump();
581 if ( !mOrderBy.isEmpty() )
590 ret += orderBy->
dump();
613 if ( mWhere !=
nullptr )
615 newSelect->
setWhere( mWhere->clone() );
637 ret += mTableDef->dump();
638 if ( mOnExpr !=
nullptr )
641 ret += mOnExpr->dump();
647 Q_FOREACH (
QString column, mUsingColumns )
666 if ( mOnExpr !=
nullptr )
667 return new NodeJoin( mTableDef->cloneThis(), mOnExpr->clone(), mType );
669 return new NodeJoin( mTableDef->cloneThis(), mUsingColumns, mType );
677 ret = mColumn->dump();
698 ret += mNode->dump();
707 return new NodeCast( mNode->clone(), mType );
virtual Node * clone() const override
Generate a clone of this node.
NodeTableDef * cloneThis() const
Clone with same type return.
QString & append(QChar ch)
bool leftAssociative() const
Is left associative ?
Function with a name and arguments node.
void push_back(const T &value)
Node * onExpr() const
On expression.
static const char * BinaryOperatorText[]
virtual Node * clone() const override
Generate a clone of this node.
NodeList * clone() const
Creates a deep copy of this list.
QString & prepend(QChar ch)
virtual QString dump() const override
Abstract virtual dump method.
NodeSelectedColumn * cloneThis() const
Clone with same type return.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
void visit(const QgsSQLStatement::NodeColumnRef &n) override
Visit NodeColumnRef.
void appendJoin(NodeJoin *join)
Append a join.
virtual QString dump() const override
Abstract virtual dump method.
NodeTableDef * tableDef() const
Table definition.
QString statement() const
Return the original, unmodified statement string.
Binary logical/arithmetical operator (AND, OR, =, +, ...)
static QString quotedString(QString text)
Returns a quoted version of a string (in single quotes)
virtual QString dump() const override
Abstract virtual dump method.
bool hasParserError() const
Returns true if an error occurred when parsing the input statement.
QgsSQLStatement::Node * mRootNode
virtual Node * clone() const override
Generate a clone of this node.
virtual Node * clone() const override
Generate a clone of this node.
A visitor that recursively explores all children.
virtual Node * clone() const override
Generate a clone of this node.
static const char * UnaryOperatorText[]
QgsSQLStatementCollectTableNames()
Class for parsing SQL statements.
QString number(int n, int base)
virtual QString dump() const override
Abstract virtual dump method.
virtual QString dump() const
Dump list.
QPair< QString, QString > TableColumnPair
QString name() const
Table name.
void acceptVisitor(Visitor &v) const
Entry function for the visitor pattern.
QString alias() const
Table alias.
virtual QString dump() const =0
Abstract virtual dump method.
virtual QString dump() const override
Abstract virtual dump method.
virtual Node * clone() const override
Generate a clone of this node.
Literal value (integer, integer64, double, string)
Node * where() const
Return the where clause.
QString name() const
The name of the column.
virtual QString dump() const override
Abstract virtual dump method.
virtual Node * clone() const override
Generate a clone of this node.
void setAlias(const QString &alias)
Set alias name.
Unary logicial/arithmetical operator ( NOT, - )
const Node * rootNode() const
Returns root node of the statement. Root node is null is parsing has failed.
virtual Node * clone() const =0
Generate a clone of this node.
virtual void accept(Visitor &v) const =0
Support the visitor pattern.
NodeJoin * cloneThis() const
Clone with same type return.
virtual QString dump() const override
Abstract virtual dump method.
virtual QString dump() const override
Abstract virtual dump method.
virtual Node * clone() const override
Generate a clone of this node.
QSet< TableColumnPair > tableNamesReferenced
QString parserErrorString() const
Returns parser error.
'X BETWEEN y and z' operator
virtual void accept(Visitor &v) const override
Support the visitor pattern.
NodeColumnRef * cloneThis() const
Clone with same type return.
virtual Node * clone() const override
Generate a clone of this node.
virtual Node * clone() const override
Generate a clone of this node.
void setOrderBy(QList< NodeColumnSorted *> orderBy)
Set order by columns.
bool contains(const T &value) const
QList< NodeColumnSorted * > orderBy() const
Return the list of order by columns.
static const char * JoinTypeText[]
QString & replace(int position, int n, QChar after)
static QString quotedIdentifierIfNeeded(QString name)
Returns a quoted column reference (in double quotes) if needed, or otherwise the original string...
QString dump() const
Return statement string, constructed from the internal abstract syntax tree.
QString mid(int position, int n) const
bool doBasicValidationChecks(QString &errorMsgOut) const
Performs basic validity checks.
QgsSQLStatement & operator=(const QgsSQLStatement &other)
Create a copy of this statement.
static QString stripQuotedIdentifier(QString text)
Remove double quotes from an identifier.
int precedence() const
Precedence.
NodeColumnSorted * cloneThis() const
Clone with same type return.
QList< NodeTableDef * > tables() const
Return the list of tables.
virtual QString dump() const override
Abstract virtual dump method.
void setDistinct(bool distinct=true)
Set whether this is prefixed by DISTINCT.
virtual QString dump() const override
Abstract virtual dump method.
virtual Node * clone() const override
Generate a clone of this node.
static const QRegExp identifierRE("^[A-Za-z_\0-\f][A-Za-z0-9_\0-\f]*$")
virtual Node * clone() const override
Generate a clone of this node.
void visit(const QgsSQLStatement::NodeUnaryOperator &n) override
Visit NodeUnaryOperator.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
void setWhere(Node *where)
Set where clause.
Support for visitor pattern - algorithms dealing with the statement may be implemented without modify...
QSet< QString > tableNamesDeclared
QString tableName() const
The name of the table.
virtual QString dump() const override
Abstract virtual dump method.
virtual void accept(Visitor &v) const override
Support the visitor pattern.
virtual Node * clone() const override
Generate a clone of this node.
UnaryOperator op() const
Operator.
virtual QString dump() const override
Abstract virtual dump method.
virtual QString dump() const override
Abstract virtual dump method.
static QString quotedIdentifier(QString name)
Returns a quoted column reference (in double quotes)
QgsSQLStatement::Node * parse(const QString &str, QString &parserErrorMsg)
'x IN (y, z)' operator
int compare(const QString &other) const
bool exactMatch(const QString &str) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QList< NodeSelectedColumn * > columns() const
Return the list of columns.
QgsSQLStatement(const QString &statement)
Creates a new statement based on the provided string.
QString mParserErrorString
QList< NodeJoin * > joins() const
Return the list of joins.