kexi

fieldlist.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2007 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_FIELDLIST_H
00021 #define KEXIDB_FIELDLIST_H
00022 
00023 #include <qvaluelist.h>
00024 #include <qdict.h>
00025 #include <qstring.h>
00026 
00027 #include <kexidb/field.h>
00028 #include <kexidb/driver.h>
00029 
00030 namespace KexiDB {
00031 
00032 class Connection;
00033 
00037 class KEXI_DB_EXPORT FieldList
00038 {
00039     public:
00046         FieldList(bool owner = false);
00047 
00051         FieldList(const FieldList& fl, bool deepCopyFields = true);
00052 
00055         virtual ~FieldList();
00056         
00058         inline uint fieldCount() const { return m_fields.count(); }
00059 
00061         FieldList& addField(Field *field);
00062 
00067         virtual FieldList& insertField(uint index, Field *field);
00068         
00073         virtual void removeField(KexiDB::Field *field);
00074 
00076         inline Field* field(uint id) { return (id < m_fields.count()) ? m_fields.at(id) : 0; }
00077         
00079         virtual Field* field(const QString& name);
00080 
00082         inline bool hasField(const Field* field) { return m_fields.findRef(field)!=-1; }
00083 
00086         inline int indexOf(const Field* field) { return m_fields.findRef(field); }
00087 
00089         QStringList names() const;
00090         
00091         Field::ListIterator fieldsIterator() const { return Field::ListIterator(m_fields); }
00092 
00093         inline Field::List* fields() { return &m_fields; }
00094 
00096         Field::List* autoIncrementFields();
00097 
00099         inline bool isOwner() const { return m_fields.autoDelete(); }
00100 
00102         virtual void clear();
00103 
00105         virtual QString debugString();
00106         
00108         void debug();
00109 
00118         FieldList* subList(const QString& n1, const QString& n2 = QString::null, 
00119             const QString& n3 = QString::null, const QString& n4 = QString::null,
00120             const QString& n5 = QString::null, const QString& n6 = QString::null,
00121             const QString& n7 = QString::null, const QString& n8 = QString::null,
00122             const QString& n9 = QString::null, const QString& n10 = QString::null,
00123             const QString& n11 = QString::null, const QString& n12 = QString::null,
00124             const QString& n13 = QString::null, const QString& n14 = QString::null,
00125             const QString& n15 = QString::null, const QString& n16 = QString::null,
00126             const QString& n17 = QString::null, const QString& n18 = QString::null
00127         );
00128 
00130         FieldList* subList(const QStringList& list);
00131 
00133         FieldList* subList(const QValueList<uint>& list);
00134 
00146         QString sqlFieldsList(Driver *driver, const QString& separator = QString::fromLatin1(","), 
00147             const QString& tableAlias = QString::null,
00148             int drvEscaping = Driver::EscapeDriver|Driver::EscapeAsNecessary);
00149 
00151         static QString sqlFieldsList(Field::List* list, Driver *driver,
00152             const QString& separator = QString::fromLatin1(","), const QString& tableAlias = QString::null,
00153             int drvEscaping = Driver::EscapeDriver|Driver::EscapeAsNecessary);
00154 
00157         void renameField(const QString& oldName, const QString& newName);
00158 
00161         void renameField(KexiDB::Field *field, const QString& newName);
00162 
00163     protected:
00164         Field::List m_fields;
00165         QDict<Field> m_fields_by_name; 
00166         Field::List *m_autoinc_fields;
00167     
00168     private:
00170         QString m_sqlFields;
00171 };
00172 
00173 } //namespace KexiDB
00174 
00175 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys