Changeset View
Changeset View
Standalone View
Standalone View
src/KDbConnection.cpp
Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Line(s) | 265 | { | |||
---|---|---|---|---|---|
267 | if (internalTable) { | 267 | if (internalTable) { | ||
268 | m_internalKDbTables.insert(internalTable); | 268 | m_internalKDbTables.insert(internalTable); | ||
269 | } else { | 269 | } else { | ||
270 | m_tables.insert(tableSchema->id(), tableSchema); | 270 | m_tables.insert(tableSchema->id(), tableSchema); | ||
271 | } | 271 | } | ||
272 | m_tablesByName.insert(tableSchema->name(), tableSchema); | 272 | m_tablesByName.insert(tableSchema->name(), tableSchema); | ||
273 | } | 273 | } | ||
274 | 274 | | |||
275 | void KDbConnectionPrivate::removeTable(const KDbTableSchema& tableSchema) | 275 | void KDbConnectionPrivate::removeTable(int id) | ||
276 | { | 276 | { | ||
277 | KDbTableSchemaChangeListener::unregisterForChanges(conn, &tableSchema); | 277 | QScopedPointer<KDbTableSchema> toDelete(m_tables.take(id)); | ||
278 | m_tablesByName.remove(tableSchema.name()); | 278 | if (!toDelete) { | ||
279 | KDbTableSchema *toDelete = m_tables.take(tableSchema.id()); | 279 | kdbWarning() << "Could not find table to delete with id=" << id; | ||
280 | delete toDelete; | 280 | return; | ||
281 | } | ||||
282 | KDbTableSchemaChangeListener::unregisterForChanges(conn, toDelete.data()); | ||||
283 | const int count = m_tablesByName.remove(toDelete->name()); | ||||
284 | Q_ASSERT_X(count == 1, "KDbConnectionPrivate::removeTable", "Table to remove not found"); | ||||
281 | } | 285 | } | ||
282 | 286 | | |||
283 | void KDbConnectionPrivate::takeTable(KDbTableSchema* tableSchema) | 287 | void KDbConnectionPrivate::takeTable(KDbTableSchema* tableSchema) | ||
284 | { | 288 | { | ||
285 | if (m_tables.isEmpty()) { | 289 | if (m_tables.isEmpty()) { | ||
286 | return; | 290 | return; | ||
287 | } | 291 | } | ||
288 | m_tables.take(tableSchema->id()); | 292 | m_tables.take(tableSchema->id()); | ||
▲ Show 20 Lines • Show All 1183 Lines • ▼ Show 20 Line(s) | 1452 | if (!internalTable) { | |||
1472 | if (!storeExtendedTableSchemaData(tableSchema)) | 1476 | if (!storeExtendedTableSchemaData(tableSchema)) | ||
1473 | createTable_ERR; | 1477 | createTable_ERR; | ||
1474 | } | 1478 | } | ||
1475 | bool res = commitAutoCommitTransaction(tg.transaction()); | 1479 | bool res = commitAutoCommitTransaction(tg.transaction()); | ||
1476 | if (res) { | 1480 | if (res) { | ||
1477 | if (!internalTable) { | 1481 | if (!internalTable) { | ||
1478 | if (previousSchemaStillKept) { | 1482 | if (previousSchemaStillKept) { | ||
1479 | //remove previous table schema | 1483 | //remove previous table schema | ||
1480 | d->removeTable(*tableSchema); | 1484 | d->removeTable(tableSchema->id()); | ||
1481 | } | 1485 | } | ||
1482 | } | 1486 | } | ||
1483 | //store locally | 1487 | //store locally | ||
1484 | d->insertTable(tableSchema); | 1488 | d->insertTable(tableSchema); | ||
1485 | //ok, this table is not created by the connection | 1489 | //ok, this table is not created by the connection | ||
1486 | tableSchema->setConnection(this); | 1490 | tableSchema->setConnection(this); | ||
1487 | } | 1491 | } | ||
1488 | return res; | 1492 | return res; | ||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 1621 | if (!removeObject(tableSchema->id())) { | |||
1618 | return false; | 1622 | return false; | ||
1619 | } | 1623 | } | ||
1620 | 1624 | | |||
1621 | if (alsoRemoveSchema) { | 1625 | if (alsoRemoveSchema) { | ||
1622 | //! @todo js: update any structure (e.g. queries) that depend on this table! | 1626 | //! @todo js: update any structure (e.g. queries) that depend on this table! | ||
1623 | tristate res = removeDataBlock(tableSchema->id(), QLatin1String("extended_schema")); | 1627 | tristate res = removeDataBlock(tableSchema->id(), QLatin1String("extended_schema")); | ||
1624 | if (!res) | 1628 | if (!res) | ||
1625 | return false; | 1629 | return false; | ||
1626 | d->removeTable(*tableSchema); | 1630 | d->removeTable(tableSchema->id()); | ||
1627 | } | 1631 | } | ||
1628 | return commitAutoCommitTransaction(tg.transaction()); | 1632 | return commitAutoCommitTransaction(tg.transaction()); | ||
1629 | } | 1633 | } | ||
1630 | 1634 | | |||
1631 | tristate KDbConnection::dropTable(const QString& tableName) | 1635 | tristate KDbConnection::dropTable(const QString& tableName) | ||
1632 | { | 1636 | { | ||
1633 | clearResult(); | 1637 | clearResult(); | ||
1634 | KDbTableSchema* ts = tableSchema(tableName); | 1638 | KDbTableSchema* ts = tableSchema(tableName); | ||
▲ Show 20 Lines • Show All 1856 Lines • Show Last 20 Lines |