KDb

KDbQueryAsterisk.cpp
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 #include "KDbQueryAsterisk.h"
21 #include "KDbQuerySchema.h"
22 #include "KDbTableSchema.h"
23 
24 class KDbQueryAsterisk::Private
25 {
26 public:
27  Private(const KDbTableSchema *t) : table(t) {}
28 
29  /*! Table schema for this asterisk */
30  const KDbTableSchema* table;
31 };
32 
33 // ----
34 
36  : KDbQueryAsterisk(query, nullptr)
37 {
38 }
39 
41  : KDbQueryAsterisk(query, &table)
42 {
43 }
44 
46  : KDbField(query, -1)
47  , d(new Private(table))
48 {
50 }
51 
53  : KDbField(asterisk)
54  , d(new Private(asterisk.table()))
55 {
56 }
57 
58 KDbQueryAsterisk::~KDbQueryAsterisk()
59 {
60  delete d;
61 }
62 
64 {
65  return d->table == other.d->table && parent() == other.parent();
66 }
67 
69 {
70  return static_cast<KDbQuerySchema*>(parent());
71 }
72 
74 {
75  return static_cast<const KDbQuerySchema*>(parent());
76 }
77 
79 {
80  return d->table;
81 }
82 
84 {
85  return new KDbQueryAsterisk(*this);
86 }
87 
89 {
90  d->table = table;
91 }
92 
94 {
95  return d->table;
96 }
97 
99 {
100  return !d->table;
101 }
102 
103 QDebug operator<<(QDebug dbg, const KDbQueryAsterisk& asterisk)
104 {
105  if (asterisk.isAllTableAsterisk()) {
106  dbg.nospace() << "ALL-TABLES ASTERISK (*) ON TABLES(";
107  bool first = true;
108  foreach(KDbTableSchema *table, *asterisk.query()->tables()) {
109  if (first)
110  first = false;
111  else
112  dbg.nospace() << ',';
113  dbg.space() << table->name();
114  }
115  dbg.space() << ')';
116  } else {
117  dbg.nospace() << "SINGLE-TABLE ASTERISK (" << asterisk.table()->name() << ".*)";
118  }
119  return dbg.space();
120 }
@ Asterisk
Definition: KDbField.h:107
QDebug & nospace()
QString name
QDebug & space()
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
void setTable(const KDbTableSchema *table)
QList< KDbTableSchema * > * tables() const
void setType(Type t)
Definition: KDbField.cpp:620
KDbQueryAsterisk(KDbQuerySchema *query)
const KDbTableSchema * table() const
KDbQuerySchema provides information about database query.
bool isSingleTableAsterisk() const
bool operator==(const KDbQueryAsterisk &other) const
Returns true if this query asterisk is equal to other.
Meta-data for a field.
Definition: KDbField.h:71
KDbQueryAsterisk class encapsulates information about single asterisk in query definition.
KDbField * copy() override
KDbFieldList * parent()
Definition: KDbField.cpp:241
KDbQuerySchema * query()
bool isAllTableAsterisk() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.