From 7f03e01a86465f0fea8236e1e8e6830ac56d10c0 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Thu, 23 May 2013 18:04:27 +0200 Subject: [PATCH] ImportCsvDialog: Also use the new savepoint logic in this dialog Do just the same in the ImportCsvDialog as before in the EditTableDialog, i.e. using a unique savepoint name which is not released when the import was successfull. --- src/ImportCsvDialog.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ImportCsvDialog.cpp b/src/ImportCsvDialog.cpp index 2a3196f7..7ec6b4f6 100644 --- a/src/ImportCsvDialog.cpp +++ b/src/ImportCsvDialog.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "sqlitedb.h" ImportCsvDialog::ImportCsvDialog(const QString& filename, DBBrowserDB* db, QWidget* parent) @@ -23,13 +24,13 @@ ImportCsvDialog::~ImportCsvDialog() } namespace { -void rollback(ImportCsvDialog* dialog, DBBrowserDB* pdb, QProgressDialog& progress) +void rollback(ImportCsvDialog* dialog, DBBrowserDB* pdb, QProgressDialog& progress, const QString& savepointName) { progress.hide(); QApplication::restoreOverrideCursor(); // restore original cursor QString error = QObject::tr("Error importing data. Message from database engine: %1").arg(pdb->lastErrorMessage); QMessageBox::warning(dialog, QApplication::applicationName(), error); - pdb->executeSQL("ROLLBACK TO SAVEPOINT CSVIMPORT;", false); + pdb->revert(savepointName); } } @@ -106,14 +107,15 @@ void ImportCsvDialog::accept() // Create a savepoint, so we can rollback in case of any errors during importing // db needs to be saved or an error will occur - if(!pdb->executeSQL("SAVEPOINT CSVIMPORT;", false)) - return rollback(this, pdb, progress); + QString restorepointName = QString("CSVIMPORT_%1").arg(QDateTime::currentMSecsSinceEpoch()); + if(!pdb->setRestorePoint(restorepointName)) + return rollback(this, pdb, progress, restorepointName); // Create table if(!importToExistingTable) { if(!pdb->createTable(ui->editName->text(), fieldList)) - return rollback(this, pdb, progress); + return rollback(this, pdb, progress, restorepointName); } // now lets import all data, one row at a time @@ -136,17 +138,13 @@ void ImportCsvDialog::accept() colNum = 0; sql.append(");"); if(!pdb->executeSQL(sql, false, false)) - return rollback(this, pdb, progress); + return rollback(this, pdb, progress, restorepointName); } progress.setValue(i); if(progress.wasCanceled()) - return rollback(this, pdb, progress); + return rollback(this, pdb, progress, restorepointName); } - // Everything ok, release the savepoint - if(!pdb->executeSQL("RELEASE SAVEPOINT CSVIMPORT;", false)) - return rollback(this, pdb, progress); - QApplication::restoreOverrideCursor(); // restore original cursor QDialog::accept(); }