File indexing completed on 2024-11-03 10:31:37
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003-2017 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KDB_QUERYASTERISK_H 0021 #define KDB_QUERYASTERISK_H 0022 0023 #include "KDbField.h" 0024 0025 class KDbQuerySchema; 0026 0027 //! @short KDbQueryAsterisk class encapsulates information about single asterisk in query definition 0028 /*! There are two types of query asterisks: 0029 0030 1. "Single-table" asterisk, that references all fields of given table used 0031 in the query. 0032 Example SQL statement: 0033 @code 0034 SELECT staff.*, cars.model from staff, cars WHERE staff.car = cars.number; 0035 @endcode 0036 The "staff.*" element is our "single-table" asterisk; 0037 this tells us that we want to get all fields of table "staff". 0038 0039 2. "All-tables" asterisk, that references all fields of all tables used in the query. 0040 Example SQL statement: 0041 @code 0042 SELECT * from staff, cars WHERE staff.car = cars.number; 0043 @endcode 0044 The "*" is our "all-tables" asterisk; 0045 this tells us that we want to get all fields of all used tables (here: "staff" and "cars"). 0046 0047 There can be many asterisks of 1st type defined for given single query. 0048 There can be one asterisk of 2nd type defined for given single query. 0049 */ 0050 class KDB_EXPORT KDbQueryAsterisk : public KDbField 0051 { 0052 public: 0053 /*! Constructs an "all-tables" query asterisk definition object ("*" in SQL notation). 0054 0055 KDbQueryAsterisk objects are owned by KDbQuerySchema object 0056 (not by KDbTableSchema object like for ordinary KDbField objects) 0057 for that the KDbQueryAsterisk object was added (using KDbQuerySchema::addField()). */ 0058 explicit KDbQueryAsterisk(KDbQuerySchema *query); 0059 0060 /*! Constructs a "single-table" query asterisk definition object ("T.*" in SQL notation). 0061 @a table schema is the single table for the asterisk. 0062 0063 KDbQueryAsterisk objects are owned by KDbQuerySchema object 0064 (not by KDbTableSchema object like for ordinary KDbField objects) 0065 for that the KDbQueryAsterisk object was added (using KDbQuerySchema::addField()). */ 0066 KDbQueryAsterisk(KDbQuerySchema *query, const KDbTableSchema &table); 0067 0068 /*! Constructs a deep copy of query asterisk definition object @a asterisk. */ 0069 KDbQueryAsterisk(const KDbQueryAsterisk &asterisk); 0070 0071 ~KDbQueryAsterisk() override; 0072 0073 /** 0074 * @brief Returns @c true if this query asterisk is equal to @a other 0075 * 0076 * @return @c false if the objects are not equal. 0077 * Two asterisks are equal if they return the same table() and query(). 0078 * This also means that both return the same value for isSingleTableAsterisk() and 0079 * isAllTableAsterisk(). 0080 * 0081 * @since 3.1 0082 */ 0083 bool operator==(const KDbQueryAsterisk& other) const; 0084 0085 /** 0086 * @brief Returns @c true if this query asterisk is not equal to @a other 0087 * 0088 * @return @c false if objects are equal. 0089 * 0090 * @see operator==(const KDbQueryAsterisk&) 0091 * @since 3.1 0092 */ 0093 inline bool operator!=(const KDbQueryAsterisk &other) const { return !operator==(other); } 0094 0095 /*! @return Query object for that this asterisk object is defined */ 0096 KDbQuerySchema *query(); 0097 0098 /*! @overload KDbQuerySchema *query() */ 0099 const KDbQuerySchema *query() const; 0100 0101 /*! @return table schema object for that this asterisk object is defined. 0102 If this is a "all-tables" asterisk, @c nullptr is returned. */ 0103 const KDbTableSchema* table() const; 0104 0105 /*! Sets table schema for this asterisk. 0106 If table is supplied, the asterisk become a "single-table" asterisk. 0107 If @a table is @c nullptr the asterisk becames "all-tables" asterisk. */ 0108 void setTable(const KDbTableSchema *table); 0109 0110 /*! This is convenience method that returns @c true 0111 if the asterisk has "all-tables" type (2nd type).*/ 0112 bool isSingleTableAsterisk() const; 0113 0114 /*! This is convenience method that returns @c true 0115 if the asterisk has "single-table" type (2nd type).*/ 0116 bool isAllTableAsterisk() const; 0117 0118 protected: 0119 //! @return a deep copy of this object. Used in KDbFieldList(const KDbFieldList& fl). 0120 KDbField* copy() override; 0121 0122 KDbQueryAsterisk(KDbQuerySchema *query, const KDbTableSchema *table); 0123 0124 private: 0125 class Private; 0126 Private * const d; 0127 KDbQueryAsterisk& operator=(const KDbQueryAsterisk &) = delete; 0128 void setTable(KDbTableSchema *table); // protect 0129 }; 0130 0131 //! Sends query asterisk information @a asterisk to debug output @a dbg. 0132 KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbQueryAsterisk& asterisk); 0133 0134 #endif