Skip to content

Commit b466cfa

Browse files
committed
Export: more error checks
- Error check in SQL export - Correct placement of `stream.status()` check in CSV export - Error check immediately after writing (additional to the one after closing) See issue #3243
1 parent a5a3d7f commit b466cfa

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/ExportDataDialog.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ bool ExportDataDialog::exportQueryCsv(const std::string& sQuery, const QString&
177177
if(counter % 1000 == 0)
178178
qApp->processEvents();
179179
counter++;
180+
writeError = stream.status() != QTextStream::Ok;
180181
}
181-
writeError = stream.status() != QTextStream::Ok;
182182
}
183183
sqlite3_finalize(stmt);
184184

@@ -283,14 +283,15 @@ bool ExportDataDialog::exportQueryJson(const std::string& sQuery, const QString&
283283

284284
// Create JSON document
285285
file.write(json_table.dump(ui->checkPrettyPrint->isChecked() ? 4 : -1).c_str());
286+
bool writeError = file.error() != QFileDevice::NoError;
286287

287288
QApplication::restoreOverrideCursor();
288289
qApp->processEvents();
289290

290291
// Done writing the file
291292
file.close();
292293

293-
if(file.error() != QFileDevice::NoError) {
294+
if(writeError || file.error() != QFileDevice::NoError) {
294295
QMessageBox::warning(this, QApplication::applicationName(),
295296
tr("Error while writing the file '%1': %2")
296297
.arg(sFilename, file.errorString()));
@@ -328,6 +329,8 @@ void ExportDataDialog::accept()
328329
break;
329330
}
330331

332+
bool success = true;
333+
331334
if(!m_sQuery.empty())
332335
{
333336
// called from sqlexecute query tab
@@ -342,7 +345,7 @@ void ExportDataDialog::accept()
342345
return;
343346
}
344347

345-
exportQuery(m_sQuery, sFilename);
348+
success = exportQuery(m_sQuery, sFilename);
346349
} else {
347350
// called from the File export menu
348351
const QList<QListWidgetItem*> selectedItems = ui->listTables->selectedItems();
@@ -395,7 +398,7 @@ void ExportDataDialog::accept()
395398
// if we are called from execute sql tab, query is already set
396399
// and we only export 1 select
397400
std::string sQuery = "SELECT * FROM " + sqlb::ObjectIdentifier(selectedItems.at(i)->data(Qt::UserRole).toString().toStdString()).toString() + ";";
398-
exportQuery(sQuery, filenames.at(i));
401+
success = exportQuery(sQuery, filenames.at(i)) && success;
399402
}
400403
}
401404

@@ -407,7 +410,11 @@ void ExportDataDialog::accept()
407410
Settings::setValue("exportcsv", "newlinecharacters", currentNewLineString());
408411

409412
// Notify the user the export has completed
410-
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));
413+
if(success) {
414+
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));
415+
} else {
416+
QMessageBox::warning(this, QApplication::applicationName(), tr("Export finished with errors."));
417+
}
411418
QDialog::accept();
412419
}
413420

src/sqlitedb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ bool DBBrowserDB::dump(const QString& filePath,
10451045

10461046
QApplication::restoreOverrideCursor();
10471047
qApp->processEvents();
1048-
return true;
1048+
return stream.status() == QTextStream::Ok && file.error() == QFileDevice::NoError;
10491049
}
10501050
return false;
10511051
}

0 commit comments

Comments
 (0)