Row::ith_column() method removed

This commit is contained in:
2021-08-15 11:52:00 +02:00
parent 869e5881df
commit b37b0b55ff
5 changed files with 60 additions and 61 deletions

48
row.cpp
View File

@@ -4,35 +4,35 @@
namespace usql {
int ColNullValue::compare(ColValue *other) {
return other->isNull() ? 0 : -1; // null goes to end
int ColNullValue::compare(ColValue &other) {
return other.isNull() ? 0 : -1; // null goes to end
}
int ColIntegerValue::compare(ColValue *other) {
long r = m_integer - other->getIntValue();
return other->isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
int ColIntegerValue::compare(ColValue &other) {
long r = m_integer - other.getIntValue();
return other.isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
}
int ColDoubleValue::compare(ColValue *other) {
if (other->isNull()) return 1; // null goes to end
int ColDoubleValue::compare(ColValue &other) {
if (other.isNull()) return 1; // null goes to end
double c = m_double - other->getDoubleValue();
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
int ColStringValue::compare(ColValue &other) {
return other.isNull() ? 1 : m_string.compare(other.getStringValue()); // null goes to end
}
int ColDateValue::compare(ColValue *other) {
long r = m_date - other->getIntValue();
return other->isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
int ColDateValue::compare(ColValue &other) {
long r = m_date - other.getIntValue();
return other.isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
}
int ColBooleanValue::compare(ColValue *other) {
if (other->isNull()) return 1; // null goes to end
int ColBooleanValue::compare(ColValue &other) {
if (other.isNull()) return 1; // null goes to end
return m_bool == other->getBoolValue() ? 0 : m_bool && !other->getBoolValue() ? -1 : 1; // true first
return m_bool == other.getBoolValue() ? 0 : m_bool && !other.getBoolValue() ? -1 : 1; // true first
}
Row::Row(int cols_count) {
@@ -120,18 +120,18 @@ void Row::setBoolColumnValue(int col_index, const std::string &value) {
m_columns[col_index] = std::make_unique<ColBooleanValue>(v);
}
void Row::setColumnValue(ColDefNode *col_def, ColValue *col_value) {
if (!col_value->isNull()) {
void Row::setColumnValue(ColDefNode *col_def, ColValue &col_value) {
if (!col_value.isNull()) {
if (col_def->type == ColumnType::integer_type)
setIntColumnValue(col_def->order, col_value->getIntValue());
setIntColumnValue(col_def->order, col_value.getIntValue());
else if (col_def->type == ColumnType::float_type)
setFloatColumnValue(col_def->order, col_value->getDoubleValue());
setFloatColumnValue(col_def->order, col_value.getDoubleValue());
else if (col_def->type == ColumnType::varchar_type)
setStringColumnValue(col_def->order, col_value->getStringValue());
setStringColumnValue(col_def->order, col_value.getStringValue());
else if (col_def->type == ColumnType::date_type)
setDateColumnValue(col_def->order, col_value->getDateValue());
setDateColumnValue(col_def->order, col_value.getDateValue());
else if (col_def->type == ColumnType::bool_type)
setBoolColumnValue(col_def->order, col_value->getBoolValue());
setBoolColumnValue(col_def->order, col_value.getBoolValue());
} else {
setColumnNull(col_def->order);
}
@@ -158,7 +158,7 @@ void Row::setColumnValue(ColDefNode *col_def, ValueNode *col_value) {
int Row::compare(const Row &other) const {
for (int ci = 0; ci < m_columns.size(); ci++) {
int cmp = m_columns[ci]->compare(other.ith_column(ci));
int cmp = m_columns[ci]->compare(other[ci]);
if (cmp != 0) return cmp;
}
return 0;