some TODOs removed..
This commit is contained in:
51
row.cpp
51
row.cpp
@@ -8,7 +8,8 @@ namespace usql {
|
||||
}
|
||||
|
||||
int ColIntegerValue::compare(ColValue * other) {
|
||||
return other->isNull() ? 1 : m_integer - other->getIntValue(); // TODO implicit conversion from long to int
|
||||
long r = m_integer - other->getIntValue();
|
||||
return other->isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
int ColDoubleValue::compare(ColValue * other) {
|
||||
@@ -23,7 +24,8 @@ namespace usql {
|
||||
}
|
||||
|
||||
int ColDateValue::compare(ColValue * other) {
|
||||
return other->isNull() ? 1 : m_date - other->getIntValue(); // TODO implicit conversion from long to int
|
||||
long r = m_date - other->getIntValue();
|
||||
return other->isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
int ColBooleanValue::compare(ColValue * other) {
|
||||
@@ -41,28 +43,35 @@ namespace usql {
|
||||
|
||||
Row::Row(const Row &other) {
|
||||
m_columns.reserve(other.m_columns.size());
|
||||
// TODO fixme, here first set cols null and then immediately replace it
|
||||
// PERF here we first set cols null and then immediately replace it
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
m_columns.push_back(std::make_unique<ColNullValue>());
|
||||
m_columns.emplace_back(std::make_unique<ColNullValue>());
|
||||
}
|
||||
|
||||
// TODO get rid of dynamic_cast
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
if (auto *other_v = dynamic_cast<ColIntegerValue *>(other.m_columns[i].get())) {
|
||||
setIntColumnValue(i, other_v->getIntValue());
|
||||
} else if (auto *other_v = dynamic_cast<ColDoubleValue *>(other.m_columns[i].get())) {
|
||||
setFloatColumnValue(i, other_v->getDoubleValue());
|
||||
} else if (auto *other_v = dynamic_cast<ColStringValue *>(other.m_columns[i].get())) {
|
||||
setStringColumnValue(i, other_v->getStringValue());
|
||||
} else if (auto *other_v = dynamic_cast<ColDateValue *>(other.m_columns[i].get())) {
|
||||
setDateColumnValue(i, other_v->getDateValue());
|
||||
} else if (auto *other_v = dynamic_cast<ColBooleanValue *>(other.m_columns[i].get())) {
|
||||
setBoolColumnValue(i, other_v->getBoolValue());
|
||||
} else if (auto *other_v = dynamic_cast<ColNullValue *>(other.m_columns[i].get())) {
|
||||
// NOP
|
||||
} else {
|
||||
throw Exception("unsupported data type");
|
||||
}
|
||||
if (other.m_columns[i]->isNull())
|
||||
continue; // for null NOP
|
||||
|
||||
ColumnType col_type = other.m_columns[i]->getColType();
|
||||
switch (col_type) {
|
||||
case ColumnType::integer_type :
|
||||
setIntColumnValue(i, (static_cast<ColIntegerValue *>(other.m_columns[i].get())->getIntValue()));
|
||||
break;
|
||||
case ColumnType::float_type :
|
||||
setFloatColumnValue(i, (static_cast<ColDoubleValue *>(other.m_columns[i].get())->getDoubleValue()));
|
||||
break;
|
||||
case ColumnType::varchar_type :
|
||||
setStringColumnValue(i, (static_cast<ColStringValue *>(other.m_columns[i].get())->getStringValue()));
|
||||
break;
|
||||
case ColumnType::date_type :
|
||||
setDateColumnValue(i, (static_cast<ColDateValue *>(other.m_columns[i].get())->getDateValue()));
|
||||
break;
|
||||
case ColumnType::bool_type :
|
||||
setBoolColumnValue(i, (static_cast<ColBooleanValue *>(other.m_columns[i].get())->getBoolValue()));
|
||||
break;
|
||||
default:
|
||||
throw Exception("unsupported column type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +164,7 @@ void Row::setColumnValue(ColDefNode *col_def, ValueNode *col_value) {
|
||||
for (int ci = 0; ci < m_columns.size(); ci++) {
|
||||
auto value = m_columns[ci]->getStringValue();
|
||||
|
||||
// TODO use string functions handle len
|
||||
// TODO use rpad string function handle len
|
||||
out.append(value + std::string(col_char_sizes[ci] - value.size(), ' ') + " | ");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user