Fix possible crashes when loading outdated project file

Fix a couple of possible crashed when loading a project file which does
not match the database schema anymore.

See issue #2232.
This commit is contained in:
Martin Kleusberg
2020-05-06 15:11:05 +02:00
parent 112e008935
commit 31ded8a8d9
2 changed files with 10 additions and 1 deletions

View File

@@ -785,7 +785,10 @@ void TableBrowser::applySettings(const BrowseDataTableSettings& storedData, bool
// Column widths
for(auto widthIt=storedData.columnWidths.constBegin();widthIt!=storedData.columnWidths.constEnd();++widthIt)
ui->dataTable->setColumnWidth(widthIt.key(), widthIt.value());
{
if(widthIt.key() < ui->dataTable->model()->columnCount())
ui->dataTable->setColumnWidth(widthIt.key(), widthIt.value());
}
m_columnsResized = true;
// Filters
@@ -963,6 +966,9 @@ void TableBrowser::hideColumns(int column, bool hide)
// (Un)hide requested column(s)
for(int col : columns)
{
if(col >= ui->dataTable->model()->columnCount())
continue;
ui->dataTable->setColumnHidden(col, hide);
if(!hide)
ui->dataTable->setColumnWidth(col, ui->dataTable->horizontalHeader()->defaultSectionSize());

View File

@@ -25,6 +25,9 @@ std::string Query::buildWherePart() const
{
for(auto i=m_where.cbegin();i!=m_where.cend();++i)
{
if(i->first >= m_column_names.size())
continue;
const auto it = findSelectedColumnByName(m_column_names.at(i->first));
std::string column = sqlb::escapeIdentifier(m_column_names.at(i->first));
if(it != m_selected_columns.cend() && it->selector != column)