diff --git a/include/matador/sql/convert.hpp b/include/matador/sql/convert.hpp index 659d7aa..edb9b8e 100644 --- a/include/matador/sql/convert.hpp +++ b/include/matador/sql/convert.hpp @@ -55,6 +55,12 @@ void convert(std::string &dest, SourceType source, typename std::enable_if +void convert(utils::blob &dest, SourceType source, typename std::enable_if::value>::type* = nullptr) +{ + throw std::logic_error("couldn't convert value to matador::utils::blob"); +} + void convert(std::string &dest, const char* source); unsigned long long to_unsigned_long_long(const char *source); @@ -108,8 +114,11 @@ void convert(DestType &dest, bool source, typename std::enable_if void convert(DestType &dest, const utils::blob &data) { + throw std::logic_error("couldn't convert matador::utils::blob into destination type"); } +void convert(utils::blob &dest, const utils::blob &data); + } #endif //QUERY_CONVERT_HPP diff --git a/src/sql/convert.cpp b/src/sql/convert.cpp index d4997b6..8d748f1 100644 --- a/src/sql/convert.cpp +++ b/src/sql/convert.cpp @@ -59,4 +59,9 @@ long double to_double(const char *source) return result; } +void convert(utils::blob &dest, const utils::blob &data) +{ + dest = data; +} + } \ No newline at end of file diff --git a/test/FieldTest.cpp b/test/FieldTest.cpp index 287088f..1b44b13 100644 --- a/test/FieldTest.cpp +++ b/test/FieldTest.cpp @@ -2,10 +2,10 @@ #include "matador/sql/field.hpp" -using namespace matador::sql; +using namespace matador; TEST_CASE("Field test", "[field]") { - field f("name"); + sql::field f("name"); REQUIRE(f.name() == "name"); REQUIRE(f.is_null()); @@ -35,4 +35,18 @@ TEST_CASE("Field test", "[field]") { auto bool_val = f.as(); REQUIRE(bool_val.has_value()); REQUIRE(bool_val.value()); + + f = utils::blob{ 7,8,6,5,4,3 }; + REQUIRE(!f.is_null()); + REQUIRE(!f.is_integer()); + REQUIRE(!f.is_floating_point()); + REQUIRE(f.is_blob()); + REQUIRE(!f.is_bool()); + REQUIRE(!f.is_string()); + + auto blob_val = f.as(); + REQUIRE(blob_val.has_value()); + REQUIRE(blob_val.value() == utils::blob{ 7,8,6,5,4,3 }); + + REQUIRE_THROWS_AS(f.as(), std::logic_error); } \ No newline at end of file