diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index ffff932c..58fc3d15 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -217,7 +217,7 @@ void EditTableDialog::checkInput() if (oldTableName == fk->table()) { fk->setTable(normTableName); if(!m_bForeignKeysEnabled) - pdb.renameColumn(curTable, m_table, f->name(), f, 0); + pdb.alterTable(curTable, m_table, f->name(), f, 0); } } } @@ -246,7 +246,7 @@ void EditTableDialog::updateTypes(QObject *object) m_table.fields().at(index)->setType(type); if(!m_bNewTable) - pdb.renameColumn(curTable, m_table, column, m_table.fields().at(index)); + pdb.alterTable(curTable, m_table, column, m_table.fields().at(index)); checkInput(); } } @@ -514,7 +514,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column) if(callRenameColumn) { - if(!pdb.renameColumn(curTable, m_table, oldFieldName, field)) + if(!pdb.alterTable(curTable, m_table, oldFieldName, field)) QMessageBox::warning(this, qApp->applicationName(), tr("Modifying this column failed. Error returned from database:\n%1").arg(pdb.lastError())); } } @@ -602,7 +602,7 @@ void EditTableDialog::removeField() QString msg = tr("Are you sure you want to delete the field '%1'?\nAll data currently stored in this field will be lost.").arg(ui->treeWidget->currentItem()->text(0)); if(QMessageBox::warning(this, QApplication::applicationName(), msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) { - if(!pdb.renameColumn(curTable, m_table, ui->treeWidget->currentItem()->text(0), sqlb::FieldPtr())) + if(!pdb.alterTable(curTable, m_table, ui->treeWidget->currentItem()->text(0), sqlb::FieldPtr())) { QMessageBox::warning(nullptr, QApplication::applicationName(), pdb.lastError()); } else { @@ -680,7 +680,7 @@ void EditTableDialog::moveCurrentField(bool down) // Editing an old one // Move the actual column - if(!pdb.renameColumn( + if(!pdb.alterTable( curTable, m_table, ui->treeWidget->currentItem()->text(0), @@ -737,7 +737,7 @@ void EditTableDialog::setWithoutRowid(bool without_rowid) // Update table if we're editing an existing table if(!m_bNewTable) { - if(!pdb.renameColumn(curTable, m_table, QString(), sqlb::FieldPtr(), 0)) + if(!pdb.alterTable(curTable, m_table, QString(), sqlb::FieldPtr(), 0)) { QMessageBox::warning(this, QApplication::applicationName(), tr("Setting the rowid column for the table failed. Error message:\n%1").arg(pdb.lastError())); @@ -753,7 +753,7 @@ void EditTableDialog::changeSchema(const QString& schema) // Update table if we're editing an existing table if(!m_bNewTable) { - if(pdb.renameColumn(curTable, m_table, QString(), sqlb::FieldPtr(), 0, schema)) + if(pdb.alterTable(curTable, m_table, QString(), sqlb::FieldPtr(), 0, schema)) { // Save the new schema name to use it from now on curTable.setSchema(schema); diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 6bb3050d..e30c56c8 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -1080,7 +1080,7 @@ bool DBBrowserDB::addColumn(const sqlb::ObjectIdentifier& tablename, const sqlb: return executeSQL(sql); } -bool DBBrowserDB::renameColumn(const sqlb::ObjectIdentifier& tablename, const sqlb::Table& table, const QString& name, sqlb::FieldPtr to, int move, QString newSchemaName) +bool DBBrowserDB::alterTable(const sqlb::ObjectIdentifier& tablename, const sqlb::Table& table, const QString& name, sqlb::FieldPtr to, int move, QString newSchemaName) { /* * USE CASES: @@ -1104,7 +1104,6 @@ bool DBBrowserDB::renameColumn(const sqlb::ObjectIdentifier& tablename, const sq // more easily. Besides that, it might make sense to support some potential use cases in a more sophisticated way. These include: // 1) Allow modifying multiple columns at once in order to only have to call this function (including all its overhead) once instead of once per change. // 2) Include the addColumn() use case in here, so the calling side doesn't need to know anything about how this class handles table modifications. - // 3) Maybe rename this function to alterTable() or something // If no new schema name has been set, we just use the old schema name if(newSchemaName.isNull()) diff --git a/src/sqlitedb.h b/src/sqlitedb.h index 0a0a69e9..bc6fb19b 100644 --- a/src/sqlitedb.h +++ b/src/sqlitedb.h @@ -79,7 +79,7 @@ public: bool addColumn(const sqlb::ObjectIdentifier& tablename, const sqlb::FieldPtr& field); /** - * @brief renameColumn Can be used to rename, modify or drop an existing column of a given table + * @brief alterTable Can be used to rename, modify or drop an existing column of a given table * @param schema Specifies the name of the schema, i.e. the database name, of the table * @param tablename Specifies the name of the table to edit * @param table Specifies the table to edit. The table constraints are used from this but not the columns @@ -89,7 +89,7 @@ public: * @param newSchema Set this to a non-empty string to move the table to a new schema * @return true if renaming was successful, false if not. In the latter case also lastErrorMessage is set */ - bool renameColumn(const sqlb::ObjectIdentifier& tablename, const sqlb::Table& table, const QString& name, sqlb::FieldPtr to, int move = 0, QString newSchemaName = QString()); + bool alterTable(const sqlb::ObjectIdentifier& tablename, const sqlb::Table& table, const QString& name, sqlb::FieldPtr to, int move = 0, QString newSchemaName = QString()); objectMap getBrowsableObjects(const QString& schema) const; const sqlb::ObjectPtr getObjectByName(const sqlb::ObjectIdentifier& name) const;