KDb

KDbQueryAsterisk.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003-2017 Jarosław Staniek <staniek@kde.org>
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
24class KDbQueryAsterisk::Private
25{
26public:
27 Private(const KDbTableSchema *t) : table(t) {}
28
29 /*! Table schema for this asterisk */
30 const KDbTableSchema* table;
31};
32
33// ----
34
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
58KDbQueryAsterisk::~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
103QDebug 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}
Meta-data for a field.
Definition KDbField.h:72
void setType(Type t)
Definition KDbField.cpp:620
KDbFieldList * parent()
Definition KDbField.cpp:241
KDbQueryAsterisk class encapsulates information about single asterisk in query definition.
bool isSingleTableAsterisk() const
KDbQueryAsterisk(KDbQuerySchema *query)
const KDbTableSchema * table() const
KDbQuerySchema * query()
bool isAllTableAsterisk() const
KDbField * copy() override
bool operator==(const KDbQueryAsterisk &other) const
Returns true if this query asterisk is equal to other.
void setTable(const KDbTableSchema *table)
KDbQuerySchema provides information about database query.
QList< KDbTableSchema * > * tables() const
QDebug & nospace()
QDebug & space()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.