mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-22 21:48:24 -05:00
Fix a number of bugs
Fix bug when closing the editFieldForm. Fix bug that not always the correct database object was used. Fix bug that changed field type when changing field name in editTableForm.
This commit is contained in:
@@ -13,8 +13,9 @@
|
||||
* The dialog will by default be modeless, unless you set 'modal' to
|
||||
* true to construct a modal dialog.
|
||||
*/
|
||||
createTableForm::createTableForm(QWidget* parent, Qt::WindowFlags fl)
|
||||
: QDialog(parent, fl)
|
||||
createTableForm::createTableForm(DBBrowserDB *db, QWidget* parent, Qt::WindowFlags fl)
|
||||
: QDialog(parent, fl),
|
||||
pdb(db)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
@@ -115,7 +116,7 @@ void createTableForm::addField()
|
||||
//TODO maybe embedd locally
|
||||
editFieldForm * addForm = new editFieldForm( this );
|
||||
addForm->setModal(true);
|
||||
addForm->setInitialValues(true, QString(""), QString(""),QString(""));
|
||||
addForm->setInitialValues(pdb, true, QString(""), QString(""),QString(""));
|
||||
if (addForm->exec())
|
||||
{
|
||||
QTreeWidgetItem *newItem = new QTreeWidgetItem();
|
||||
|
||||
@@ -215,7 +215,7 @@ class createTableForm : public QDialog, public Ui::createTableForm
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
createTableForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
|
||||
createTableForm( DBBrowserDB *db = 0, QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
|
||||
~createTableForm();
|
||||
|
||||
QString createStatement;
|
||||
@@ -231,6 +231,7 @@ protected slots:
|
||||
|
||||
private:
|
||||
void init();
|
||||
DBBrowserDB *pdb;
|
||||
|
||||
};
|
||||
|
||||
|
||||
+6
-10
@@ -31,13 +31,9 @@ editFieldForm::~editFieldForm()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void editFieldForm::setDB(DBBrowserDB &db)
|
||||
{
|
||||
this->pdb = db;
|
||||
}
|
||||
|
||||
void editFieldForm::setInitialValues(bool is_new, QString table, QString fld_name, QString fld_type)
|
||||
void editFieldForm::setInitialValues(DBBrowserDB *db, bool is_new, QString table, QString fld_name, QString fld_type)
|
||||
{
|
||||
pdb = db;
|
||||
original_field_name = QString(fld_name);
|
||||
table_name = table;
|
||||
ui->nameLineEdit->setText(fld_name);
|
||||
@@ -75,14 +71,14 @@ void editFieldForm::accept()
|
||||
field_type = ui->txtCustomType->text();
|
||||
bool ok;
|
||||
if(is_new)
|
||||
ok = pdb.createColumn(table_name, field_name, field_type);
|
||||
ok = pdb->createColumn(table_name, field_name, field_type);
|
||||
else
|
||||
ok = pdb.renameColumn(table_name, original_field_name, field_name, field_type);
|
||||
ok = pdb->renameColumn(table_name, original_field_name, field_name, field_type);
|
||||
if(!ok){
|
||||
qDebug(pdb.lastErrorMessage.toUtf8());
|
||||
qDebug(pdb->lastErrorMessage.toUtf8());
|
||||
return;
|
||||
}
|
||||
accept();
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void editFieldForm::checkInput()
|
||||
|
||||
+2
-4
@@ -16,8 +16,6 @@ public:
|
||||
editFieldForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
|
||||
~editFieldForm();
|
||||
|
||||
void setDB(DBBrowserDB &db);
|
||||
|
||||
QString table_name;
|
||||
QString field_name;
|
||||
QString field_type;
|
||||
@@ -25,12 +23,12 @@ public:
|
||||
bool is_new;
|
||||
|
||||
public slots:
|
||||
virtual void setInitialValues( bool is_new, QString table, QString fld_name, QString fld_type );
|
||||
virtual void setInitialValues( DBBrowserDB *db, bool is_new, QString table, QString fld_name, QString fld_type );
|
||||
virtual void accept();
|
||||
virtual void checkInput();
|
||||
|
||||
private:
|
||||
DBBrowserDB pdb;
|
||||
DBBrowserDB *pdb;
|
||||
Ui::editFieldForm *ui;
|
||||
};
|
||||
|
||||
|
||||
+19
-16
@@ -64,20 +64,23 @@ void editTableForm::populateFields()
|
||||
|
||||
void editTableForm::accept()
|
||||
{
|
||||
// Rename table
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time
|
||||
modified = true;
|
||||
QString newName = ui->editTableName->text();
|
||||
QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(curTable, newName);
|
||||
if (!pdb->executeSQL(sql)){
|
||||
QApplication::restoreOverrideCursor();
|
||||
QString error("Error renaming table. Message from database engine:\n");
|
||||
error.append(pdb->lastErrorMessage).append("\n\n").append(sql);
|
||||
QMessageBox::warning( this, QApplication::applicationName(), error );
|
||||
} else {
|
||||
QApplication::restoreOverrideCursor();
|
||||
QDialog::accept();
|
||||
// Rename table if necessary
|
||||
if(ui->editTableName->text() != curTable)
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor ); // this might take time
|
||||
modified = true;
|
||||
QString newName = ui->editTableName->text();
|
||||
QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(curTable, newName);
|
||||
if (!pdb->executeSQL(sql)){
|
||||
QApplication::restoreOverrideCursor();
|
||||
QString error("Error renaming table. Message from database engine:\n");
|
||||
error.append(pdb->lastErrorMessage).append("\n\n").append(sql);
|
||||
QMessageBox::warning( this, QApplication::applicationName(), error );
|
||||
} else {
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void editTableForm::checkInput()
|
||||
@@ -97,14 +100,14 @@ void editTableForm::editField()
|
||||
QTreeWidgetItem *item = ui->treeWidget->currentItem();
|
||||
editFieldForm * fieldForm = new editFieldForm( this );
|
||||
fieldForm->setModal(true);
|
||||
fieldForm->setInitialValues(false, curTable, item->text(0), item->text(1));
|
||||
fieldForm->setInitialValues(pdb, false, curTable, item->text(0), item->text(1));
|
||||
if (fieldForm->exec())
|
||||
{
|
||||
modified = true;
|
||||
//do the sql rename here
|
||||
//qDebug(fieldForm->name + fieldForm->type);
|
||||
item->setText(0,fieldForm->field_name);
|
||||
item->setText(1,fieldForm->field_name);
|
||||
item->setText(1,fieldForm->field_type);
|
||||
}
|
||||
//not until nested transaction are supported
|
||||
//if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))) goto rollback;
|
||||
@@ -205,7 +208,7 @@ void editTableForm::addField()
|
||||
{
|
||||
editFieldForm * addForm = new editFieldForm( this );
|
||||
addForm->setModal(true);
|
||||
addForm->setInitialValues(true, curTable, QString(""),QString(""));
|
||||
addForm->setInitialValues(pdb, true, curTable, QString(""),QString(""));
|
||||
if (addForm->exec())
|
||||
{
|
||||
modified = true;
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public slots:
|
||||
protected:
|
||||
QStringList types;
|
||||
QStringList fields;
|
||||
DBBrowserDB * pdb;
|
||||
DBBrowserDB *pdb;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
+3
-5
@@ -642,7 +642,7 @@ void MainWindow::createTable()
|
||||
QMessageBox::information( this, QApplication::applicationName(), "There is no database opened. Please open or create a new database file." );
|
||||
return;
|
||||
}
|
||||
createTableForm * tableForm = new createTableForm( this );
|
||||
createTableForm * tableForm = new createTableForm(&db, this);
|
||||
tableForm->setModal(true);
|
||||
if ( tableForm->exec() ) {
|
||||
if (!db.executeSQL(tableForm->createStatement)){
|
||||
@@ -1319,8 +1319,7 @@ void MainWindow::on_add_field(){
|
||||
//QTreeWidgetItem *item = dbTreeWidget->currentItem();
|
||||
editFieldForm *fieldForm = new editFieldForm( this );
|
||||
//qDebug(item->text(2));
|
||||
fieldForm->setInitialValues(true, ui->dbTreeWidget->currentItem()->text(0), "", "TEXT");
|
||||
fieldForm->setDB(this->db);
|
||||
fieldForm->setInitialValues(&db, true, ui->dbTreeWidget->currentItem()->text(0), "", "TEXT");
|
||||
if (fieldForm->exec())
|
||||
{
|
||||
//modified = true;
|
||||
@@ -1345,8 +1344,7 @@ void MainWindow::on_edit_field(){
|
||||
QTreeWidgetItem *item = ui->dbTreeWidget->currentItem();
|
||||
editFieldForm *fieldForm = new editFieldForm( this );
|
||||
qDebug(item->text(2).toUtf8());
|
||||
fieldForm->setInitialValues(false, "TABLE_NAME", item->text(0), item->text(2));
|
||||
fieldForm->setDB(this->db);
|
||||
fieldForm->setInitialValues(&db, false, "TABLE_NAME", item->text(0), item->text(2));
|
||||
if (fieldForm->exec())
|
||||
{
|
||||
//modified = true;
|
||||
|
||||
Reference in New Issue
Block a user