Kexi API Documentation (2.0 alpha)

queryschema.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KEXIDB_QUERY_H
00021 #define KEXIDB_QUERY_H
00022 
00023 #include <qvaluevector.h>
00024 #include <qstring.h>
00025 #include <qmap.h>
00026 #include <qptrlist.h>
00027 
00028 #include "fieldlist.h"
00029 #include "schemadata.h"
00030 #include "tableschema.h"
00031 #include "relationship.h"
00032 
00033 namespace KexiDB {
00034 
00035 class Connection;
00036 class QueryAsterisk;
00037 class QuerySchemaPrivate;
00038 class QuerySchemaParameter;
00039 typedef QValueList<QuerySchemaParameter> QuerySchemaParameterList;
00040 
00042 
00048 class KEXI_DB_EXPORT QueryColumnInfo
00049 {
00050     public:
00051         typedef QPtrVector<QueryColumnInfo> Vector;
00052         typedef QPtrList<QueryColumnInfo> List;
00053         typedef QPtrListIterator<QueryColumnInfo> ListIterator;
00054 
00055         QueryColumnInfo(Field *f, const QCString& _alias, bool _visible, QueryColumnInfo *foreignColumn = 0);
00056         ~QueryColumnInfo();
00057 
00059         inline QCString aliasOrName() const { 
00060             return alias.isEmpty() ? field->name().latin1() : (const char*)alias; 
00061         }
00062 
00065         inline QString captionOrAliasOrName() const {
00066             return field->caption().isEmpty() ? QString(aliasOrName()) : field->caption(); }
00067 
00068         Field *field;
00069         QCString alias;
00070 
00075         inline int indexForVisibleLookupValue() const { return m_indexForVisibleLookupValue; }
00076 
00078         inline void setIndexForVisibleLookupValue(int index) { m_indexForVisibleLookupValue = index; }
00079 
00081         QueryColumnInfo *foreignColumn() const { return m_foreignColumn; }
00082 
00084         QString debugString() const;
00085 
00087         bool visible : 1;
00088 
00089     private:
00092         int m_indexForVisibleLookupValue;
00093 
00095         QueryColumnInfo *m_foreignColumn;
00096 };
00097 
00099 
00100 class KEXI_DB_EXPORT OrderByColumn
00101 {
00102     public:
00103         typedef QValueListConstIterator<OrderByColumn> ListConstIterator;
00104         OrderByColumn();
00105         OrderByColumn(QueryColumnInfo& column, bool ascending = true, int pos = -1);
00106         
00109         OrderByColumn(Field& field, bool ascending = true);
00110 
00111         ~OrderByColumn();
00112 
00114         inline QueryColumnInfo* column() const { return m_column; }
00115 
00119         inline int position() const { return m_pos; }
00120 
00122         inline Field *field() const { return m_field; }
00123 
00125         inline bool ascending() const { return m_ascending; }
00126 
00128         bool operator== ( const OrderByColumn& col ) const 
00129             { return m_column==col.m_column && m_field==col.m_field 
00130                 && m_ascending==col.m_ascending; }
00131 
00133         QString debugString() const;
00134 
00138         QString toSQLString(bool includeTableName = true) const;
00139 
00140     protected:
00142         QueryColumnInfo* m_column; 
00143         int m_pos; 
00144 
00145 
00146         Field* m_field; 
00147 
00149         bool m_ascending : 1;
00150 };
00151 
00153 typedef QValueList<OrderByColumn> OrderByColumnListBase;
00154 
00156 class KEXI_DB_EXPORT OrderByColumnList : protected OrderByColumnListBase
00157 {
00158     public:
00160         OrderByColumnList();
00161 
00162         ~OrderByColumnList();
00163 
00168         bool appendFields(QuerySchema& querySchema,
00169             const QString& field1, bool ascending1 = true, 
00170             const QString& field2 = QString::null, bool ascending2 = true, 
00171             const QString& field3 = QString::null, bool ascending3 = true, 
00172             const QString& field4 = QString::null, bool ascending4 = true, 
00173             const QString& field5 = QString::null, bool ascending5 = true);
00174 
00176         void appendColumn(QueryColumnInfo& columnInfo, bool ascending = true);
00177         
00181         void appendField(Field& field, bool ascending = true);
00182 
00186         bool appendField(QuerySchema& querySchema, const QString& fieldName, 
00187             bool ascending = true);
00188 
00191         bool appendColumn(QuerySchema& querySchema, bool ascending = true, int pos = -1);
00192 
00194         void appendColumn(const OrderByColumn& column);
00195         
00197         bool isEmpty() const { return OrderByColumnListBase::isEmpty(); }
00198         
00200         uint count() const { return OrderByColumnListBase::count(); }
00201 
00203         void clear() { OrderByColumnListBase::clear(); }
00204 
00205         const_iterator constBegin () const { return OrderByColumnListBase::constBegin(); }
00206         const_iterator constEnd () const { return OrderByColumnListBase::constEnd(); }
00207 
00209         QString debugString() const;
00210         
00214         QString toSQLString(bool includeTableNames = true) const;
00215 };
00216 
00218 
00221 class KEXI_DB_EXPORT QuerySchema : public FieldList, public SchemaData
00222 {
00223     public:
00225         QuerySchema();
00226 
00241         QuerySchema(TableSchema* tableSchema);
00242         
00243         virtual ~QuerySchema();
00244         
00259         virtual FieldList& insertField(uint position, Field *field);
00260 
00261         /* Like above method, but you can also set column's visibility. 
00262          New column is not bound explicitly to any table.
00263         */
00264         FieldList& insertField(uint position, Field *field, bool visible);
00265 
00266         /* Like above method, but you can also explicitly bound the new column
00267          to specific position on tables list. 
00268          If \a visible is true (the default), the field will be visible. 
00269          If bindToTable==-1, no particular table should be bound.
00270          @see tableBoundToColumn(uint columnPosition) */
00271         FieldList& insertField(uint position, Field *field, 
00272             int bindToTable, bool visible = true);
00273         
00277         FieldList& addField(Field* field, bool visible = true);
00278         
00285         FieldList& addField(Field* field, int bindToTable, 
00286             bool visible = true);
00287 
00289         virtual void removeField(Field *field);
00290 
00293         FieldList& addExpression(BaseExpr* expr, bool visible = true);
00294 
00297         bool isColumnVisible(uint position) const;
00298 
00300         void setColumnVisible(uint position, bool v);
00301 
00303         FieldList& addAsterisk(QueryAsterisk *asterisk, bool visible = true);
00304 
00310         virtual void clear();
00311 
00313         virtual QString debugString();
00314 
00317         Connection* connection() const;
00318         
00330         TableSchema* masterTable() const;
00331 
00336         void setMasterTable(TableSchema *table);
00337         
00341         TableSchema::List* tables() const;
00342 
00347         void addTable(TableSchema *table, const QCString& alias = QCString());
00348 
00353         void removeTable(TableSchema *table);
00354 
00356         TableSchema* table(const QString& tableName) const;
00357         
00359         bool contains(TableSchema *table) const;
00360 
00379         Field* findTableField(const QString &tableOrTableAndFieldName) const;
00380 
00387         QCString columnAlias(uint position) const;
00388         
00394         bool hasColumnAlias(uint position) const;
00395 
00398         void setColumnAlias(uint position, const QCString& alias);
00399 
00421         int tableBoundToColumn(uint columnPosition) const;
00422 
00426         QCString tableAlias(uint position) const;
00427         
00439         int tablePositionForAlias(const QCString& name) const;
00440 
00445         int tablePosition(const QString& tableName) const;
00446         
00453         QValueList<int> tablePositions(const QString& tableName) const;
00454 
00460         bool hasTableAlias(uint position) const;
00461 
00464         int columnPositionForAlias(const QCString& name) const;
00465 
00470         void setTableAlias(uint position, const QCString& alias);
00471 
00473         Relationship::List* relationships() const;
00474 
00482         Relationship* addRelationship( Field *field1, Field *field2 );
00483 
00485         Field::List* asterisks() const;
00486 
00511         virtual Field* field(const QString& name, bool expanded = true);
00512 
00514         inline Field* field(uint id) { return FieldList::field(id); }
00515 
00528         QueryColumnInfo* columnInfo(const QString& identifier, bool expanded = true);
00529 
00531         enum FieldsExpandedOptions {
00532             Default,                   
00533             Unique,                    
00534             WithInternalFields,        
00535             WithInternalFieldsAndRowID 
00536 
00537         };
00538 
00580         QueryColumnInfo::Vector fieldsExpanded(FieldsExpandedOptions options = Default);
00581 
00583         QueryColumnInfo::Vector internalFields();
00584 
00589         QueryColumnInfo* expandedOrInternalField(uint index);
00590 
00592         enum ColumnsOrderOptions {
00593             UnexpandedList,                 
00594             UnexpandedListWithoutAsterisks, 
00595             ExpandedList                    
00596         };
00597 
00627         QMap<QueryColumnInfo*,int> columnsOrder(ColumnsOrderOptions options = ExpandedList);
00628 
00651         QValueVector<int> pkeyFieldsOrder();
00652 
00671         uint pkeyFieldsCount();
00672 
00677         QueryColumnInfo::List* autoIncrementFields();
00678 
00680         QString statement() const;
00681 
00683         void setStatement(const QString &s);
00684 
00695         static QString sqlColumnsList(QueryColumnInfo::List* infolist, Driver *driver);
00696 
00699         QString autoIncrementSQLFieldsList(Driver *driver);
00700 
00704         void setWhereExpression(BaseExpr *expr);
00705 
00707         BaseExpr *whereExpression() const;
00708     
00712         void addToWhereExpression(KexiDB::Field *field, const QVariant& value, int relation = '=');
00713 
00726         void setOrderByColumnList(const OrderByColumnList& list);
00727 
00730         OrderByColumnList& orderByColumnList() const;
00731 
00734         QuerySchemaParameterList parameters();
00735 
00736     protected:
00737         void init();
00738 
00739         void computeFieldsExpanded();
00740 
00741         QuerySchemaPrivate *d;
00742         
00743     friend class Connection;
00744     friend class QuerySchemaPrivate;
00745 };
00746 
00748 
00770 class KEXI_DB_EXPORT QueryAsterisk : protected Field
00771 {
00772     public:
00782         QueryAsterisk( QuerySchema *query, TableSchema *table = 0 );
00783         
00784         virtual ~QueryAsterisk();
00785 
00787         QuerySchema *query() const { return static_cast<QuerySchema*>(m_parent); }
00788 
00792         virtual TableSchema* table() const { return m_table; }
00793 
00796         virtual void setTable(TableSchema *table);
00797 
00800         bool isSingleTableAsterisk() const { return m_table!=NULL; }
00801         
00804         bool isAllTableAsterisk() const { return m_table==NULL; }
00805         
00807         virtual QString debugString();
00808 
00809     protected:
00811         TableSchema* m_table;
00812 
00813     friend class QuerySchema;
00814 };
00815 
00816 } //namespace KexiDB
00817 
00818 #endif
KDE Logo
This file is part of the documentation for Kexi 2.0 alpha.
Documentation copyright © 2002-2007 the Kexi Team.
Generated on Tue Apr 1 20:48:48 2008 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003