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.
This commit is contained in:
Martin Kleusberg
2018-01-15 22:38:10 +01:00
parent dbbd268fa2
commit 39a5460500
2 changed files with 14 additions and 3 deletions

View File

@@ -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<sqlb::Table>()->fieldInformation();
sqlb::TablePtr table = pdb.getObjectByName(sqlb::ObjectIdentifier(ui->comboTableName->currentData())).dynamicCast<sqlb::Table>();
if(!table)
return;
sqlb::FieldInfoList tableFields = table->fieldInformation();
ui->tableTableColumns->setRowCount(tableFields.size());
int tableRows = 0;
for(int i=0;i<tableFields.size();++i)
@@ -236,6 +239,10 @@ void EditIndexDialog::checkInput()
if(ui->editIndexName->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;

View File

@@ -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