mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
In the Edit Table dialog we used to call our alterTable function (which works around SQLite's missing full ALTER TABLE support by - besided other things - copying all the data of the table) for pretty much every change immediately. This was taking a lot of time for larger tables. Our alterTable function allowed any number of changes if they affect only one field of the table at once. So we could have reduced the number of calls a lot by just using that capability. Instead however, this commit improves the alterTable function to make possible transforming a table completely in just one call. It does so by taking the new table schema and using that without further modification. It also takes a new parameter to keep track of what column in the old table becomes what column in the new table, so the data can be preserved. This commit obviously also changes the Edit Table dialog to make proper use of the new features. This means that whatever changes you make to a table, you will only have to wait once until for the alterTable call, and that's when clicking the OK button. See issue #1444.
74 lines
1.6 KiB
C++
74 lines
1.6 KiB
C++
#ifndef EDITTABLEDIALOG_H
|
|
#define EDITTABLEDIALOG_H
|
|
|
|
#include "sql/sqlitetypes.h"
|
|
|
|
#include <QDialog>
|
|
|
|
class DBBrowserDB;
|
|
class QTreeWidgetItem;
|
|
class ForeignKeyEditorDelegate;
|
|
|
|
namespace Ui {
|
|
class EditTableDialog;
|
|
}
|
|
|
|
class EditTableDialog : public QDialog
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit EditTableDialog(DBBrowserDB& pdb, const sqlb::ObjectIdentifier& tableName, bool createTable, QWidget* parent = nullptr);
|
|
~EditTableDialog() override;
|
|
|
|
protected:
|
|
void keyPressEvent(QKeyEvent *evt) override;
|
|
|
|
private:
|
|
enum Columns {
|
|
kName = 0,
|
|
kType = 1,
|
|
kNotNull = 2,
|
|
kPrimaryKey = 3,
|
|
kAutoIncrement = 4,
|
|
kUnique = 5,
|
|
kDefault = 6,
|
|
kCheck = 7,
|
|
kForeignKey = 8
|
|
};
|
|
|
|
void updateColumnWidth();
|
|
void updateSqlText();
|
|
|
|
void moveCurrentField(bool down);
|
|
|
|
private slots:
|
|
void populateFields();
|
|
void addField();
|
|
void removeField();
|
|
void fieldSelectionChanged();
|
|
void accept() override;
|
|
void reject() override;
|
|
void checkInput();
|
|
void itemChanged(QTreeWidgetItem* item, int column);
|
|
void updateTypes(QObject *object);
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
|
void updateTypes();
|
|
void moveUp();
|
|
void moveDown();
|
|
void setWithoutRowid(bool without_rowid);
|
|
void changeSchema(const QString& schema);
|
|
|
|
private:
|
|
Ui::EditTableDialog* ui;
|
|
DBBrowserDB& pdb;
|
|
ForeignKeyEditorDelegate* m_fkEditorDelegate;
|
|
sqlb::ObjectIdentifier curTable;
|
|
QMap<QString, QString> trackColumns;
|
|
sqlb::Table m_table;
|
|
bool m_bNewTable;
|
|
QString m_sRestorePointName;
|
|
};
|
|
|
|
#endif
|