Fix foreign key check after editing a table

After editing a table we perform a foreign key check to see if the
modifications caused any problems. This check doesn't seem to work
because it expected that in case of a problem the PRAGMA would fail.
This however isn't the case - it just doesn't return any results but it
doesn't fail. This commit fixes the check and only shows rolls back if
the PRAGMA returned any data.
This commit is contained in:
Martin Kleusberg
2018-08-28 21:17:14 +02:00
parent 406734a2c9
commit 049d4ba76f

View File

@@ -996,7 +996,7 @@ void MainWindow::editObject()
// If foreign_keys were enabled, we must commit or rollback the transaction so the foreign_keys pragma can be restored.
if (foreign_keys == "1") {
if (!db.executeSQL(QString("PRAGMA %1.foreign_key_check").arg(sqlb::escapeIdentifier(name.schema())))) {
if (!db.querySingeValueFromDb(QString("PRAGMA %1.foreign_key_check").arg(sqlb::escapeIdentifier(name.schema()))).isNull()) {
QMessageBox::warning(this, QApplication::applicationName(),
tr("Error checking foreign keys after table modification. The changes will be reverted.\n"
"Message from database engine:\n%1").arg(db.lastError()));