20#include <kexidb/relationship.h>
22#include <kexidb/indexschema.h>
23#include <kexidb/tableschema.h>
24#include <kexidb/queryschema.h>
25#include <kexidb/driver.h>
31Relationship::Relationship()
34 , m_masterIndexOwned(false)
35 , m_detailsIndexOwned(false)
37 m_pairs.setAutoDelete(
true);
43 , m_masterIndexOwned(false)
44 , m_detailsIndexOwned(false)
46 m_pairs.setAutoDelete(
true);
47 setIndices(masterIndex, detailsIndex);
53 , m_masterIndexOwned(false)
54 , m_detailsIndexOwned(false)
56 m_pairs.setAutoDelete(
true);
57 createIndices( query, field1, field2 );
60Relationship::~Relationship()
62 if (m_masterIndexOwned)
64 if (m_detailsIndexOwned)
65 delete m_detailsIndex;
70 if (!field1 || !field2 || !query) {
71 KexiDBWarn <<
"Relationship::addRelationship(): !masterField || !detailsField || !query" << endl;
75 KexiDBWarn <<
"Relationship::addRelationship(): relationship's fields cannot be asterisks" << endl;
79 KexiDBWarn <<
"Relationship::addRelationship(): fields cannot belong to the same table" << endl;
84 KexiDBWarn <<
"Relationship::addRelationship(): fields do not belong to this query" << endl;
90 Field *masterField = 0, *detailsField = 0;
96 detailsField = field2;
110 masterField = field1;
112 detailsField = field2;
115 m_detailsIndex =
new IndexSchema(detailsField->table());
116 m_detailsIndexOwned =
true;
117 m_detailsIndex->addField(detailsField);
118 m_detailsIndex->setForeignKey(
true);
120 else if (!p1 && !p2) {
121 masterField = field1;
123 m_masterIndexOwned =
true;
124 m_masterIndex->addField(masterField);
125 m_masterIndex->setForeignKey(
true);
127 detailsField = field2;
128 m_detailsIndex =
new IndexSchema(detailsField->table());
129 m_detailsIndexOwned =
true;
130 m_detailsIndex->addField(detailsField);
131 m_detailsIndex->setForeignKey(
true);
134 if (!m_masterIndex || !m_detailsIndex)
137 setIndices(m_masterIndex, m_detailsIndex,
false);
142 return m_masterIndex ? m_masterIndex->table() : 0;
147 return m_detailsIndex ? m_detailsIndex->table() : 0;
152 setIndices(masterIndex, detailsIndex,
true);
160 if (!masterIndex || !detailsIndex || !masterIndex->
table() || !detailsIndex->
table()
165 for (;it1.current() && it1.current(); ++it1, ++it2) {
166 Field *f1 = it1.current();
167 Field *f2 = it2.current();
170 KexiDBWarn <<
"Relationship::setIndices(INDEX on '"<<masterIndex->
table()->name()
171 <<
"',INDEX on "<<detailsIndex->
table()->name()<<
"): !equal field types: "
179 KexiDBWarn <<
"Relationship::setIndices(INDEX on '"<<masterIndex->
table()->name()
180 <<
"',INDEX on "<<detailsIndex->
table()->name()<<
"): !equal signedness of field types: "
191 m_masterIndex->detachRelationship(
this);
193 if (m_detailsIndex) {
194 m_detailsIndex->detachRelationship(
this);
196 m_masterIndex = masterIndex;
197 m_detailsIndex = detailsIndex;
199 m_detailsIndex->attachRelationship(
this, ownedByMaster);
static TQString defaultSQLTypeName(int id_t)
bool isPrimaryKey() const
TQPair< Field *, Field * > Pair
fields pair
bool isIntegerType() const
TQPtrListIterator< Field > ListIterator
iterator for list of fields
virtual bool isQueryAsterisk() const
virtual TableSchema * table() const
bool isUnsigned() const
if the type has the unsigned attribute
Provides information about database index that can be created for a database table.
TableSchema * table() const
void attachRelationship(Relationship *rel)
KexiDB::QuerySchema provides information about database query.
bool contains(TableSchema *table) const
IndexSchema * primaryKey() const
High-level database connectivity library with database backend drivers.