diff --git a/src/KDbConnection.cpp b/src/KDbConnection.cpp --- a/src/KDbConnection.cpp +++ b/src/KDbConnection.cpp @@ -272,12 +272,16 @@ m_tablesByName.insert(tableSchema->name(), tableSchema); } -void KDbConnectionPrivate::removeTable(const KDbTableSchema& tableSchema) +void KDbConnectionPrivate::removeTable(int id) { - KDbTableSchemaChangeListener::unregisterForChanges(conn, &tableSchema); - m_tablesByName.remove(tableSchema.name()); - KDbTableSchema *toDelete = m_tables.take(tableSchema.id()); - delete toDelete; + QScopedPointer toDelete(m_tables.take(id)); + if (!toDelete) { + kdbWarning() << "Could not find table to delete with id=" << id; + return; + } + KDbTableSchemaChangeListener::unregisterForChanges(conn, toDelete.data()); + const int count = m_tablesByName.remove(toDelete->name()); + Q_ASSERT_X(count == 1, "KDbConnectionPrivate::removeTable", "Table to remove not found"); } void KDbConnectionPrivate::takeTable(KDbTableSchema* tableSchema) @@ -1477,7 +1481,7 @@ if (!internalTable) { if (previousSchemaStillKept) { //remove previous table schema - d->removeTable(*tableSchema); + d->removeTable(tableSchema->id()); } } //store locally @@ -1623,7 +1627,7 @@ tristate res = removeDataBlock(tableSchema->id(), QLatin1String("extended_schema")); if (!res) return false; - d->removeTable(*tableSchema); + d->removeTable(tableSchema->id()); } return commitAutoCommitTransaction(tg.transaction()); } diff --git a/src/KDbConnection_p.h b/src/KDbConnection_p.h --- a/src/KDbConnection_p.h +++ b/src/KDbConnection_p.h @@ -81,10 +81,9 @@ void insertTable(KDbTableSchema* tableSchema); - /*! Removes table schema pointed by tableSchema.id() and tableSchema.name() - from internal structures and destroys it. Does not make any change at the backend. - Note that the table schema being removed may be not the same as @a tableSchema. */ - void removeTable(const KDbTableSchema& tableSchema); + /*! Removes table schema having identifier @a id from internal structures and destroys it. + Does not make any change at the backend. */ + void removeTable(int id); void takeTable(KDbTableSchema* tableSchema); diff --git a/src/KDbTableSchemaChangeListener.cpp b/src/KDbTableSchemaChangeListener.cpp --- a/src/KDbTableSchemaChangeListener.cpp +++ b/src/KDbTableSchemaChangeListener.cpp @@ -85,7 +85,7 @@ if (listener) { listeners->remove(listener); } else { - listeners->clear(); + delete conn->d->tableSchemaChangeListeners.take(table); } }