usql update
usql is still very primitive..it just barely works
This commit is contained in:
44
usql/row.cpp
44
usql/row.cpp
@@ -19,13 +19,13 @@ namespace usql {
|
||||
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
if (ColIntegerValue *other_v = dynamic_cast<ColIntegerValue *>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->integerValue());
|
||||
setColumnValue(i, other_v->getIntValue());
|
||||
}
|
||||
if (ColFloatValue *other_v = dynamic_cast<ColFloatValue *>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->floatValue());
|
||||
if (ColDoubleValue *other_v = dynamic_cast<ColDoubleValue *>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->getDoubleValue());
|
||||
}
|
||||
if (ColStringValue *other_v = dynamic_cast<ColStringValue *>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->stringValue());
|
||||
setColumnValue(i, other_v->getStringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,22 +35,52 @@ namespace usql {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, int value) {
|
||||
void Row::setColumnNull(int col_index) {
|
||||
m_columns[col_index] = std::make_unique<ColNullValue>();
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, long value) {
|
||||
m_columns[col_index] = std::make_unique<ColIntegerValue>(value);
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, double value) {
|
||||
m_columns[col_index] = std::make_unique<ColFloatValue>(value);
|
||||
m_columns[col_index] = std::make_unique<ColDoubleValue>(value);
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, const std::string &value) {
|
||||
m_columns[col_index] = std::make_unique<ColStringValue>(value);
|
||||
};
|
||||
|
||||
void Row::setColumnValue(ColDefNode *col_def, ColValue *col_value) {
|
||||
if (!col_value->isNull()) {
|
||||
if (col_def->type == ColumnType::integer_type)
|
||||
setColumnValue(col_def->order, col_value->getIntValue());
|
||||
else if (col_def->type == ColumnType::float_type)
|
||||
setColumnValue(col_def->order, col_value->getDoubleValue());
|
||||
else if (col_def->type == ColumnType::varchar_type)
|
||||
setColumnValue(col_def->order, col_value->getStringValue());
|
||||
} else {
|
||||
setColumnNull(col_def->order);
|
||||
}
|
||||
}
|
||||
|
||||
void Row::setColumnValue(ColDefNode *col_def, ValueNode *col_value) {
|
||||
if (!col_value->isNull()) {
|
||||
if (col_def->type == ColumnType::integer_type)
|
||||
setColumnValue(col_def->order, col_value->getIntValue());
|
||||
else if (col_def->type == ColumnType::float_type)
|
||||
setColumnValue(col_def->order, col_value->getDoubleValue());
|
||||
else if (col_def->type == ColumnType::varchar_type)
|
||||
setColumnValue(col_def->order, col_value->getStringValue());
|
||||
} else {
|
||||
setColumnNull(col_def->order);
|
||||
}
|
||||
}
|
||||
|
||||
void Row::print() {
|
||||
for (int ci = 0; ci < m_columns.size(); ci++) {
|
||||
if (ci > 0) std::cout << ",";
|
||||
auto v = m_columns[ci]->stringValue();
|
||||
auto v = m_columns[ci]->getStringValue();
|
||||
std::cout << v;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user