Skip to content

Commit 61e13ae

Browse files
committed
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.
1 parent db17cd9 commit 61e13ae

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/sql/Query.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ std::string Query::buildQuery(bool withRowid) const
6666

6767
// Sorting
6868
std::string order_by;
69-
if(m_sort.size())
69+
for(const auto& sorted_column : m_sort)
7070
{
71-
order_by = "ORDER BY ";
72-
for(const auto& sorted_column : m_sort)
71+
if(sorted_column.column < m_column_names.size())
7372
order_by += sqlb::escapeIdentifier(m_column_names.at(sorted_column.column)) + " "
7473
+ (sorted_column.direction == sqlb::Ascending ? "ASC" : "DESC") + ",";
74+
}
75+
if(order_by.size())
76+
{
7577
order_by.pop_back();
78+
order_by = "ORDER BY " + order_by;
7679
}
7780

7881
return "SELECT " + selector + " FROM " + m_table.toString().toStdString() + " " + where + " " + order_by;

0 commit comments

Comments
 (0)