1
/* This file is part of the KDE project
2
Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org>
3
Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl>
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.
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.
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., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
21
#ifndef KEXIDB_TABLE_H
22
#define KEXIDB_TABLE_H
24
#include <qvaluelist.h>
28
#include <kexidb/fieldlist.h>
29
#include <kexidb/schemadata.h>
30
#include <kexidb/indexschema.h>
31
#include <kexidb/relationship.h>
37
/*! KexiDB::TableSchema provides information about native database table
38
that can be stored using SQL database engine.
41
class KEXI_DB_EXPORT TableSchema : public FieldList, public SchemaData
44
typedef QPtrList<TableSchema> List; //!< Type of tables list
45
typedef QPtrListIterator<TableSchema> ListIterator; //!< Iterator for tables list
47
TableSchema(const QString & name);
48
TableSchema(const SchemaData& sdata);
51
/*! Copy constructor. */
52
TableSchema(const TableSchema& ts);
54
virtual ~TableSchema();
56
/*! Inserts \a field into a specified position (\a index).
57
'order' property of \a field is set automatically. */
58
virtual FieldList& insertField(uint index, Field *field);
60
/*! Reimplemented for internal reasons. */
61
virtual void removeField(KexiDB::Field *field);
63
/*! \return list of fields that are primary key of this table.
64
This method never returns NULL value,
65
if there is no primary key, empty IndexSchema object is returned.
66
IndexSchema object is owned by the table schema. */
67
IndexSchema* primaryKey() const { return m_pkey; }
69
/*! Sets table's primary key index to \a pkey. Pass pkey==NULL if you want to unassign
70
existing primary key ("primary" property of given IndexSchema object will be
71
cleared then so this index becomes ordinary index, still existing on table indeices list).
73
If this table already has primary key assigned,
74
it is unassigned using setPrimaryKey(NULL) call.
76
Before assigning as primary key, you should add the index to indices list
77
with addIndex() (this is not done automatically!).
79
void setPrimaryKey(IndexSchema *pkey);
81
const IndexSchema::ListIterator indicesIterator() const
82
{ return IndexSchema::ListIterator(m_indices); }
84
const IndexSchema::List* indices() { return &m_indices; }
86
/*! Removes all fields from the list, clears name and all other properties.
87
\sa FieldList::clear() */
90
/*! \return String for debugging purposes. */
91
virtual QString debugString();
93
/*! if table was created using a connection,
94
returns this connection object, otherwise NULL. */
95
Connection* connection() const { return m_conn; }
97
/*! \return true if this is KexiDB storage system's table
98
(used internally by KexiDB). This helps in hiding such tables
99
in applications (if desired) and will also enable lookup of system
100
tables for schema export/import functionality.
102
Any internal KexiDB system table's schema (kexi__*) has
103
cleared its SchemaData part, e.g. id=-1 for such table,
104
and no description, caption and so on. This is because
105
it represents a native database table rather that extended Kexi table.
107
isKexiDBSystem()==true implies isNative()==true.
109
By default (after allocation), TableSchema object
110
has this property set to false. */
111
bool isKexiDBSystem() const { return m_isKexiDBSystem; }
113
/*! Sets KexiDBSystem flag to on or off. When on, native flag is forced to be on.
114
When off, native flag is not affected.
115
\sa isKexiDBSystem() */
116
void setKexiDBSystem(bool set);
118
/*! \return true if this is schema of native database object,
119
When this is kexiDBSystem table, native flag is forced to be on. */
120
virtual bool isNative() const { return m_native || m_isKexiDBSystem; }
122
/* Sets native flag. Does not allow to set this off for system KexiDB table. */
123
virtual void setNative(bool set);
125
/*! \return query schema object that is defined by "select * from <this_table_name>"
126
This query schema object is owned by the table schema object.
127
It is convenient way to get such a query when it is available otherwise.
128
Always return non-null.
130
QuerySchema* query();
133
Field* anyNonPKField();
136
/*! Automatically retrieves table schema via connection. */
137
TableSchema(Connection *conn, const QString & name = QString::null);
141
IndexSchema::List m_indices;
147
QuerySchema *m_query; //!< cached query schema that is defined by "select * from <this_table_name>"
153
bool m_isKexiDBSystem : 1;
155
friend class Connection;