21#include "tableschema.h"
23#include "connection.h"
24#include "lookupfieldschema.h"
31class TableSchema::Private
44 void clearLookupFields()
46 for (TQMap<const Field*, LookupFieldSchema*>::ConstIterator it = lookupFields.constBegin();
47 it!=lookupFields.constEnd(); ++it)
55 TQMap<const Field*, LookupFieldSchema*> lookupFields;
56 TQPtrVector<LookupFieldSchema> lookupFieldsList;
64TableSchema::TableSchema(
const TQString& name)
68 , m_isKexiDBSystem(false)
70 m_name = name.lower();
74TableSchema::TableSchema(
const SchemaData& sdata)
78 , m_isKexiDBSystem(false)
83TableSchema::TableSchema()
87 , m_isKexiDBSystem(false)
92TableSchema::TableSchema(
const TableSchema& ts,
bool copyId)
94 , SchemaData(static_cast<const SchemaData&>(ts))
99TableSchema::TableSchema(
const TableSchema& ts,
int setId)
101 , SchemaData(static_cast<const SchemaData&>(ts))
108TableSchema::TableSchema(Connection *conn,
const TQString & name)
110 , SchemaData(
KexiDB::TableObjectType)
113 , m_isKexiDBSystem(false)
118 m_indices.setAutoDelete(
true );
120 m_indices.append(m_pkey);
123TableSchema::~TableSchema()
126 m_conn->removeMe(
this );
131void TableSchema::init()
134 m_indices.setAutoDelete(
true );
136 m_indices.append(m_pkey);
139void TableSchema::init(
const TableSchema& ts,
bool copyId)
143 m_isKexiDBSystem =
false;
146 m_indices.setAutoDelete(
true );
152 IndexSchema::ListIterator idx_it(ts.m_indices);
153 for (;idx_it.current();++idx_it) {
154 IndexSchema *idx =
new IndexSchema(
155 *idx_it.current(), *
this );
159 m_indices.append(idx);
165 if (m_pkey && m_pkey!=pkey) {
166 if (m_pkey->fieldCount()==0) {
167 m_indices.remove(m_pkey);
170 m_pkey->setPrimaryKey(
false);
181 d->anyNonPKField = 0;
188 if (!
field || index>m_fields.count())
190 field->setTable(
this);
191 field->m_order = index;
193 Field *f = m_fields.at(index+1);
194 for (
int i=index+1; f; i++, f = m_fields.next())
199 if (
field->isPrimaryKey()) {
205 if (
field->isUniqueKey()) {
213 if (
field->isIndexed()) {
221 m_indices.append(idx);
227 if (d->anyNonPKField &&
field == d->anyNonPKField)
228 d->anyNonPKField = 0;
229 delete d->lookupFields[
field];
230 d->lookupFields.remove(
field);
239 field->setTable(
this);
240 field->m_order = m_fields.count();
244 if (field->isPrimaryKey()) {
250 if (field->isUniqueKey()) {
258 if (
field->isIndexed()) {
260 idx =
new IndexSchema(
this);
266 m_indices.append(idx);
274 d->clearLookupFields();
334 if (includeTableName)
342 s.append( TQString(
"\n") + lookupSchema->
debugString() );
351 m_isKexiDBSystem = set;
354void TableSchema::setNative(
bool set)
356 if (m_isKexiDBSystem && !set) {
357 KexiDBWarn <<
"TableSchema::setNative(): cannot set native off"
358 " when KexiDB system flag is set on!" << endl;
374 if (!d->anyNonPKField) {
378 for (; (f = it.current()); --it) {
379 if (!f->
isPrimaryKey() && (!m_pkey || !m_pkey->hasField(f)))
382 d->anyNonPKField = f;
384 return d->anyNonPKField;
391 KexiDBWarn <<
"TableSchema::setLookupFieldSchema(): no such field '" << fieldName
392 <<
"' in table " << name() << endl;
398 delete d->lookupFields[f];
399 d->lookupFields.remove( f );
401 d->lookupFieldsList.clear();
407 return d->lookupFields[ &
field ];
420 if (d->lookupFields.isEmpty())
421 return d->lookupFieldsList;
422 if (!d->lookupFields.isEmpty() && !d->lookupFieldsList.isEmpty())
423 return d->lookupFieldsList;
425 d->lookupFieldsList.clear();
426 d->lookupFieldsList.resize( d->lookupFields.count() );
429 TQMap<const Field*, LookupFieldSchema*>::ConstIterator itMap = d->lookupFields.find( it.current() );
430 if (itMap != d->lookupFields.constEnd()) {
431 d->lookupFieldsList.insert( i, itMap.data() );
435 return d->lookupFieldsList;
440InternalTableSchema::InternalTableSchema(
const TQString& name)
445InternalTableSchema::InternalTableSchema(
const TableSchema& ts)
450InternalTableSchema::~InternalTableSchema()
virtual void removeField(KexiDB::Field *field)
FieldList(bool owner=false)
FieldList & addField(Field *field)
virtual TQString debugString()
virtual FieldList & insertField(uint index, Field *field)
bool isPrimaryKey() const
TQPtrListIterator< Field > ListIterator
iterator for list of fields
Provides information about database index that can be created for a database table.
bool isPrimaryKey() const
void setAutoGenerated(bool set)
virtual FieldList & addField(Field *field)
void setPrimaryKey(bool set)
Provides information about lookup field's setup.
TQString debugString() const
KexiDB::QuerySchema provides information about database query.
virtual TQString schemaDataDebugString() const
void clear()
Clears all properties except 'type'.
const TQPtrVector< LookupFieldSchema > & lookupFieldsList()
void setPrimaryKey(IndexSchema *pkey)
virtual TQString debugString()
QuerySchema * m_query
cached query schema that is defined by "select * from <this_table_name>"
virtual FieldList & insertField(uint index, Field *field)
void setKexiDBSystem(bool set)
LookupFieldSchema * lookupFieldSchema(const Field &field) const
virtual void removeField(KexiDB::Field *field)
bool setLookupFieldSchema(const TQString &fieldName, LookupFieldSchema *lookupFieldSchema)
High-level database connectivity library with database backend drivers.