Skip to content

Commit 7f03e01

Browse files
committed
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.
1 parent a1b72c5 commit 7f03e01

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/ImportCsvDialog.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QMessageBox>
44
#include <QProgressDialog>
55
#include <QPushButton>
6+
#include <QDateTime>
67
#include "sqlitedb.h"
78

89
ImportCsvDialog::ImportCsvDialog(const QString& filename, DBBrowserDB* db, QWidget* parent)
@@ -23,13 +24,13 @@ ImportCsvDialog::~ImportCsvDialog()
2324
}
2425

2526
namespace {
26-
void rollback(ImportCsvDialog* dialog, DBBrowserDB* pdb, QProgressDialog& progress)
27+
void rollback(ImportCsvDialog* dialog, DBBrowserDB* pdb, QProgressDialog& progress, const QString& savepointName)
2728
{
2829
progress.hide();
2930
QApplication::restoreOverrideCursor(); // restore original cursor
3031
QString error = QObject::tr("Error importing data. Message from database engine: %1").arg(pdb->lastErrorMessage);
3132
QMessageBox::warning(dialog, QApplication::applicationName(), error);
32-
pdb->executeSQL("ROLLBACK TO SAVEPOINT CSVIMPORT;", false);
33+
pdb->revert(savepointName);
3334
}
3435
}
3536

@@ -106,14 +107,15 @@ void ImportCsvDialog::accept()
106107

107108
// Create a savepoint, so we can rollback in case of any errors during importing
108109
// db needs to be saved or an error will occur
109-
if(!pdb->executeSQL("SAVEPOINT CSVIMPORT;", false))
110-
return rollback(this, pdb, progress);
110+
QString restorepointName = QString("CSVIMPORT_%1").arg(QDateTime::currentMSecsSinceEpoch());
111+
if(!pdb->setRestorePoint(restorepointName))
112+
return rollback(this, pdb, progress, restorepointName);
111113

112114
// Create table
113115
if(!importToExistingTable)
114116
{
115117
if(!pdb->createTable(ui->editName->text(), fieldList))
116-
return rollback(this, pdb, progress);
118+
return rollback(this, pdb, progress, restorepointName);
117119
}
118120

119121
// now lets import all data, one row at a time
@@ -136,17 +138,13 @@ void ImportCsvDialog::accept()
136138
colNum = 0;
137139
sql.append(");");
138140
if(!pdb->executeSQL(sql, false, false))
139-
return rollback(this, pdb, progress);
141+
return rollback(this, pdb, progress, restorepointName);
140142
}
141143
progress.setValue(i);
142144
if(progress.wasCanceled())
143-
return rollback(this, pdb, progress);
145+
return rollback(this, pdb, progress, restorepointName);
144146
}
145147

146-
// Everything ok, release the savepoint
147-
if(!pdb->executeSQL("RELEASE SAVEPOINT CSVIMPORT;", false))
148-
return rollback(this, pdb, progress);
149-
150148
QApplication::restoreOverrideCursor(); // restore original cursor
151149
QDialog::accept();
152150
}

0 commit comments

Comments
 (0)