KDb

KDbQueryAsterisk.h
1 /* This file is part of the KDE project
2  Copyright (C) 2003-2017 JarosÅ‚aw Staniek <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KDB_QUERYASTERISK_H
21 #define KDB_QUERYASTERISK_H
22 
23 #include "KDbField.h"
24 
25 class KDbQuerySchema;
26 
27 //! @short KDbQueryAsterisk class encapsulates information about single asterisk in query definition
28 /*! There are two types of query asterisks:
29 
30  1. "Single-table" asterisk, that references all fields of given table used
31  in the query.
32  Example SQL statement:
33  @code
34  SELECT staff.*, cars.model from staff, cars WHERE staff.car = cars.number;
35  @endcode
36  The "staff.*" element is our "single-table" asterisk;
37  this tells us that we want to get all fields of table "staff".
38 
39  2. "All-tables" asterisk, that references all fields of all tables used in the query.
40  Example SQL statement:
41  @code
42  SELECT * from staff, cars WHERE staff.car = cars.number;
43  @endcode
44  The "*" is our "all-tables" asterisk;
45  this tells us that we want to get all fields of all used tables (here: "staff" and "cars").
46 
47  There can be many asterisks of 1st type defined for given single query.
48  There can be one asterisk of 2nd type defined for given single query.
49 */
50 class KDB_EXPORT KDbQueryAsterisk : public KDbField
51 {
52 public:
53  /*! Constructs an "all-tables" query asterisk definition object ("*" in SQL notation).
54 
55  KDbQueryAsterisk objects are owned by KDbQuerySchema object
56  (not by KDbTableSchema object like for ordinary KDbField objects)
57  for that the KDbQueryAsterisk object was added (using KDbQuerySchema::addField()). */
58  explicit KDbQueryAsterisk(KDbQuerySchema *query);
59 
60  /*! Constructs a "single-table" query asterisk definition object ("T.*" in SQL notation).
61  @a table schema is the single table for the asterisk.
62 
63  KDbQueryAsterisk objects are owned by KDbQuerySchema object
64  (not by KDbTableSchema object like for ordinary KDbField objects)
65  for that the KDbQueryAsterisk object was added (using KDbQuerySchema::addField()). */
66  KDbQueryAsterisk(KDbQuerySchema *query, const KDbTableSchema &table);
67 
68  /*! Constructs a deep copy of query asterisk definition object @a asterisk. */
69  KDbQueryAsterisk(const KDbQueryAsterisk &asterisk);
70 
71  ~KDbQueryAsterisk() override;
72 
73  /**
74  * @brief Returns @c true if this query asterisk is equal to @a other
75  *
76  * @return @c false if the objects are not equal.
77  * Two asterisks are equal if they return the same table() and query().
78  * This also means that both return the same value for isSingleTableAsterisk() and
79  * isAllTableAsterisk().
80  *
81  * @since 3.1
82  */
83  bool operator==(const KDbQueryAsterisk& other) const;
84 
85  /**
86  * @brief Returns @c true if this query asterisk is not equal to @a other
87  *
88  * @return @c false if objects are equal.
89  *
90  * @see operator==(const KDbQueryAsterisk&)
91  * @since 3.1
92  */
93  inline bool operator!=(const KDbQueryAsterisk &other) const { return !operator==(other); }
94 
95  /*! @return Query object for that this asterisk object is defined */
97 
98  /*! @overload KDbQuerySchema *query() */
99  const KDbQuerySchema *query() const;
100 
101  /*! @return table schema object for that this asterisk object is defined.
102  If this is a "all-tables" asterisk, @c nullptr is returned. */
103  const KDbTableSchema* table() const;
104 
105  /*! Sets table schema for this asterisk.
106  If table is supplied, the asterisk become a "single-table" asterisk.
107  If @a table is @c nullptr the asterisk becames "all-tables" asterisk. */
108  void setTable(const KDbTableSchema *table);
109 
110  /*! This is convenience method that returns @c true
111  if the asterisk has "all-tables" type (2nd type).*/
112  bool isSingleTableAsterisk() const;
113 
114  /*! This is convenience method that returns @c true
115  if the asterisk has "single-table" type (2nd type).*/
116  bool isAllTableAsterisk() const;
117 
118 protected:
119  //! @return a deep copy of this object. Used in KDbFieldList(const KDbFieldList& fl).
120  KDbField* copy() override;
121 
122  KDbQueryAsterisk(KDbQuerySchema *query, const KDbTableSchema *table);
123 
124 private:
125  class Private;
126  Private * const d;
127  KDbQueryAsterisk& operator=(const KDbQueryAsterisk &) = delete;
128  void setTable(KDbTableSchema *table); // protect
129 };
130 
131 //! Sends query asterisk information @a asterisk to debug output @a dbg.
132 KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbQueryAsterisk& asterisk);
133 
134 #endif
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
KDbQuerySchema * query()
Definition: KDbField.cpp:600
KDbTableSchema * table()
Definition: KDbField.cpp:585
virtual KDbField * copy()
Definition: KDbField.cpp:374
void setTable(KDbTableSchema *table)
Definition: KDbField.cpp:595
bool operator!=(const KDbQueryAsterisk &other) const
Returns true if this query asterisk is not equal to other.
KDbQuerySchema provides information about database query.
Meta-data for a field.
Definition: KDbField.h:71
KDbQueryAsterisk class encapsulates information about single asterisk in query definition.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Dec 11 2023 04:08:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.