~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kexi/kexidb/tableschema.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org>
 
3
   Copyright (C) 2003-2006 Jarosław Staniek <staniek@kde.org>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#ifndef KEXIDB_TABLE_H
 
22
#define KEXIDB_TABLE_H
 
23
 
 
24
#include <QList>
 
25
#include <QString>
 
26
#include <QPointer>
 
27
#include <QVector>
 
28
 
 
29
#include "fieldlist.h"
 
30
#include "schemadata.h"
 
31
#include "indexschema.h"
 
32
#include "relationship.h"
 
33
 
 
34
namespace KexiDB
 
35
{
 
36
 
 
37
class Connection;
 
38
class LookupFieldSchema;
 
39
 
 
40
/*! KexiDB::TableSchema provides information about native database table
 
41
  that can be stored using KexiDB database engine.
 
42
*/
 
43
class KEXI_DB_EXPORT TableSchema : public FieldList, public SchemaData
 
44
{
 
45
public:
 
46
    typedef QList<TableSchema*> List; //!< Type of tables list
 
47
    typedef QList<TableSchema>::ConstIterator ListIterator; //!< Iterator for tables list
 
48
 
 
49
    TableSchema(const QString & name);
 
50
    TableSchema(const SchemaData& sdata);
 
51
    TableSchema();
 
52
 
 
53
    /*! Copy constructor.
 
54
     if \a copyId is true, it's copied as well, otherwise the table id becomes -1,
 
55
     what is usable when we want to store the copy as an independent table. */
 
56
    TableSchema(const TableSchema& ts, bool copyId = true);
 
57
 
 
58
    /*! Copy constructor like \ref TableSchema(const TableSchema&, bool).
 
59
     \a setId is set as the table identifier. This is rarely usable, e.g.
 
60
     in project and data migration routines when we need to need deal with unique identifiers;
 
61
     @see KexiMigrate::performImport(). */
 
62
    TableSchema(const TableSchema& ts, int setId);
 
63
 
 
64
    virtual ~TableSchema();
 
65
 
 
66
    /*! Inserts \a field into a specified position (\a index).
 
67
     'order' property of \a field is set automatically. */
 
68
    virtual FieldList& insertField(uint index, Field *field);
 
69
 
 
70
    /*! Reimplemented for internal reasons. */
 
71
    virtual void removeField(KexiDB::Field *field);
 
72
 
 
73
    /*! \return list of fields that are primary key of this table.
 
74
     This method never returns 0 value,
 
75
     if there is no primary key, empty IndexSchema object is returned.
 
76
     IndexSchema object is owned by the table schema. */
 
77
    IndexSchema* primaryKey() const {
 
78
        return m_pkey;
 
79
    }
 
80
 
 
81
    /*! Sets table's primary key index to \a pkey. Pass pkey==0 if you want to unassign
 
82
     existing primary key ("primary" property of given IndexSchema object will be
 
83
     cleared then so this index becomes ordinary index, still existing on table indeices list).
 
84
 
 
85
     If this table already has primary key assigned,
 
86
     it is unassigned using setPrimaryKey(0) call.
 
87
 
 
88
     Before assigning as primary key, you should add the index to indices list
 
89
     with addIndex() (this is not done automatically!).
 
90
    */
 
91
    void setPrimaryKey(IndexSchema *pkey);
 
92
 
 
93
    const IndexSchema::ListIterator indicesIterator() const {
 
94
        return IndexSchema::ListIterator(m_indices.constBegin());
 
95
    }
 
96
 
 
97
    const IndexSchema::List* indices() const {
 
98
        return &m_indices;
 
99
    }
 
100
 
 
101
    /*! Removes all fields from the list, clears name and all other properties.
 
102
      \sa FieldList::clear() */
 
103
    virtual void clear();
 
104
 
 
105
    /*! \return String for debugging purposes, if \a includeTableName is true,
 
106
     table name, caption, etc. is prepended, else only debug string for
 
107
     the fields are returned. */
 
108
    QString debugString(bool includeTableName);
 
109
 
 
110
    /*! \return String for debugging purposes. Equal to debugString(true). */
 
111
    virtual QString debugString();
 
112
 
 
113
    /*! \return connection object if table was created/retrieved using a connection,
 
114
      otherwise 0. */
 
115
    Connection* connection() const;
 
116
 
 
117
    /*! \return true if this is KexiDB storage system's table
 
118
     (used internally by KexiDB). This helps in hiding such tables
 
119
     in applications (if desired) and will also enable lookup of system
 
120
     tables for schema export/import functionality.
 
121
 
 
122
     Any internal KexiDB system table's schema (kexi__*) has
 
123
     cleared its SchemaData part, e.g. id=-1 for such table,
 
124
     and no description, caption and so on. This is because
 
125
     it represents a native database table rather that extended Kexi table.
 
126
 
 
127
     isKexiDBSystem()==true implies isNative()==true.
 
128
 
 
129
     By default (after allocation), TableSchema object
 
130
     has this property set to false. */
 
131
    bool isKexiDBSystem() const {
 
132
        return m_isKexiDBSystem;
 
133
    }
 
134
 
 
135
    /*! Sets KexiDBSystem flag to on or off. When on, native flag is forced to be on.
 
136
     When off, native flag is not affected.
 
137
     \sa isKexiDBSystem() */
 
138
    void setKexiDBSystem(bool set);
 
139
 
 
140
    /*! \return true if this is schema of native database object,
 
141
     When this is kexiDBSystem table, native flag is forced to be on. */
 
142
    virtual bool isNative() const {
 
143
        return m_native || m_isKexiDBSystem;
 
144
    }
 
145
 
 
146
    /* Sets native flag. Does not allow to set this off for system KexiDB table. */
 
147
    virtual void setNative(bool set);
 
148
 
 
149
    /*! \return query schema object that is defined by "select * from <this_table_name>"
 
150
     This query schema object is owned by the table schema object.
 
151
     It is convenient way to get such a query when it is not available otherwise.
 
152
     Always returns non-0. */
 
153
    QuerySchema* query();
 
154
 
 
155
    /*! \return any field not being a part of primary key of this table.
 
156
     If there is no such field, returns 0. */
 
157
    Field* anyNonPKField();
 
158
 
 
159
    /*! Sets lookup field schema \a lookupFieldSchema for \a fieldName.
 
160
     Passing null \a lookupFieldSchema will remove the previously set lookup field.
 
161
     \return true if \a lookupFieldSchema has been added,
 
162
     or false if there is no such field \a fieldName. */
 
163
    bool setLookupFieldSchema(const QString& fieldName, LookupFieldSchema *lookupFieldSchema);
 
164
 
 
165
    /*! \return lookup field schema for \a field.
 
166
     0 is returned if there is no such field in the table or this field has no lookup schema.
 
167
     Note that even id non-zero is returned here, you may want to check whether lookup field's
 
168
     rowSource().name() is empty (if so, the field should behave as there was no lookup field
 
169
     defined at all). */
 
170
    LookupFieldSchema *lookupFieldSchema(const Field& field) const;
 
171
 
 
172
    /*! \overload LookupFieldSchema *TableSchema::lookupFieldSchema( Field& field ) const */
 
173
    LookupFieldSchema *lookupFieldSchema(const QString& fieldName);
 
174
 
 
175
    /*! \return list of lookup field schemas for this table.
 
176
     The order is the same as the order of fields within the table. */
 
177
    const QVector<LookupFieldSchema*>& lookupFieldsList();
 
178
 
 
179
protected:
 
180
    /*! Automatically retrieves table schema via connection. */
 
181
    TableSchema(Connection *conn, const QString & name = QString());
 
182
 
 
183
    IndexSchema::List m_indices;
 
184
 
 
185
    QPointer<Connection> m_conn;
 
186
 
 
187
    IndexSchema *m_pkey;
 
188
 
 
189
    QuerySchema *m_query; //!< cached query schema that is defined by "select * from <this_table_name>"
 
190
 
 
191
    class Private;
 
192
    Private * const d;
 
193
 
 
194
private:
 
195
    //! Used by some ctors.
 
196
    void init();
 
197
 
 
198
    //! Used by some ctors.
 
199
    void init(const TableSchema& ts, bool copyId);
 
200
 
 
201
    bool m_isKexiDBSystem : 1;
 
202
 
 
203
    friend class Connection;
 
204
};
 
205
 
 
206
/*! Internal table with a name \a name. Rarely used.
 
207
 Use Connection::createTable() to create a table using this schema.
 
208
 The table will not be visible as user table.
 
209
 For example, 'kexi__blobs' table is created this way by Kexi application. */
 
210
class KEXI_DB_EXPORT InternalTableSchema : public TableSchema
 
211
{
 
212
public:
 
213
    InternalTableSchema(const QString& name);
 
214
    InternalTableSchema(const TableSchema& ts);
 
215
    virtual ~InternalTableSchema();
 
216
};
 
217
 
 
218
} //namespace KexiDB
 
219
 
 
220
#endif