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
+1 -1
View File
@@ -33,7 +33,7 @@ const std::string &column_definition::name() const
return name_;
}
size_t column_definition::index() const
int column_definition::index() const
{
return index_;
}
+20 -29
View File
@@ -7,13 +7,14 @@ namespace matador::sql {
field::field(std::string name)
: name_(std::move(name))
, value_(nullptr)
, type_(field_traits<nullptr_t>::type())
, type_(data_type_t::type_unknown)
{}
field::field(std::string name, data_type_t data_type, size_t size, int index)
{
}
: name_(std::move(name))
, size_(size)
, index_(index)
, type_(data_type) {}
field::field(field &&x) noexcept
: name_(std::move(x.name_))
@@ -23,7 +24,7 @@ field::field(field &&x) noexcept
{
x.value_ = nullptr;
x.index_ = -1;
x.type_ = field_type::Null;
x.type_ = data_type_t::type_unknown;
}
field &field::operator=(field &&x) noexcept
@@ -34,7 +35,7 @@ field &field::operator=(field &&x) noexcept
type_ = x.type_;
x.index_ = -1;
x.value_ = nullptr;
x.type_ = field_type::Null;
x.type_ = data_type_t::type_unknown;
return *this;
}
@@ -67,52 +68,42 @@ std::string field::str() const
bool field::is_integer() const
{
return type_ == field_type::Integer;
return type_ >= data_type_t::type_char && type_ <= data_type_t::type_unsigned_long_long;
}
bool field::is_floating_point() const
{
return type_ == field_type::FloatingPoint;
return type_ == data_type_t::type_float || type_ == data_type_t::type_double;
}
bool field::is_bool() const
{
return type_ == field_type::Boolean;
return type_ == data_type_t::type_bool;
}
bool field::is_string() const
{
return type_ == field_type::String;
return type_ == data_type_t::type_text;
}
bool field::is_varchar() const
{
return type_ == data_type_t::type_varchar;
}
bool field::is_blob() const
{
return type_ == field_type::Blob;
return type_ == data_type_t::type_blob;
}
bool field::is_null() const
{
return type_ == field_type::Null;
return type_ == data_type_t::type_null;
}
data_type_t field::field_type_to_data_type(field_type type)
bool field::is_unknown() const
{
switch (type) {
case field_type::Integer:
return data_type_t::type_long_long;
case field_type::FloatingPoint:
return data_type_t::type_double;
case field_type::String:
return data_type_t::type_varchar;
case field_type::Boolean:
return data_type_t::type_bool;
case field_type::Blob:
return data_type_t::type_blob;
case field_type::Null:
return data_type_t::type_null;
default:
return data_type_t::type_unknown;
}
return type_ == data_type_t::type_unknown;
}
}
+3 -3
View File
@@ -8,9 +8,9 @@ template<>
record *create_prototype<record>(const std::vector<column_definition> &prototype)
{
auto result = std::make_unique<record>();
// for (const auto &col: prototype) {
// result->append({})
// }
for (const auto &col: prototype) {
result->append({col.name(), col.type(), col.attributes().size(), col.index()});
}
return result.release();
}