usql update
This commit is contained in:
181
usql/row.h
181
usql/row.h
@@ -9,135 +9,136 @@
|
||||
|
||||
namespace usql {
|
||||
|
||||
struct ColValue {
|
||||
virtual bool isNull() { return false; };
|
||||
virtual ColumnType getColType() = 0;
|
||||
virtual long getIntValue() = 0;
|
||||
virtual double getDoubleValue() = 0;
|
||||
virtual std::string getStringValue() = 0;
|
||||
virtual long getDateValue() = 0;
|
||||
virtual bool getBoolValue() = 0;
|
||||
struct ColValue {
|
||||
virtual bool isNull() const { return false; };
|
||||
virtual ColumnType getColType() const = 0;
|
||||
virtual long getIntegerValue() const = 0;
|
||||
virtual double getDoubleValue() const = 0;
|
||||
virtual std::string getStringValue() const = 0;
|
||||
virtual std::string getCsvStringValue() const { return getStringValue(); };
|
||||
virtual long getDateValue() const = 0;
|
||||
virtual bool getBoolValue() const = 0;
|
||||
|
||||
virtual int compare(ColValue &other) = 0;
|
||||
virtual int compare(ColValue &other) const = 0;
|
||||
|
||||
virtual ~ColValue() = default;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct ColNullValue : ColValue {
|
||||
bool isNull() override { return true; };
|
||||
ColumnType getColType() override { throw Exception("getColType not supported on ColNullValue"); }
|
||||
long getIntValue() override { throw Exception("getIntValue not supported on ColNullValue"); };
|
||||
double getDoubleValue() override { throw Exception("getDoubleValue not supported on ColNullValue"); };
|
||||
std::string getStringValue() override { return "null"; };
|
||||
long getDateValue() override { throw Exception("getDateValue not supported on ColNullValue"); };
|
||||
bool getBoolValue() override { throw Exception("getDateValue not supported on ColNullValue"); };
|
||||
struct ColNullValue : ColValue {
|
||||
bool isNull() const override { return true; };
|
||||
ColumnType getColType() const override { throw Exception("getColType not supported on ColNullValue"); }
|
||||
long getIntegerValue() const override { throw Exception("getIntegerValue not supported on ColNullValue"); };
|
||||
double getDoubleValue() const override { throw Exception("getDoubleValue not supported on ColNullValue"); };
|
||||
std::string getStringValue() const override { return "null"; };
|
||||
long getDateValue() const override { throw Exception("getDateValue not supported on ColNullValue"); };
|
||||
bool getBoolValue() const override { throw Exception("getDateValue not supported on ColNullValue"); };
|
||||
|
||||
int compare(ColValue &other) override;
|
||||
int compare(ColValue &other) const override;
|
||||
|
||||
virtual ~ColNullValue() = default;
|
||||
};
|
||||
~ColNullValue() override = default;
|
||||
};
|
||||
|
||||
|
||||
struct ColIntegerValue : ColValue {
|
||||
struct ColIntegerValue : ColValue {
|
||||
explicit ColIntegerValue(long value) : m_integer(value) {};
|
||||
ColIntegerValue(const ColIntegerValue &other) : m_integer(other.m_integer) {};
|
||||
|
||||
ColumnType getColType() override { return ColumnType::integer_type; };
|
||||
long getIntValue() override { return m_integer; };
|
||||
double getDoubleValue() override { return (double) m_integer; };
|
||||
std::string getStringValue() override { return std::to_string(m_integer); };
|
||||
long getDateValue() override { return m_integer; };
|
||||
bool getBoolValue() override { throw Exception("Not supported on ColIntegerValue"); };
|
||||
ColumnType getColType() const override { return ColumnType::integer_type; };
|
||||
long getIntegerValue() const override { return m_integer; };
|
||||
double getDoubleValue() const override { return (double) m_integer; };
|
||||
std::string getStringValue() const override { return std::to_string(m_integer); };
|
||||
long getDateValue() const override { return m_integer; };
|
||||
bool getBoolValue() const override { throw Exception("Not supported on ColIntegerValue"); };
|
||||
|
||||
int compare(ColValue &other) override;
|
||||
int compare(ColValue &other) const override;
|
||||
|
||||
~ColIntegerValue() override = default;
|
||||
|
||||
long m_integer;
|
||||
|
||||
virtual ~ColIntegerValue() = default;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct ColDoubleValue : ColValue {
|
||||
struct ColDoubleValue : ColValue {
|
||||
explicit ColDoubleValue(double value) : m_double(value) {};
|
||||
ColDoubleValue(const ColDoubleValue &other) : m_double(other.m_double) {}
|
||||
|
||||
ColumnType getColType() override { return ColumnType::float_type; };
|
||||
long getIntValue() override { return (long) m_double; };
|
||||
double getDoubleValue() override { return m_double; };
|
||||
std::string getStringValue() override { return Settings::double_to_string(m_double); };
|
||||
long getDateValue() override { return (long) m_double; };
|
||||
bool getBoolValue() override { throw Exception("Not supported on ColDoubleValue"); };
|
||||
ColumnType getColType() const override { return ColumnType::float_type; };
|
||||
long getIntegerValue() const override { return (long) m_double; };
|
||||
double getDoubleValue() const override { return m_double; };
|
||||
std::string getStringValue() const override { return Settings::double_to_string(m_double); };
|
||||
long getDateValue() const override { return (long) m_double; };
|
||||
bool getBoolValue() const override { throw Exception("Not supported on ColDoubleValue"); };
|
||||
|
||||
int compare(ColValue &other) override;
|
||||
int compare(ColValue &other) const override;
|
||||
|
||||
virtual ~ColDoubleValue() = default;
|
||||
~ColDoubleValue() override = default;
|
||||
|
||||
double m_double;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct ColStringValue : ColValue {
|
||||
struct ColStringValue : ColValue {
|
||||
explicit ColStringValue(const std::string &value) : m_string(std::make_unique<std::string>(value)) {};
|
||||
ColStringValue(const ColStringValue &other) : m_string(std::make_unique<std::string>(*other.m_string)) {};
|
||||
|
||||
ColStringValue & operator=(ColStringValue other);
|
||||
|
||||
ColumnType getColType() override { return ColumnType::varchar_type; };
|
||||
long getIntValue() override { return std::stoi(*m_string); };
|
||||
double getDoubleValue() override { return std::stod(*m_string); };
|
||||
std::string getStringValue() override { return *m_string; };
|
||||
long getDateValue() override { return std::stoi(*m_string); };
|
||||
bool getBoolValue() override { throw Exception("Not supported on ColStringValue"); };
|
||||
ColumnType getColType() const override { return ColumnType::varchar_type; };
|
||||
long getIntegerValue() const override { return std::stoi(*m_string); };
|
||||
double getDoubleValue() const override { return std::stod(*m_string); };
|
||||
std::string getStringValue() const override { return *m_string; };
|
||||
std::string getCsvStringValue() const override;;
|
||||
long getDateValue() const override { return std::stoi(*m_string); };
|
||||
bool getBoolValue() const override { throw Exception("Not supported on ColStringValue"); };
|
||||
|
||||
int compare(ColValue &other) override;
|
||||
int compare(ColValue &other) const override;
|
||||
|
||||
std::unique_ptr<std::string> m_string;
|
||||
};
|
||||
};
|
||||
|
||||
struct ColDateValue : ColValue {
|
||||
explicit ColDateValue(long value) : m_date(value) {};
|
||||
ColDateValue(const ColDateValue &other) : m_date(other.m_date) {};
|
||||
struct ColDateValue : ColValue {
|
||||
explicit ColDateValue(long value) : m_date(value) {};
|
||||
ColDateValue(const ColDateValue &other) : m_date(other.m_date) {};
|
||||
|
||||
ColumnType getColType() override { return ColumnType::date_type; };
|
||||
long getIntValue() override { return m_date; };
|
||||
double getDoubleValue() override { return (double) m_date; };
|
||||
std::string getStringValue() override { return Settings::date_to_string(m_date); };
|
||||
long getDateValue() override { return m_date; };
|
||||
bool getBoolValue() override { throw Exception("Not supported on ColDateValue"); };
|
||||
ColumnType getColType() const override { return ColumnType::date_type; };
|
||||
long getIntegerValue() const override { return m_date; };
|
||||
double getDoubleValue() const override { return (double) m_date; };
|
||||
std::string getStringValue() const override { return Settings::date_to_string(m_date); };
|
||||
long getDateValue() const override { return m_date; };
|
||||
bool getBoolValue() const override { throw Exception("Not supported on ColDateValue"); };
|
||||
|
||||
int compare(ColValue &other) override;
|
||||
int compare(ColValue &other) const override;
|
||||
|
||||
virtual ~ColDateValue() = default;
|
||||
~ColDateValue() override = default;
|
||||
|
||||
long m_date; // seconds since epoch for now
|
||||
};
|
||||
long m_date; // seconds since epoch for now
|
||||
};
|
||||
|
||||
struct ColBooleanValue : ColValue {
|
||||
explicit ColBooleanValue(bool value) : m_bool(value) {};
|
||||
ColBooleanValue(const ColBooleanValue &other) : m_bool(other.m_bool) {};
|
||||
struct ColBooleanValue : ColValue {
|
||||
explicit ColBooleanValue(bool value) : m_bool(value) {};
|
||||
ColBooleanValue(const ColBooleanValue &other) : m_bool(other.m_bool) {};
|
||||
|
||||
ColumnType getColType() override { return ColumnType::bool_type; };
|
||||
long getIntValue() override { return (long) m_bool; };
|
||||
double getDoubleValue() override { return (double) m_bool; };
|
||||
std::string getStringValue() override { return m_bool ? "Y" : "N"; };
|
||||
long getDateValue() override { throw Exception("Not supported on ColBooleanValue"); };
|
||||
bool getBoolValue() override { return m_bool; };
|
||||
ColumnType getColType() const override { return ColumnType::bool_type; };
|
||||
long getIntegerValue() const override { return (long) m_bool; };
|
||||
double getDoubleValue() const override { return (double) m_bool; };
|
||||
std::string getStringValue() const override { return m_bool ? "Y" : "N"; };
|
||||
long getDateValue() const override { throw Exception("Not supported on ColBooleanValue"); };
|
||||
bool getBoolValue() const override { return m_bool; };
|
||||
|
||||
int compare(ColValue &other) override;
|
||||
int compare(ColValue &other) const override;
|
||||
|
||||
virtual ~ColBooleanValue() = default;
|
||||
~ColBooleanValue() override = default;
|
||||
|
||||
bool m_bool;
|
||||
};
|
||||
bool m_bool;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Row {
|
||||
class Row {
|
||||
|
||||
public:
|
||||
explicit Row(int cols_count) : m_columns(cols_count) {};
|
||||
public:
|
||||
explicit Row(int cols_count, bool visible) : m_columns(cols_count), m_visible(visible) {};
|
||||
Row(const Row &other);
|
||||
|
||||
Row &operator=(Row other);
|
||||
@@ -154,7 +155,7 @@ namespace usql {
|
||||
void setColumnValue(ColDefNode *col_def, ColValue &col_value);
|
||||
void setColumnValue(ColDefNode *col_def, ValueNode *col_value);
|
||||
|
||||
ColValue &operator[](int i) const {
|
||||
ColValue &operator[](int i) const {
|
||||
auto type_index = m_columns[i].index();
|
||||
switch (type_index) {
|
||||
case 0:
|
||||
@@ -169,17 +170,23 @@ namespace usql {
|
||||
return (ColValue &) *std::get_if<ColDateValue>(&m_columns[i]);
|
||||
case 5:
|
||||
return (ColValue &) *std::get_if<ColBooleanValue>(&m_columns[i]);
|
||||
default:
|
||||
throw Exception("should not happen");
|
||||
}
|
||||
throw Exception("should not happen");
|
||||
}
|
||||
|
||||
int compare(const Row &other) const;
|
||||
[[nodiscard]] int compare(const Row &other) const;
|
||||
|
||||
void print(const std::vector<ColDefNode> &col_defs);
|
||||
static int print_get_column_size(const ColDefNode &col_def);
|
||||
private:
|
||||
// xx std::vector<std::unique_ptr<ColValue>> m_columns;
|
||||
|
||||
[[nodiscard]] bool is_visible() const { return m_visible; };
|
||||
void set_visible() { m_visible = true; };
|
||||
void set_deleted() { m_visible = true; };
|
||||
|
||||
private:
|
||||
bool m_visible;
|
||||
std::vector<std::variant<ColNullValue, ColIntegerValue, ColDoubleValue, ColStringValue, ColDateValue, ColBooleanValue>> m_columns;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user