order by refactoring

This commit is contained in:
2021-08-01 11:30:56 +02:00
parent 70c036f08c
commit 4a344d0e77
4 changed files with 51 additions and 37 deletions

20
row.cpp
View File

@@ -3,6 +3,26 @@
namespace usql {
int ColNullValue::compare(ColValue * other) {
return other->isNull() ? 0 : -1; // null goes to end
}
int ColIntegerValue::compare(ColValue * other) {
return other->isNull() ? 1 : m_integer - other->getIntValue(); // null goes to end
}
int ColDoubleValue::compare(ColValue * other) {
if (other->isNull()) { // null goes to end
return 1;
}
double c = m_double - other->getDoubleValue();
return c < 0 ? -1 : c == 0.0 ? 0 : 1;
}
int ColStringValue::compare(ColValue * other) {
return other->isNull() ? 1 : m_string.compare(other->getStringValue()); // null goes to end
}
Row::Row(int cols_count) {
m_columns.reserve(cols_count);
for (int i = 0; i < cols_count; i++) {