KDb

KDbExpressionData.h
1 /* This file is part of the KDE project
2  Copyright (C) 2003-2015 JarosÅ‚aw Staniek <[email protected]>
3 
4  Based on nexp.cpp : Parser module of Python-like language
5  (C) 2001 JarosÅ‚aw Staniek, MIMUW (www.mimuw.edu.pl)
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef KDB_EXPRESSION_P_H
24 #define KDB_EXPRESSION_P_H
25 
26 #include "config-kdb.h"
27 #include "KDbToken.h"
28 #include "KDbField.h"
29 
31 class KDbEscapedString;
32 class KDbExpressionData;
33 class KDbParseInfo;
38 
39 namespace KDb
40 {
42 
43 //! Classes of expressions
45  UnknownExpression,
46  UnaryExpression,
47  ArithmeticExpression,
48  LogicalExpression,
49  RelationalExpression,
50  SpecialBinaryExpression,
51  ConstExpression,
52  VariableExpression,
53  FunctionExpression,
54  AggregationExpression,
55  FieldListExpression,
56  TableListExpression,
57  ArgumentListExpression,
58  QueryParameterExpression,
59  LastExpressionClass = QueryParameterExpression //!< This line should be at the end of the list
60 };
61 }
62 
64 
65 //! Internal data class used to implement implicitly shared class KDbExpression.
66 //! Provides thread-safe reference counting.
67 class KDB_TESTING_EXPORT KDbExpressionData : public QSharedData
68 {
69 public:
71 
72  /*Data(const Data& other)
73  : QSharedData(other)
74  , token(other.token)
75  , expressionClass(other.expressionClass)
76  , parent(other.parent)
77  , children(other.children)
78  {
79  kdbDebug() << "KDbExpressionData" << ref;
80  }*/
81 
82  virtual ~KDbExpressionData();
83 
84  //! @see KDbExpression::token()
86  //! @see KDbExpression::expressionClass()
90  KDbField::Type type() const; //!< @return type of this expression;
91  bool isValid() const;
92  bool isTextType() const;
93  bool isIntegerType() const;
94  bool isNumericType() const;
95  bool isFPNumericType() const;
96  bool isDateTimeType() const;
97  KDbEscapedString toString(const KDbDriver *driver,
99  KDb::ExpressionCallStack *callStack = nullptr) const;
100  virtual void getQueryParameters(QList<KDbQuerySchemaParameter> *params);
101  bool validate(KDbParseInfo *parseInfo);
102  virtual KDbExpressionData* clone();
103 
104  template <typename T>
105  const T* convertConst() const { return dynamic_cast<const T*>(this); }
106 
107  template <typename T>
108  T* convert() { return dynamic_cast<T*>(this); }
109 
110  //! Sends information about this expression to debug output @a dbg.
111  QDebug debug(QDebug dbg, KDb::ExpressionCallStack *callStack) const;
112 
113  KDbField::Type type(KDb::ExpressionCallStack *callStack) const;
114 
115  bool validate(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack);
116 
117 protected:
118  //! Sends information about this expression to debug output @a dbg (internal).
119  virtual void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const;
120 
121  virtual KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const;
122 
123  virtual KDbEscapedString toStringInternal(const KDbDriver *driver,
125  KDb::ExpressionCallStack *callStack) const;
126 
127  virtual bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack);
128 
129  bool addToCallStack(QDebug *dbg, KDb::ExpressionCallStack *callStack) const;
130 };
131 
132 //! Internal data class used to implement implicitly shared class KDbNArgExpression.
133 //! Provides thread-safe reference counting.
135 {
136  Q_DECLARE_TR_FUNCTIONS(KDbNArgExpressionData)
137 public:
139  ~KDbNArgExpressionData() override;
140 
141  void getQueryParameters(QList<KDbQuerySchemaParameter> *params) override;
142  KDbNArgExpressionData* clone() override;
143  bool containsInvalidArgument() const;
144  bool containsNullArgument() const;
145 
146 protected:
147  //! Sends information about this expression to debug output @a dbg (internal).
148  void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override;
149 
150  KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override;
151 
152  KDbEscapedString toStringInternal(const KDbDriver *driver,
154  KDb::ExpressionCallStack *callStack) const override;
155 
156  bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override;
157 };
158 
159 //! Internal data class used to implement implicitly shared class KDbUnaryExpression.
160 //! Provides thread-safe reference counting.
162 {
163 public:
165  ~KDbUnaryExpressionData() override;
166 
167  void getQueryParameters(QList<KDbQuerySchemaParameter> *params) override;
168  KDbUnaryExpressionData* clone() override;
169  inline ExplicitlySharedExpressionDataPointer arg() const {
170  return children.isEmpty() ? ExplicitlySharedExpressionDataPointer() : children.first();
171  }
172 
173 protected:
174  //! Sends information about this expression to debug output @a dbg (internal).
175  void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override;
176 
177  KDbEscapedString toStringInternal(const KDbDriver *driver,
179  KDb::ExpressionCallStack *callStack) const override;
180 
181  KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override;
182 
183  bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override;
184 };
185 
186 //! Internal data class used to implement implicitly shared class KDbBinaryExpression.
187 //! Provides thread-safe reference counting.
189 {
190  Q_DECLARE_TR_FUNCTIONS(KDbBinaryExpressionData)
191 public:
193  ~KDbBinaryExpressionData() override;
194 
195  void getQueryParameters(QList<KDbQuerySchemaParameter> *params) override;
196  KDbBinaryExpressionData *clone() override;
199 
200 protected:
201  void setLeft(const KDbExpressionData& left);
202 
203  //! Sends information about this expression to debug output @a dbg (internal).
204  void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override;
205 
206  KDbEscapedString toStringInternal(const KDbDriver *driver,
208  KDb::ExpressionCallStack *callStack) const override;
209 
210  KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override;
211 
212  bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override;
213 };
214 
215 //! Internal data class used to implement implicitly shared class KDbConstExpression.
216 //! Provides thread-safe reference counting.
218 {
219 public:
220  explicit KDbConstExpressionData(const QVariant& aValue = QVariant());
221  ~KDbConstExpressionData() override;
222 
223  QVariant value;
224  void getQueryParameters(QList<KDbQuerySchemaParameter> *params) override;
225  KDbConstExpressionData *clone() override;
226 
227 protected:
228  //! Sends information about this expression to debug output @a dbg (internal).
229  void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override;
230 
233  KDb::ExpressionCallStack *callStack) const override;
234 
235  KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override;
236 
237  bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override;
238 };
239 
240 //! Internal data class used to implement implicitly shared class KDbQueryParameterExpression.
241 //! Provides thread-safe reference counting.
243 {
244 public:
248 
249  KDbField::Type m_type;
250  void getQueryParameters(QList<KDbQuerySchemaParameter> *params) override;
251  KDbQueryParameterExpressionData* clone() override;
252 
253 protected:
254  //! Sends information about this expression to debug output @a dbg (internal).
255  void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override;
256 
257  KDbEscapedString toStringInternal(const KDbDriver *driver,
259  KDb::ExpressionCallStack *callStack) const override;
260 
261  KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override;
262 
263  bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override;
264 };
265 
266 //! Internal data class used to implement implicitly shared class KDbVariableExpression.
267 //! Provides thread-safe reference counting.
269 {
270  Q_DECLARE_TR_FUNCTIONS(KDbVariableExpressionData)
271 public:
273  explicit KDbVariableExpressionData(const QString& aName);
274  ~KDbVariableExpressionData() override;
275 
276  /*! Verbatim name as returned by scanner. */
278 
279  /*! 0 by default. After successful validate() it will point to a field,
280  if the variable is of a form "tablename.fieldname" or "fieldname",
281  otherwise (eg. for asterisks) still 0.
282  Only meaningful for column expressions within a query. */
284 
285  /*! -1 by default. After successful validate() it will contain a position of a table
286  within query that needs to be bound to the field.
287  This value can be either be -1 if no binding is needed.
288  This value is used in the Parser to call
289  KDbQuerySchema::addField(KDbField* field, int bindToTable);
290  Only meaningful for column expressions within a query. */
292 
293  /*! 0 by default. After successful validate() it will point to a table
294  that is referenced by asterisk, i.e. "*.tablename".
295  This is set to @c nullptr if this variable is not an asterisk of that form. */
297 
298  void getQueryParameters(QList<KDbQuerySchemaParameter> *params) override;
299  KDbVariableExpressionData* clone() override;
300 
301 protected:
302  //! Sends information about this expression to debug output @a dbg (internal).
303  void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override;
304 
305  KDbEscapedString toStringInternal(const KDbDriver *driver,
307  KDb::ExpressionCallStack *callStack) const override;
308 
309  KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override;
310 
311  /*! Validation. Sets field, tablePositionForField
312  and tableForQueryAsterisk members.
313  See addColumn() in parse.y to see how it's used on column adding. */
314  bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override;
315 };
316 
317 //! Internal data class used to implement implicitly shared class KDbFunctionExpression.
318 //! Provides thread-safe reference counting.
320 {
321  Q_DECLARE_TR_FUNCTIONS(KDbFunctionExpressionData)
322 public:
324  explicit KDbFunctionExpressionData(const QString &aName,
327  ~KDbFunctionExpressionData() override;
328 
329  QString name;
331 
332  void getQueryParameters(QList<KDbQuerySchemaParameter> *params) override;
333  KDbFunctionExpressionData* clone() override;
334 
335  void setArguments(ExplicitlySharedExpressionDataPointer arguments);
336 
337  static KDbEscapedString toString(const QString &name,
338  const KDbDriver *driver,
339  const KDbNArgExpressionData *args,
341  KDb::ExpressionCallStack *callStack);
342 
343 protected:
344  //! Sends information about this expression to debug output @a dbg (internal).
345  void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override;
346 
347  KDbEscapedString toStringInternal(const KDbDriver *driver,
349  KDb::ExpressionCallStack *callStack) const override;
350 
351  KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override;
352 
353  /*! Validation. Sets field, tablePositionForField
354  and tableForQueryAsterisk members.
355  See addColumn() in parse.y to see how it's used on column adding. */
356  bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override;
357 };
358 
359 QDebug operator<<(QDebug dbg, const KDbExpressionData& expr);
360 
361 #endif
KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override
Internal data class used to implement implicitly shared class KDbExpression.
@ LastExpressionClass
This line should be at the end of the list.
void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override
Sends information about this expression to debug output dbg (internal).
KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override
An iterator for a list of values of query schema parameters Allows to iterate over parameters and ret...
A type-safe KDbSQL token It can be used in KDb expressions.
Definition: KDbToken.h:36
void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override
Sends information about this expression to debug output dbg (internal).
Type type(const QSqlDatabase &db)
Internal data class used to implement implicitly shared class KDbBinaryExpression.
A database connectivity and creation framework.
KDbField::Type type() const
Specialized string for escaping.
void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override
Sends information about this expression to debug output dbg (internal).
A single parameter of a query schema.
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
Database driver's abstraction.
Definition: KDbDriver.h:49
Internal data class used to implement implicitly shared class KDbQueryParameterExpression.
bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override
Internal data class used to implement implicitly shared class KDbUnaryExpression.
KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override
We're assuming it's called after VariableExpr::validate()
Internal data class used to implement implicitly shared class KDbConstExpression.
Internal data class used to implement implicitly shared class KDbVariableExpression.
void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override
Sends information about this expression to debug output dbg (internal).
void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override
Sends information about this expression to debug output dbg (internal).
bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override
ExpressionClass
Classes of expressions.
Internal data class used to implement implicitly shared class KDbNArgExpression.
bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override
void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override
Sends information about this expression to debug output dbg (internal).
KDbTableSchema * tableForQueryAsterisk
KDbEscapedString toStringInternal(const KDbDriver *driver, KDbQuerySchemaParameterValueListIterator *params, KDb::ExpressionCallStack *callStack) const override
Meta-data for a field.
Definition: KDbField.h:71
Internal data class used to implement implicitly shared class KDbFunctionExpression.
KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override
bool validateInternal(KDbParseInfo *parseInfo, KDb::ExpressionCallStack *callStack) override
KDb::ExpressionClass expressionClass
void debugInternal(QDebug dbg, KDb::ExpressionCallStack *callStack) const override
Sends information about this expression to debug output dbg (internal).
KDbField::Type typeInternal(KDb::ExpressionCallStack *callStack) const override
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 04:06:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.