QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgssqlstatement.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssqlstatement.cpp
3  -------------------
4  begin : April 2016
5  copyright : (C) 2011 by Martin Dobias
6  copyright : (C) 2016 by Even Rouault
7  email : even.rouault at spatialys.com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgssqlstatement.h"
18 #include "qgis.h"
19 
20 #include <QRegularExpression>
21 
22 #include <cmath>
23 #include <limits>
24 
25 
26 // from parser
27 extern QgsSQLStatement::Node *parse( const QString &str, QString &parserErrorMsg, bool allowFragments );
28 
30 // operators
31 
33 {
34  // this must correspond (number and order of element) to the declaration of the enum BinaryOperator
35  "OR", "AND",
36  "=", "<>", "<=", ">=", "<", ">", "LIKE", "NOT LIKE", "ILIKE", "NOT ILIKE", "IS", "IS NOT",
37  "+", "-", "*", "/", "//", "%", "^",
38  "||"
39 };
40 
42 {
43  // this must correspond (number and order of element) to the declaration of the enum UnaryOperator
44  "NOT", "-"
45 };
46 
47 const char *QgsSQLStatement::JOIN_TYPE_TEXT[] =
48 {
49  // this must correspond (number and order of element) to the declaration of the enum JoinType
50  "", "LEFT", "LEFT OUTER", "RIGHT", "RIGHT OUTER", "CROSS", "INNER", "FULL"
51 };
52 
54 
56 {
57  if ( !mStatement.isNull() )
58  return mStatement;
59  else
60  return dump();
61 }
62 
63 QString QgsSQLStatement::dump() const
64 {
65  if ( !mRootNode )
66  return tr( "(no root)" );
67 
68  return mRootNode->dump();
69 }
70 
71 QString QgsSQLStatement::quotedIdentifier( QString name )
72 {
73  return QStringLiteral( "\"%1\"" ).arg( name.replace( '\"', QLatin1String( "\"\"" ) ) );
74 }
75 
76 QString QgsSQLStatement::quotedIdentifierIfNeeded( const QString &name )
77 {
78  // This might not be complete, but it must be at least what we recognize
79  static const char *const RESERVED_KEYWORDS[] =
80  {
81  "AND", "OR", "NOT", "LIKE", "IN", "IS", "BETWEEN", "NULL", "SELECT", "ALL", "DISTINCT", "CAST", "AS",
82  "FROM", "JOIN", "ON", "USING", "WHERE", "ORDER", "BY", "ASC", "DESC",
83  "LEFT", "RIGHT", "INNER", "OUTER", "CROSS", "FULL", "NATURAL", "UNION",
84  "OFFSET", "LIMIT", "GROUP", "HAVING"
85  };
86 
87  for ( size_t i = 0; i < sizeof( RESERVED_KEYWORDS ) / sizeof( RESERVED_KEYWORDS[0] ); ++i )
88  {
89  if ( name.compare( QString( RESERVED_KEYWORDS[i] ), Qt::CaseInsensitive ) == 0 )
90  {
91  return quotedIdentifier( name );
92  }
93  }
94  const thread_local QRegularExpression IDENTIFIER_RE( "^[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*$" );
95  return IDENTIFIER_RE.match( name ).hasMatch() ? name : quotedIdentifier( name );
96 }
97 
99 {
100  if ( text.length() >= 2 && text[0] == '"' && text[text.length() - 1] == '"' )
101  {
102  // strip double quotes on start,end
103  text = text.mid( 1, text.length() - 2 );
104 
105  // make single "double quotes" from double "double quotes"
106  text.replace( QLatin1String( "\"\"" ), QLatin1String( "\"" ) );
107  }
108  return text;
109 }
110 
112 {
113  if ( text.length() >= 2 && text[0] == '[' && text[text.length() - 1] == ']' )
114  {
115  // strip square brackets on start,end
116  text = text.mid( 1, text.length() - 2 );
117  }
118  return text;
119 }
120 
121 QString QgsSQLStatement::quotedString( QString text )
122 {
123  text.replace( '\'', QLatin1String( "''" ) );
124  text.replace( '\\', QLatin1String( "\\\\" ) );
125  text.replace( '\n', QLatin1String( "\\n" ) );
126  text.replace( '\t', QLatin1String( "\\t" ) );
127  return QStringLiteral( "'%1'" ).arg( text );
128 }
129 
130 QgsSQLStatement::QgsSQLStatement( const QString &expr )
131  : QgsSQLStatement( expr, false )
132 {
133 }
134 
135 QgsSQLStatement::QgsSQLStatement( const QString &expr, bool allowFragments )
136  : mAllowFragments( allowFragments )
137 {
139  mStatement = expr;
140 }
141 
143 {
145  mStatement = other.mStatement;
146 }
147 
149 {
150  if ( &other != this )
151  {
152  delete mRootNode;
153  mParserErrorString.clear();
155  mStatement = other.mStatement;
156  }
157  return *this;
158 }
159 
161 {
162  delete mRootNode;
163 }
164 
165 bool QgsSQLStatement::hasParserError() const { return !mParserErrorString.isNull() || ( !mRootNode && !mAllowFragments ); }
166 
168 
170 {
171  if ( mRootNode )
172  mRootNode->accept( v );
173 }
174 
176 {
177  return mRootNode;
178 }
179 
181 {
182  const auto constTables = n.tables();
183  for ( QgsSQLStatement::NodeTableDef *table : constTables )
184  {
185  table->accept( *this );
186  }
187  const auto constColumns = n.columns();
188  for ( QgsSQLStatement::NodeSelectedColumn *column : constColumns )
189  {
190  column->accept( *this );
191  }
192  const auto constJoins = n.joins();
193  for ( QgsSQLStatement::NodeJoin *join : constJoins )
194  {
195  join->accept( *this );
196  }
197  QgsSQLStatement::Node *where = n.where();
198  if ( where )
199  where->accept( *this );
200  const auto constOrderBy = n.orderBy();
201  for ( QgsSQLStatement::NodeColumnSorted *column : constOrderBy )
202  {
203  column->accept( *this );
204  }
205 }
206 
208 {
209  n.tableDef()->accept( *this );
210  QgsSQLStatement::Node *expr = n.onExpr();
211  if ( expr )
212  expr->accept( *this );
213 }
214 
221 {
222  public:
223  typedef QPair<QString, QString> TableColumnPair;
224 
229 
230  void visit( const QgsSQLStatement::NodeColumnRef &n ) override;
231  void visit( const QgsSQLStatement::NodeTableDef &n ) override;
232 
233  QSet<QString> tableNamesDeclared;
234  QSet<TableColumnPair> tableNamesReferenced;
235 };
236 
238 {
239  if ( !n.tableName().isEmpty() )
240  tableNamesReferenced.insert( TableColumnPair( n.tableName(), n.name() ) );
242 }
243 
245 {
246  tableNamesDeclared.insert( n.alias().isEmpty() ? ( n.schema().isEmpty() ? n.name() : n.schema() + '.' + n.name() ) : n.alias() );
248 }
249 
250 bool QgsSQLStatement::doBasicValidationChecks( QString &errorMsgOut ) const
251 {
252  errorMsgOut.clear();
253  if ( !mRootNode )
254  {
255  errorMsgOut = tr( "No root node" );
256  return false;
257  }
259  mRootNode->accept( v );
260 
261  for ( const QgsSQLStatementCollectTableNames::TableColumnPair &pair : std::as_const( v.tableNamesReferenced ) )
262  {
263  if ( !v.tableNamesDeclared.contains( pair.first ) )
264  {
265  if ( !errorMsgOut.isEmpty() )
266  errorMsgOut += QLatin1Char( ' ' );
267  errorMsgOut += tr( "Table %1 is referenced by column %2, but not selected in FROM / JOIN." ).arg( pair.first, pair.second );
268  }
269  }
270 
271  return errorMsgOut.isEmpty();
272 }
273 
275 // nodes
276 
278 {
279  for ( QgsSQLStatement::Node *node : mList )
280  {
281  node->accept( v );
282  }
283 }
284 
286 {
287  NodeList *nl = new NodeList;
288  const auto constMList = mList;
289  for ( Node *node : constMList )
290  {
291  nl->mList.append( node->clone() );
292  }
293 
294  return nl;
295 }
296 
298 {
299  QString msg;
300  bool first = true;
301  const auto constMList = mList;
302  for ( Node *n : constMList )
303  {
304  if ( !first ) msg += QLatin1String( ", " );
305  else first = false;
306  msg += n->dump();
307  }
308  return msg;
309 }
310 
311 
312 //
313 
315 {
316  return QStringLiteral( "%1 %2" ).arg( UNARY_OPERATOR_TEXT[mOp], mOperand->dump() );
317 }
318 
320 {
321  return new NodeUnaryOperator( mOp, mOperand->clone() );
322 }
323 
324 //
325 
327 {
328  // see left/right in qgsexpressionparser.yy
329  switch ( mOp )
330  {
331  case boOr:
332  return 1;
333 
334  case boAnd:
335  return 2;
336 
337  case boEQ:
338  case boNE:
339  case boLE:
340  case boGE:
341  case boLT:
342  case boGT:
343  case boLike:
344  case boILike:
345  case boNotLike:
346  case boNotILike:
347  case boIs:
348  case boIsNot:
349  return 3;
350 
351  case boPlus:
352  case boMinus:
353  return 4;
354 
355  case boMul:
356  case boDiv:
357  case boIntDiv:
358  case boMod:
359  return 5;
360 
361  case boPow:
362  return 6;
363 
364  case boConcat:
365  return 7;
366  }
367  Q_ASSERT( false && "unexpected binary operator" );
368  return -1;
369 }
370 
372 {
373  // see left/right in qgsexpressionparser.yy
374  switch ( mOp )
375  {
376  case boOr:
377  case boAnd:
378  case boEQ:
379  case boNE:
380  case boLE:
381  case boGE:
382  case boLT:
383  case boGT:
384  case boLike:
385  case boILike:
386  case boNotLike:
387  case boNotILike:
388  case boIs:
389  case boIsNot:
390  case boPlus:
391  case boMinus:
392  case boMul:
393  case boDiv:
394  case boIntDiv:
395  case boMod:
396  case boConcat:
397  return true;
398 
399  case boPow:
400  return false;
401  }
402  Q_ASSERT( false && "unexpected binary operator" );
403  return false;
404 }
405 
407 {
411 
412  QString rdump( mOpRight->dump() );
413 
414  // avoid dumping "IS (NOT ...)" as "IS NOT ..."
415  if ( mOp == boIs && ruOp && ruOp->op() == uoNot )
416  {
417  rdump.prepend( '(' ).append( ')' );
418  }
419 
420  QString fmt;
421  if ( leftAssociative() )
422  {
423  fmt += lOp && ( lOp->precedence() < precedence() ) ? "(%1)" : "%1";
424  fmt += QLatin1String( " %2 " );
425  fmt += rOp && ( rOp->precedence() <= precedence() ) ? "(%3)" : "%3";
426  }
427  else
428  {
429  fmt += lOp && ( lOp->precedence() <= precedence() ) ? "(%1)" : "%1";
430  fmt += QLatin1String( " %2 " );
431  fmt += rOp && ( rOp->precedence() < precedence() ) ? "(%3)" : "%3";
432  }
433 
434  return fmt.arg( mOpLeft->dump(), BINARY_OPERATOR_TEXT[mOp], rdump );
435 }
436 
438 {
439  return new NodeBinaryOperator( mOp, mOpLeft->clone(), mOpRight->clone() );
440 }
441 
442 //
443 
445 {
446  return QStringLiteral( "%1 %2IN (%3)" ).arg( mNode->dump(), mNotIn ? "NOT " : "", mList->dump() );
447 }
448 
450 {
451  return new NodeInOperator( mNode->clone(), mList->clone(), mNotIn );
452 }
453 
454 //
455 
457 {
458  return QStringLiteral( "%1 %2BETWEEN %3 AND %4" ).arg( mNode->dump(), mNotBetween ? "NOT " : "", mMinVal->dump(), mMaxVal->dump() );
459 }
460 
462 {
463  return new NodeBetweenOperator( mNode->clone(), mMinVal->clone(), mMaxVal->clone(), mNotBetween );
464 }
465 
466 //
467 
469 {
470  return QStringLiteral( "%1(%2)" ).arg( mName, mArgs ? mArgs->dump() : QString() ); // function
471 }
472 
474 {
475  return new NodeFunction( mName, mArgs ? mArgs->clone() : nullptr );
476 }
477 
478 //
479 
481 {
482  if ( mValue.isNull() )
483  return QStringLiteral( "NULL" );
484 
485  switch ( mValue.type() )
486  {
487  case QVariant::Int:
488  return QString::number( mValue.toInt() );
489  case QVariant::LongLong:
490  return QString::number( mValue.toLongLong() );
491  case QVariant::Double:
492  return QString::number( mValue.toDouble() );
493  case QVariant::String:
494  return quotedString( mValue.toString() );
495  case QVariant::Bool:
496  return mValue.toBool() ? "TRUE" : "FALSE";
497  default:
498  return tr( "[unsupported type: %1; value: %2]" ).arg( mValue.typeName(), mValue.toString() );
499  }
500 }
501 
503 {
504  return new NodeLiteral( mValue );
505 }
506 
507 //
508 
510 {
511  QString ret;
512  if ( mDistinct )
513  ret += QLatin1String( "DISTINCT " );
514  if ( !mTableName.isEmpty() )
515  {
516  ret += quotedIdentifierIfNeeded( mTableName );
517  ret += '.';
518  }
519  ret += ( mStar ) ? mName : quotedIdentifierIfNeeded( mName );
520  return ret;
521 }
522 
524 {
525  return cloneThis();
526 }
527 
529 {
530  NodeColumnRef *newColumnRef = new NodeColumnRef( mTableName, mName, mStar );
531  newColumnRef->setDistinct( mDistinct );
532  return newColumnRef;
533 }
534 
535 //
536 
538 {
539  QString ret;
540  ret += mColumnNode->dump();
541  if ( !mAlias.isEmpty() )
542  {
543  ret += QLatin1String( " AS " );
544  ret += quotedIdentifierIfNeeded( mAlias );
545  }
546  return ret;
547 }
548 
550 {
551  NodeSelectedColumn *newObj = new NodeSelectedColumn( mColumnNode->clone() );
552  newObj->setAlias( mAlias );
553  return newObj;
554 }
555 
557 {
558  return cloneThis();
559 }
560 //
561 
563 {
564  QString ret;
565  if ( !mSchema.isEmpty() )
566  ret += mSchema + '.';
567 
568  ret += quotedIdentifierIfNeeded( mName );
569  if ( !mAlias.isEmpty() )
570  {
571  ret += QLatin1String( " AS " );
572  ret += quotedIdentifierIfNeeded( mAlias );
573  }
574  return ret;
575 }
576 
578 {
579  return new NodeTableDef( mSchema, mName, mAlias );
580 }
581 
583 {
584  return cloneThis();
585 }
586 
587 //
588 
590 {
591  qDeleteAll( mTableList );
592  qDeleteAll( mColumns );
593  qDeleteAll( mJoins );
594  delete mWhere;
595  qDeleteAll( mOrderBy );
596 }
597 
599 {
600  QString ret = QStringLiteral( "SELECT " );
601  if ( mDistinct )
602  ret += QLatin1String( "DISTINCT " );
603  bool bFirstColumn = true;
604  const auto constMColumns = mColumns;
605  for ( QgsSQLStatement::NodeSelectedColumn *column : constMColumns )
606  {
607  if ( !bFirstColumn )
608  ret += QLatin1String( ", " );
609  bFirstColumn = false;
610  ret += column->dump();
611  }
612  ret += QLatin1String( " FROM " );
613  bool bFirstTable = true;
614  const auto constMTableList = mTableList;
615  for ( QgsSQLStatement::NodeTableDef *table : constMTableList )
616  {
617  if ( !bFirstTable )
618  ret += QLatin1String( ", " );
619  bFirstTable = false;
620  ret += table->dump();
621  }
622  const auto constMJoins = mJoins;
623  for ( QgsSQLStatement::NodeJoin *join : constMJoins )
624  {
625  ret += ' ';
626  ret += join->dump();
627  }
628  if ( mWhere )
629  {
630  ret += QLatin1String( " WHERE " );
631  ret += mWhere->dump();
632  }
633  if ( !mOrderBy.isEmpty() )
634  {
635  ret += QLatin1String( " ORDER BY " );
636  bool bFirst = true;
637  const auto constMOrderBy = mOrderBy;
638  for ( QgsSQLStatement::NodeColumnSorted *orderBy : constMOrderBy )
639  {
640  if ( !bFirst )
641  ret += QLatin1String( ", " );
642  bFirst = false;
643  ret += orderBy->dump();
644  }
645  }
646  return ret;
647 }
648 
650 {
651  QList<QgsSQLStatement::NodeSelectedColumn *> newColumnList;
652  const auto constMColumns = mColumns;
653  for ( QgsSQLStatement::NodeSelectedColumn *column : constMColumns )
654  {
655  newColumnList.push_back( column->cloneThis() );
656  }
657  QList<QgsSQLStatement::NodeTableDef *> newTableList;
658  const auto constMTableList = mTableList;
659  for ( QgsSQLStatement::NodeTableDef *table : constMTableList )
660  {
661  newTableList.push_back( table->cloneThis() );
662  }
663  QgsSQLStatement::NodeSelect *newSelect = new NodeSelect( newTableList, newColumnList, mDistinct );
664  const auto constMJoins = mJoins;
665  for ( QgsSQLStatement::NodeJoin *join : constMJoins )
666  {
667  newSelect->appendJoin( join->cloneThis() );
668  }
669  if ( mWhere )
670  {
671  newSelect->setWhere( mWhere->clone() );
672  }
673  QList<QgsSQLStatement::NodeColumnSorted *> newOrderByList;
674  const auto constMOrderBy = mOrderBy;
675  for ( QgsSQLStatement::NodeColumnSorted *columnSorted : constMOrderBy )
676  {
677  newOrderByList.push_back( columnSorted->cloneThis() );
678  }
679  newSelect->setOrderBy( newOrderByList );
680  return newSelect;
681 }
682 
683 //
684 
686 {
687  QString ret;
688  if ( mType != jtDefault )
689  {
690  ret += JOIN_TYPE_TEXT[mType];
691  ret += QLatin1Char( ' ' );
692  }
693  ret += QLatin1String( "JOIN " );
694  ret += mTableDef->dump();
695  if ( mOnExpr )
696  {
697  ret += QLatin1String( " ON " );
698  ret += mOnExpr->dump();
699  }
700  else
701  {
702  ret += QLatin1String( " USING (" );
703  bool first = true;
704  const auto constMUsingColumns = mUsingColumns;
705  for ( QString column : constMUsingColumns )
706  {
707  if ( !first )
708  ret += QLatin1String( ", " );
709  first = false;
710  ret += quotedIdentifierIfNeeded( column );
711  }
712  ret += QLatin1Char( ')' );
713  }
714  return ret;
715 }
716 
718 {
719  return cloneThis();
720 }
721 
723 {
724  if ( mOnExpr )
725  return new NodeJoin( mTableDef->cloneThis(), mOnExpr->clone(), mType );
726  else
727  return new NodeJoin( mTableDef->cloneThis(), mUsingColumns, mType );
728 }
729 
730 //
731 
733 {
734  QString ret;
735  ret = mColumn->dump();
736  if ( !mAsc )
737  ret += QLatin1String( " DESC" );
738  return ret;
739 }
740 
742 {
743  return cloneThis();
744 }
745 
747 {
748  return new NodeColumnSorted( mColumn->cloneThis(), mAsc );
749 }
750 
751 //
752 
754 {
755  QString ret( QStringLiteral( "CAST(" ) );
756  ret += mNode->dump();
757  ret += QLatin1String( " AS " );
758  ret += mType;
759  ret += ')';
760  return ret;
761 }
762 
764 {
765  return new NodeCast( mNode->clone(), mType );
766 }
767 
768 //
769 // QgsSQLStatementFragment
770 //
771 
773  : QgsSQLStatement( fragment, true )
774 {
775 
776 }
QgsSQLStatement::Node
Abstract node class.
Definition: qgssqlstatement.h:234
QgsSQLStatement::NodeColumnRef::tableName
QString tableName() const
The name of the table. May be empty.
Definition: qgssqlstatement.h:547
QgsSQLStatement::NodeJoin
Join definition.
Definition: qgssqlstatement.h:683
QgsSQLStatement::NodeTableDef::accept
void accept(QgsSQLStatement::Visitor &v) const override
Support the visitor pattern.
Definition: qgssqlstatement.h:668
QgsSQLStatement::mRootNode
QgsSQLStatement::Node * mRootNode
Definition: qgssqlstatement.h:865
QgsSQLStatement::stripQuotedIdentifier
static QString stripQuotedIdentifier(QString text)
Remove double quotes from an identifier.
Definition: qgssqlstatement.cpp:98
QgsSQLStatement::QgsSQLStatement
QgsSQLStatement(const QString &statement)
Creates a new statement based on the provided string.
Definition: qgssqlstatement.cpp:130
QgsSQLStatement::boPlus
@ boPlus
Definition: qgssqlstatement.h:171
QgsSQLStatement::NodeColumnSorted::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:732
QgsSQLStatementCollectTableNames::TableColumnPair
QPair< QString, QString > TableColumnPair
Definition: qgssqlstatement.cpp:223
QgsSQLStatement::NodeColumnSorted
Column in a ORDER BY.
Definition: qgssqlstatement.h:723
QgsSQLStatement::NodeTableDef::name
QString name() const
Table name.
Definition: qgssqlstatement.h:653
QgsSQLStatement::NodeBinaryOperator::leftAssociative
bool leftAssociative() const
Is left associative ?
Definition: qgssqlstatement.cpp:371
QgsSQLStatementCollectTableNames
Internal use.
Definition: qgssqlstatement.cpp:220
QgsSQLStatement::NodeLiteral::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:480
QgsSQLStatement::NodeInOperator::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:449
QgsSQLStatement::NodeSelect::~NodeSelect
~NodeSelect() override
Definition: qgssqlstatement.cpp:589
QgsSQLStatement::NodeSelect::setOrderBy
void setOrderBy(const QList< QgsSQLStatement::NodeColumnSorted * > &orderBy)
Sets order by columns.
Definition: qgssqlstatement.h:767
QgsSQLStatement::NodeSelect::setWhere
void setWhere(QgsSQLStatement::Node *where)
Sets where clause.
Definition: qgssqlstatement.h:765
QgsSQLStatement::NodeTableDef::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:582
QgsSQLStatement::NodeColumnRef::cloneThis
QgsSQLStatement::NodeColumnRef * cloneThis() const
Clone with same type return.
Definition: qgssqlstatement.cpp:528
QgsSQLStatement::boLE
@ boLE
Definition: qgssqlstatement.h:159
QgsSQLStatement::JOIN_TYPE_TEXT
static const char * JOIN_TYPE_TEXT[]
Definition: qgssqlstatement.h:206
QgsSQLStatement::NodeTableDef
Table definition.
Definition: qgssqlstatement.h:638
QgsSQLStatement::boLT
@ boLT
Definition: qgssqlstatement.h:161
QgsSQLStatement::NodeColumnRef::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:523
QgsSQLStatement::NodeFunction
Function with a name and arguments node.
Definition: qgssqlstatement.h:483
QgsSQLStatement::acceptVisitor
void acceptVisitor(QgsSQLStatement::Visitor &v) const
Entry function for the visitor pattern.
Definition: qgssqlstatement.cpp:169
qgis.h
QgsSQLStatement::dump
QString dump() const
Returns the statement string, constructed from the internal abstract syntax tree.
Definition: qgssqlstatement.cpp:63
QgsSQLStatement::NodeSelect::where
QgsSQLStatement::Node * where() const
Returns the where clause.
Definition: qgssqlstatement.h:778
QgsSQLStatement::NodeTableDef::cloneThis
QgsSQLStatement::NodeTableDef * cloneThis() const
Clone with same type return.
Definition: qgssqlstatement.cpp:577
QgsSQLStatement::boGE
@ boGE
Definition: qgssqlstatement.h:160
QgsSQLStatement::NodeColumnRef::setDistinct
void setDistinct(bool distinct=true)
Sets whether this is prefixed by DISTINCT.
Definition: qgssqlstatement.h:544
QgsSQLStatement::NodeSelect
SELECT node.
Definition: qgssqlstatement.h:753
QgsSQLStatementCollectTableNames::visit
void visit(const QgsSQLStatement::NodeColumnRef &n) override
Visit NodeColumnRef.
Definition: qgssqlstatement.cpp:237
QgsSQLStatement::NodeSelect::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:598
QgsSQLStatement::NodeCast
CAST operator.
Definition: qgssqlstatement.h:610
QgsSQLStatement::NodeUnaryOperator
Unary logicial/arithmetical operator ( NOT, - )
Definition: qgssqlstatement.h:343
QgsSQLStatement::NodeSelect::appendJoin
void appendJoin(QgsSQLStatement::NodeJoin *join)
Append a join.
Definition: qgssqlstatement.h:763
QgsSQLStatement::NodeList::clone
QgsSQLStatement::NodeList * clone() const
Creates a deep copy of this list. Ownership is transferred to the caller.
Definition: qgssqlstatement.cpp:285
QgsSQLStatement::mAllowFragments
bool mAllowFragments
Definition: qgssqlstatement.h:866
QgsSQLStatement::NodeUnaryOperator::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:314
QgsSQLStatement::boMul
@ boMul
Definition: qgssqlstatement.h:173
QgsSQLStatement::NodeJoin::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:717
QgsSQLStatement::boPow
@ boPow
Definition: qgssqlstatement.h:177
QgsSQLStatementFragment::QgsSQLStatementFragment
QgsSQLStatementFragment(const QString &fragment)
Constructor for QgsSQLStatementFragment of the specified fragment.
Definition: qgssqlstatement.cpp:772
QgsSQLStatement::NodeSelect::columns
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
Definition: qgssqlstatement.h:772
QgsSQLStatement::NodeTableDef::schema
QString schema() const
Returns the schema name.
Definition: qgssqlstatement.h:660
QgsSQLStatement::NodeJoin::tableDef
QgsSQLStatement::NodeTableDef * tableDef() const
Table definition.
Definition: qgssqlstatement.h:693
QgsSQLStatement::boOr
@ boOr
Definition: qgssqlstatement.h:153
QgsSQLStatement::Visitor
Support for visitor pattern - algorithms dealing with the statement may be implemented without modify...
Definition: qgssqlstatement.h:804
QgsSQLStatement::NodeSelectedColumn::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:537
QgsSQLStatement::stripMsQuotedIdentifier
static QString stripMsQuotedIdentifier(QString text)
Remove double quotes from an Microsoft style identifier.
Definition: qgssqlstatement.cpp:111
QgsSQLStatement::statement
QString statement() const
Returns the original, unmodified statement string.
Definition: qgssqlstatement.cpp:55
QgsSQLStatement::quotedString
static QString quotedString(QString text)
Returns a quoted version of a string (in single quotes)
Definition: qgssqlstatement.cpp:121
QgsSQLStatement::rootNode
const QgsSQLStatement::Node * rootNode() const
Returns the root node of the statement.
Definition: qgssqlstatement.cpp:175
QgsSQLStatement::NodeJoin::cloneThis
QgsSQLStatement::NodeJoin * cloneThis() const
Clone with same type return.
Definition: qgssqlstatement.cpp:722
QgsSQLStatement::boIsNot
@ boIsNot
Definition: qgssqlstatement.h:168
QgsSQLStatement::uoNot
@ uoNot
Definition: qgssqlstatement.h:142
QgsSQLStatement::hasParserError
bool hasParserError() const
Returns true if an error occurred when parsing the input statement.
Definition: qgssqlstatement.cpp:165
QgsSQLStatement::boNE
@ boNE
Definition: qgssqlstatement.h:158
QgsSQLStatement::boLike
@ boLike
Definition: qgssqlstatement.h:163
QgsSQLStatement::NodeSelect::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:649
QgsSQLStatement::boConcat
@ boConcat
Definition: qgssqlstatement.h:180
QgsSQLStatement::NodeUnaryOperator::op
QgsSQLStatement::UnaryOperator op() const
Operator.
Definition: qgssqlstatement.h:351
QgsSQLStatement::NodeTableDef::alias
QString alias() const
Table alias.
Definition: qgssqlstatement.h:663
QgsSQLStatement::boNotILike
@ boNotILike
Definition: qgssqlstatement.h:166
QgsSQLStatementCollectTableNames::tableNamesReferenced
QSet< TableColumnPair > tableNamesReferenced
Definition: qgssqlstatement.cpp:234
QgsSQLStatement::NodeColumnSorted::cloneThis
QgsSQLStatement::NodeColumnSorted * cloneThis() const
Clone with same type return.
Definition: qgssqlstatement.cpp:746
QgsSQLStatement::mParserErrorString
QString mParserErrorString
Definition: qgssqlstatement.h:868
QgsSQLStatement::BINARY_OPERATOR_TEXT
static const char * BINARY_OPERATOR_TEXT[]
Definition: qgssqlstatement.h:200
QgsSQLStatement
Class for parsing SQL statements.
Definition: qgssqlstatement.h:35
QgsSQLStatement::NodeBinaryOperator::precedence
int precedence() const
Precedence.
Definition: qgssqlstatement.cpp:326
QgsSQLStatement::NodeSelect::tables
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
Definition: qgssqlstatement.h:770
QgsSQLStatement::boMinus
@ boMinus
Definition: qgssqlstatement.h:172
QgsSQLStatement::NodeSelectedColumn::setAlias
void setAlias(const QString &alias)
Sets alias name.
Definition: qgssqlstatement.h:585
QgsSQLStatement::Node::dump
virtual QString dump() const =0
Abstract virtual dump method.
QgsSQLStatement::operator=
QgsSQLStatement & operator=(const QgsSQLStatement &other)
Create a copy of this statement.
Definition: qgssqlstatement.cpp:148
QgsSQLStatement::boIntDiv
@ boIntDiv
Definition: qgssqlstatement.h:175
QgsSQLStatement::NodeCast::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:753
QgsSQLStatement::boIs
@ boIs
Definition: qgssqlstatement.h:167
QgsSQLStatement::boILike
@ boILike
Definition: qgssqlstatement.h:165
QgsSQLStatement::NodeJoin::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:685
QgsSQLStatement::NodeInOperator
'x IN (y, z)' operator
Definition: qgssqlstatement.h:414
QgsSQLStatement::NodeColumnRef::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:509
QgsSQLStatement::doBasicValidationChecks
bool doBasicValidationChecks(QString &errorMsgOut) const
Performs basic validity checks.
Definition: qgssqlstatement.cpp:250
QgsSQLStatement::NodeBinaryOperator
Binary logical/arithmetical operator (AND, OR, =, +, ...)
Definition: qgssqlstatement.h:371
QgsSQLStatement::boGT
@ boGT
Definition: qgssqlstatement.h:162
QgsSQLStatement::NodeSelect::orderBy
QList< QgsSQLStatement::NodeColumnSorted * > orderBy() const
Returns the list of order by columns.
Definition: qgssqlstatement.h:780
QgsSQLStatement::boMod
@ boMod
Definition: qgssqlstatement.h:176
QgsSQLStatement::NodeColumnRef
Reference to a column.
Definition: qgssqlstatement.h:535
QgsSQLStatement::UNARY_OPERATOR_TEXT
static const char * UNARY_OPERATOR_TEXT[]
Definition: qgssqlstatement.h:203
QgsSQLStatement::NodeList
A list of nodes.
Definition: qgssqlstatement.h:308
QgsSQLStatement::boDiv
@ boDiv
Definition: qgssqlstatement.h:174
QgsSQLStatement::Node::accept
virtual void accept(QgsSQLStatement::Visitor &v) const =0
Support the visitor pattern.
QgsSQLStatement::NodeSelect::joins
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
Definition: qgssqlstatement.h:776
QgsSQLStatement::NodeBinaryOperator::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:406
str
#define str(x)
Definition: qgis.cpp:37
QgsSQLStatement::RecursiveVisitor::visit
void visit(const QgsSQLStatement::NodeUnaryOperator &n) override
Visit NodeUnaryOperator.
Definition: qgssqlstatement.h:846
QgsSQLStatement::NodeList::dump
virtual QString dump() const
Dump list.
Definition: qgssqlstatement.cpp:297
QgsSQLStatement::mStatement
QString mStatement
Definition: qgssqlstatement.h:867
QgsSQLStatement::NodeSelectedColumn::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:556
QgsSQLStatement::boAnd
@ boAnd
Definition: qgssqlstatement.h:154
QgsSQLStatement::NodeBinaryOperator::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:437
QgsSQLStatement::NodeSelectedColumn::cloneThis
QgsSQLStatement::NodeSelectedColumn * cloneThis() const
Clone with same type return.
Definition: qgssqlstatement.cpp:549
QgsSQLStatement::NodeCast::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:763
QgsSQLStatement::NodeTableDef::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:562
QgsSQLStatement::NodeUnaryOperator::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:319
QgsSQLStatement::quotedIdentifier
static QString quotedIdentifier(QString name)
Returns a quoted column reference (in double quotes)
Definition: qgssqlstatement.cpp:71
QgsSQLStatement::NodeFunction::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:468
QgsSQLStatement::boEQ
@ boEQ
Definition: qgssqlstatement.h:157
QgsSQLStatement::NodeLiteral::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:502
QgsSQLStatementCollectTableNames::tableNamesDeclared
QSet< QString > tableNamesDeclared
Definition: qgssqlstatement.cpp:233
QgsSQLStatement::NodeFunction::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:473
QgsSQLStatement::jtDefault
@ jtDefault
Definition: qgssqlstatement.h:189
QgsSQLStatement::RecursiveVisitor
A visitor that recursively explores all children.
Definition: qgssqlstatement.h:840
QgsSQLStatement::NodeList::accept
void accept(QgsSQLStatement::Visitor &v) const
Accept visitor.
Definition: qgssqlstatement.cpp:277
QgsSQLStatement::NodeBetweenOperator::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:461
QgsSQLStatement::boNotLike
@ boNotLike
Definition: qgssqlstatement.h:164
QgsSQLStatement::NodeList::mList
QList< Node * > mList
Definition: qgssqlstatement.h:336
QgsSQLStatement::NodeColumnRef::name
QString name() const
The name of the column.
Definition: qgssqlstatement.h:550
QgsSQLStatement::NodeSelectedColumn
Selected column.
Definition: qgssqlstatement.h:577
QgsSQLStatement::NodeBetweenOperator::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:456
QgsSQLStatement::NodeBetweenOperator
'X BETWEEN y and z' operator
Definition: qgssqlstatement.h:446
qgssqlstatement.h
QgsSQLStatement::quotedIdentifierIfNeeded
static QString quotedIdentifierIfNeeded(const QString &name)
Returns a quoted column reference (in double quotes) if needed, or otherwise the original string.
Definition: qgssqlstatement.cpp:76
QgsSQLStatement::NodeJoin::onExpr
QgsSQLStatement::Node * onExpr() const
On expression. Will be nullptr if usingColumns() is not empty.
Definition: qgssqlstatement.h:696
QgsSQLStatement::~QgsSQLStatement
virtual ~QgsSQLStatement()
Definition: qgssqlstatement.cpp:160
QgsSQLStatement::NodeInOperator::dump
QString dump() const override
Abstract virtual dump method.
Definition: qgssqlstatement.cpp:444
QgsSQLStatement::parserErrorString
QString parserErrorString() const
Returns parser error.
Definition: qgssqlstatement.cpp:167
parse
QgsSQLStatement::Node * parse(const QString &str, QString &parserErrorMsg, bool allowFragments)
QgsSQLStatement::NodeColumnSorted::clone
QgsSQLStatement::Node * clone() const override
Generate a clone of this node.
Definition: qgssqlstatement.cpp:741
QgsSQLStatement::NodeLiteral
Literal value (integer, integer64, double, string)
Definition: qgssqlstatement.h:512