From 39a54605004951f100619dd9d0096accff9dcd61 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Mon, 15 Jan 2018 22:38:10 +0100 Subject: [PATCH] Fix crashes in Edit Index dialog when database has no tables Fix some crashes in the Edit Index dialog which happen if you try to add a new index when there are no tables in the database yet. See issue #1293. --- src/EditIndexDialog.cpp | 9 ++++++++- src/sqlitetypes.h | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/EditIndexDialog.cpp b/src/EditIndexDialog.cpp index b3ea640d..3b7b0e98 100644 --- a/src/EditIndexDialog.cpp +++ b/src/EditIndexDialog.cpp @@ -112,7 +112,10 @@ void EditIndexDialog::tableChanged(const QString& new_table, bool initialLoad) void EditIndexDialog::updateColumnLists() { // Fill the table column list - sqlb::FieldInfoList tableFields = pdb.getObjectByName(sqlb::ObjectIdentifier(ui->comboTableName->currentData())).dynamicCast()->fieldInformation(); + sqlb::TablePtr table = pdb.getObjectByName(sqlb::ObjectIdentifier(ui->comboTableName->currentData())).dynamicCast(); + if(!table) + return; + sqlb::FieldInfoList tableFields = table->fieldInformation(); ui->tableTableColumns->setRowCount(tableFields.size()); int tableRows = 0; for(int i=0;ieditIndexName->text().isEmpty()) valid = false; + // Check if a table is selected (this is especially important in the case where there are no tables in the database yet). + if(ui->comboTableName->currentText().isNull()) + valid = false; + // Check if index has any columns if(index.columns().size() == 0) valid = false; diff --git a/src/sqlitetypes.h b/src/sqlitetypes.h index 632727c3..2e86b28f 100644 --- a/src/sqlitetypes.h +++ b/src/sqlitetypes.h @@ -40,8 +40,12 @@ public: explicit ObjectIdentifier(QVariant variant) { QStringList str = variant.toStringList(); - m_schema = str.first(); - m_name = str.last(); + if(str.size()) + { + m_schema = str.first(); + if(str.size() >= 2) + m_name = str.last(); + } } bool operator==(const ObjectIdentifier& rhs) const