mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-22 03:51:25 -06:00
Fix possible crash when sorted column does not exist anymore
When sorting a table or a view by a column, then removing enough columns from that table, that view, or the underlying table of the view so that the column index get out of bound, and then going back to browse that table the application crashes. This commit makes sure to ignore such columns which would cause a crash. See issue #1774.
This commit is contained in:
@@ -66,13 +66,16 @@ std::string Query::buildQuery(bool withRowid) const
|
||||
|
||||
// Sorting
|
||||
std::string order_by;
|
||||
if(m_sort.size())
|
||||
for(const auto& sorted_column : m_sort)
|
||||
{
|
||||
order_by = "ORDER BY ";
|
||||
for(const auto& sorted_column : m_sort)
|
||||
if(sorted_column.column < m_column_names.size())
|
||||
order_by += sqlb::escapeIdentifier(m_column_names.at(sorted_column.column)) + " "
|
||||
+ (sorted_column.direction == sqlb::Ascending ? "ASC" : "DESC") + ",";
|
||||
}
|
||||
if(order_by.size())
|
||||
{
|
||||
order_by.pop_back();
|
||||
order_by = "ORDER BY " + order_by;
|
||||
}
|
||||
|
||||
return "SELECT " + selector + " FROM " + m_table.toString().toStdString() + " " + where + " " + order_by;
|
||||
|
||||
Reference in New Issue
Block a user