fixed field class and all tests

This commit is contained in:
2024-03-19 19:49:17 +01:00
parent 12919ba372
commit b15b8da31f
9 changed files with 43 additions and 99 deletions
+2 -2
View File
@@ -46,7 +46,7 @@ public:
column_definition(std::string name, data_type_t type, size_t index, std::string ref_table, std::string ref_column, utils::field_attributes attr, null_option null_opt);
[[nodiscard]] const std::string& name() const;
[[nodiscard]] size_t index() const;
[[nodiscard]] int index() const;
[[nodiscard]] const utils::field_attributes& attributes() const;
[[nodiscard]] bool is_nullable() const;
[[nodiscard]] data_type_t type() const;
@@ -111,7 +111,7 @@ private:
static const data_type_index data_type_index_;
std::string name_;
size_t index_{};
int index_{-1};
utils::field_attributes attributes_;
null_option null_option_{null_option::NOT_NULL};
data_type_t type_{data_type_t::type_unknown};
+6 -54
View File
@@ -12,54 +12,6 @@
namespace matador::sql {
enum class field_type {
Integer,
FloatingPoint,
String,
Boolean,
Blob,
Null
};
template < typename Type, typename Enable = void >
struct field_traits;
template<typename Type>
struct field_traits<Type, typename std::enable_if<std::is_integral<Type>::value && !std::is_same<Type, bool>::value>::type>
{
static field_type type() { return field_type::Integer; }
};
template<typename Type>
struct field_traits<Type, typename std::enable_if<std::is_floating_point<Type>::value>::type>
{
static field_type type() { return field_type::FloatingPoint; }
};
template<typename Type>
struct field_traits<Type, typename std::enable_if<std::is_same<Type, std::string>::value>::type>
{
static field_type type() { return field_type::String; }
};
template<typename Type>
struct field_traits<Type, typename std::enable_if<std::is_same<Type, bool>::value>::type>
{
static field_type type() { return field_type::Boolean; }
};
template<typename Type>
struct field_traits<Type, typename std::enable_if<std::is_same<Type, nullptr_t>::value>::type>
{
static field_type type() { return field_type::Null; }
};
template<typename Type>
struct field_traits<Type, typename std::enable_if<std::is_same<Type, utils::blob>::value>::type>
{
static field_type type() { return field_type::Blob; }
};
class field
{
public:
@@ -70,7 +22,7 @@ public:
, size_(size)
, index_(index)
, value_(value)
, type_(field_traits<Type>::type()) {}
, type_(data_type_traits<Type>::builtin_type(size)) {}
field(std::string name, data_type_t data_type, size_t size = 0, int index = -1);
field(const field &x) = default;
field& operator=(const field &x) = default;
@@ -80,7 +32,7 @@ public:
template<typename Type>
field& operator=(Type value) {
value_ = std::move(value);
type_ = field_traits<Type>::type();
type_ = data_type_traits<Type>::builtin_type(-1);
return *this;
}
@@ -102,8 +54,10 @@ public:
[[nodiscard]] bool is_floating_point() const;
[[nodiscard]] bool is_bool() const;
[[nodiscard]] bool is_string() const;
[[nodiscard]] bool is_varchar() const;
[[nodiscard]] bool is_blob() const;
[[nodiscard]] bool is_null() const;
[[nodiscard]] bool is_unknown() const;
friend std::ostream& operator<<(std::ostream &out, const field &col);
@@ -111,19 +65,17 @@ private:
template<class Operator>
void process(Operator &op)
{
op.on_attribute(name_.c_str(), value_, field_type_to_data_type(type_), size_);
op.on_attribute(name_.c_str(), value_, type_, size_);
}
private:
friend class record;
static data_type_t field_type_to_data_type(field_type type);
std::string name_;
int index_{-1};
any_type value_;
size_t size_{};
field_type type_;
data_type_t type_;
};
}