usql update

This commit is contained in:
2021-12-19 13:33:47 +01:00
parent 37d0d9b3f5
commit 5c925f2608
23 changed files with 1570 additions and 1124 deletions

View File

@@ -4,16 +4,16 @@
namespace usql {
int ColNullValue::compare(ColValue &other) {
int ColNullValue::compare(ColValue &other) const {
return other.isNull() ? 0 : -1; // null goes to end
}
int ColIntegerValue::compare(ColValue &other) {
long r = m_integer - other.getIntValue();
int ColIntegerValue::compare(ColValue &other) const {
long r = m_integer - other.getIntegerValue();
return other.isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
}
int ColDoubleValue::compare(ColValue &other) {
int ColDoubleValue::compare(ColValue &other) const {
if (other.isNull()) return 1; // null goes to end
double c = m_double - other.getDoubleValue();
@@ -25,22 +25,34 @@ ColStringValue & ColStringValue::operator=(ColStringValue other) {
return *this;
}
int ColStringValue::compare(ColValue &other) {
int ColStringValue::compare(ColValue &other) const {
return other.isNull() ? 1 : m_string->compare(other.getStringValue()); // null goes to end
}
int ColDateValue::compare(ColValue &other) {
long r = m_date - other.getIntValue();
std::string ColStringValue::getCsvStringValue() const {
auto src_str = getStringValue();
std::string toSearch{"\""}, replaceStr{"\\\""};
size_t pos = src_str.find(toSearch);
while(pos != std::string::npos) {
src_str.replace(pos, toSearch.size(), replaceStr);
pos =src_str.find(toSearch, pos + replaceStr.size());
}
return src_str;
}
int ColDateValue::compare(ColValue &other) const {
long r = m_date - other.getIntegerValue();
return other.isNull() ? 1 : r > 0 ? 1 : r == 0 ? 0 : -1;
}
int ColBooleanValue::compare(ColValue &other) {
int ColBooleanValue::compare(ColValue &other) const {
if (other.isNull()) return 1; // null goes to end
return m_bool == other.getBoolValue() ? 0 : m_bool && !other.getBoolValue() ? -1 : 1; // true first
}
Row::Row(const Row &other) : m_columns(other.m_columns.size()) {
Row::Row(const Row &other) : m_columns(other.m_columns.size()), m_visible(other.m_visible) {
for (int i = 0; i < other.m_columns.size(); i++) {
if (other[i].isNull())
continue; // for null NOP
@@ -48,7 +60,7 @@ Row::Row(const Row &other) : m_columns(other.m_columns.size()) {
ColumnType col_type = other[i].getColType();
switch (col_type) {
case ColumnType::integer_type :
setIntColumnValue(i, other[i].getIntValue());
setIntColumnValue(i, other[i].getIntegerValue());
break;
case ColumnType::float_type :
setFloatColumnValue(i, other[i].getDoubleValue());
@@ -110,7 +122,7 @@ void Row::setBoolColumnValue(int col_index, const std::string &value) {
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.getIntegerValue());
else if (col_def->type == ColumnType::float_type)
setFloatColumnValue(col_def->order, col_value.getDoubleValue());
else if (col_def->type == ColumnType::varchar_type)