diff --git a/include/sqlpp11/compat/optional.h b/include/sqlpp11/compat/optional.h index 8ad500c4..35ed5165 100644 --- a/include/sqlpp11/compat/optional.h +++ b/include/sqlpp11/compat/optional.h @@ -36,7 +36,8 @@ #include namespace sqlpp { -#warning move into compat? + namespace compat + { template using optional = std::optional; @@ -44,6 +45,7 @@ namespace sqlpp using std::nullopt; using std::bad_optional_access; + } // namespace compat } // namespace sqlpp #else // incomplete backport of std::optional @@ -53,196 +55,201 @@ namespace sqlpp namespace sqlpp { - class nullopt_t + namespace compat { - }; - constexpr nullopt_t nullopt; + class nullopt_t + { + }; + constexpr nullopt_t nullopt; - class bad_optional_access : public std::exception - { + class bad_optional_access : public std::exception + { public: ~bad_optional_access() override = default; const char* what() const noexcept override { return "bad optional access"; } - }; - - template - class optional - { - // Unnamed union, injecting members into scope. - union - { - char _nothing; - T _value; }; - bool _active = false; - // Placement new - template - void create(Args&&... args) + template + class optional { - new ((void*)std::addressof(_value)) T(std::forward(args)...); - _active = true; - } - - void destroy() - { - if (_active) + // Unnamed union, injecting members into scope. + union { - _value.~T(); + char _nothing; + T _value; + }; + bool _active = false; + + // Placement new + template + void create(Args&&... args) + { + new ((void*)std::addressof(_value)) T(std::forward(args)...); + _active = true; } - } - public: - optional() noexcept : _nothing(), _active(false) - { - } - optional(T t) : _active(true) - { - create(std::move(t)); - } + void destroy() + { + if (_active) + { + _value.~T(); + } + } - optional(const optional&) = default; - optional(optional&&) = default; - optional(const nullopt_t&) noexcept - { - } + public: + optional() noexcept : _nothing(), _active(false) + { + } + optional(T t) : _active(true) + { + create(std::move(t)); + } - optional& operator=(const optional&) = default; - optional& operator=(optional&&) = default; - optional& operator=(const nullopt_t&) noexcept - { - destroy(); - } + optional(const optional&) = default; + optional(optional&&) = default; + optional(const nullopt_t&) noexcept + { + } - ~optional() { - destroy(); - } + optional& operator=(const optional&) = default; + optional& operator=(optional&&) = default; + optional& operator=(const nullopt_t&) noexcept + { + destroy(); + } - bool has_value() const - { - return _active; - } + ~optional() + { + destroy(); + } - explicit operator bool() const - { - return _active; - } + bool has_value() const + { + return _active; + } - T& operator*() - { - return _value; - } + explicit operator bool() const + { + return _active; + } - const T& operator*() const - { - return _value; - } - - const T& operator->() const - { - return _value; - } - - template - optional& emplace(Args&&... args) { - create(std::forward(args)...); - } - - T& value() - { - if (_active) + T& operator*() + { return _value; - throw bad_optional_access(); - } + } - template - T value_or(U&& u) - { - if (_active) + const T& operator*() const + { return _value; - return std::forward(u); - } + } - const T& value() const - { - if (_active) + const T& operator->() const + { return _value; - throw bad_optional_access(); - } + } - void reset() + template + optional& emplace(Args&&... args) + { + create(std::forward(args)...); + } + + T& value() + { + if (_active) + return _value; + throw bad_optional_access(); + } + + template + T value_or(U&& u) + { + if (_active) + return _value; + return std::forward(u); + } + + const T& value() const + { + if (_active) + return _value; + throw bad_optional_access(); + } + + void reset() + { + destroy(); + } + }; + + template + bool operator==(const optional& left, const optional& right) { - destroy(); + if (static_cast(left) != static_cast(right)) + return false; + if (!static_cast(left)) + return true; + return *left == *right; } - }; - template - bool operator==(const optional& left, const optional& right) - { - if (static_cast(left) != static_cast(right)) - return false; - if (!static_cast(left)) - return true; - return *left == *right; - } + template + bool operator==(const optional& left, const R& right) + { + if (!static_cast(left)) + return false; + return *left == right; + } - template - bool operator==(const optional& left, const R& right) - { - if (!static_cast(left)) - return false; - return *left == right; - } + template + bool operator==(const L& left, const optional& right) + { + if (!static_cast(right)) + return false; + return left == *right; + } - template - bool operator==(const L& left, const optional& right) - { - if (!static_cast(right)) - return false; - return left == *right; - } + template + bool operator!=(const optional& left, const optional& right) + { + if (static_cast(left) != static_cast(right)) + return true; + if (!static_cast(left)) + return false; + return *left != *right; + } - template - bool operator!=(const optional& left, const optional& right) - { - if (static_cast(left) != static_cast(right)) - return true; - if (!static_cast(left)) - return false; - return *left != *right; - } + template + bool operator!=(const optional& left, const R& right) + { + if (!static_cast(left)) + return true; + return *left != right; + } - template - bool operator!=(const optional& left, const R& right) - { - if (!static_cast(left)) - return true; - return *left != right; - } + template + bool operator!=(const L& left, const optional& right) + { + if (!static_cast(right)) + return true; + return left != *right; + } - template - bool operator!=(const L& left, const optional& right) - { - if (!static_cast(right)) - return true; - return left != *right; - } + template + bool operator==(const optional& left, const nullopt_t&) + { + return !left; + } - template - bool operator==(const optional& left, const nullopt_t&) - { - return !left; - } - - template - bool operator==(const nullopt_t& n, const optional& right) - { - return !right; - } + template + bool operator==(const nullopt_t& n, const optional& right) + { + return !right; + } + } // namespace compat } // namespace sqlpp #endif diff --git a/include/sqlpp11/compat/span.h b/include/sqlpp11/compat/span.h index 22fcbc8f..c957f4c6 100644 --- a/include/sqlpp11/compat/span.h +++ b/include/sqlpp11/compat/span.h @@ -36,42 +36,48 @@ #include namespace sqlpp { - template - using span = std::span; + namespace compat + { + template + using span = std::span; + } } // namespace sqlpp #else // incomplete backport of std::span namespace sqlpp { - template - class span + namespace compat { - const T* _data = nullptr; - size_t _size = 0u; - public: - constexpr span() = default; - constexpr span(const T* data, size_t size) : _data(data), _size(size) + template + class span { - } + const T* _data = nullptr; + size_t _size = 0u; - const char* data() const - { - return _data; - } + public: + constexpr span() = default; + constexpr span(const T* data, size_t size) : _data(data), _size(size) + { + } - size_t size() const - { - return _size; - } + const char* data() const + { + return _data; + } - const T& operator[](size_t i) const - { - return *(_data + i); - } + size_t size() const + { + return _size; + } - }; + const T& operator[](size_t i) const + { + return *(_data + i); + } + }; + } // namespace compat } // namespace sqlpp #endif diff --git a/include/sqlpp11/compat/string_view.h b/include/sqlpp11/compat/string_view.h index b1863979..3e15b699 100644 --- a/include/sqlpp11/compat/string_view.h +++ b/include/sqlpp11/compat/string_view.h @@ -36,7 +36,10 @@ #include namespace sqlpp { - using string_view = std::string_view; + namespace compat + { + using string_view = std::string_view; + } } // namespace sqlpp #else // incomplete backport of std::string_view @@ -47,60 +50,63 @@ namespace sqlpp namespace sqlpp { - class string_view + namespace compat { - const char* _data = nullptr; - size_t _size = 0u; - public: - constexpr string_view() = default; - string_view(const std::string& source) : _data(source.data()), _size(source.size()) + class string_view { + const char* _data = nullptr; + size_t _size = 0u; + + public: + constexpr string_view() = default; + string_view(const std::string& source) : _data(source.data()), _size(source.size()) + { + } + + constexpr string_view(const char* data, size_t size) : _data(data), _size(size) + { + } + + string_view(const char* data) : _data(data), _size(std::char_traits::length(data)) + { + } + + const char* data() const + { + return _data; + } + + size_t size() const + { + return _size; + } + + operator std::string() const + { + return std::string(_data, _size); + } + }; + + inline bool operator==(const string_view& left, const string_view& right) + { + if (left.size() != right.size()) + return false; + return std::char_traits::compare(left.data(), right.data(), left.size()) == 0; } - constexpr string_view(const char* data, size_t size) : _data(data), _size(size) + inline bool operator!=(const string_view& left, const string_view& right) { + if (left.size() != right.size()) + return true; + return std::char_traits::compare(left.data(), right.data(), left.size()) != 0; } - string_view(const char* data) : _data(data), _size(std::char_traits::length(data)) + inline std::ostream& operator<<(std::ostream& os, const string_view& sv) { + return os << std::string(sv); } - const char* data() const - { - return _data; - } - - size_t size() const - { - return _size; - } - - operator std::string() const - { - return std::string(_data, _size); - } - }; - - inline bool operator==(const string_view& left, const string_view& right) - { - if (left.size() != right.size()) - return false; - return std::char_traits::compare(left.data(), right.data(), left.size()) == 0; - } - - inline bool operator!=(const string_view& left, const string_view& right) - { - if (left.size() != right.size()) - return true; - return std::char_traits::compare(left.data(), right.data(), left.size()) != 0; - } - - inline std::ostream& operator<<(std::ostream& os, const string_view& sv) - { - return os << std::string(sv); - } - - + } // namespace compat } // namespace sqlpp #endif diff --git a/include/sqlpp11/data_types/blob/data_type.h b/include/sqlpp11/data_types/blob/data_type.h index 4a6e98ad..31437609 100644 --- a/include/sqlpp11/data_types/blob/data_type.h +++ b/include/sqlpp11/data_types/blob/data_type.h @@ -39,7 +39,7 @@ namespace sqlpp { using _traits = make_traits; using _cpp_value_type = std::vector; - using _result_type = sqlpp::span; + using _result_type = sqlpp::compat::span; template using _is_valid_operand = ::sqlpp::logic::any_t::value, is_text_t::value>; diff --git a/include/sqlpp11/data_types/text/data_type.h b/include/sqlpp11/data_types/text/data_type.h index 99c63d4e..8a19f9da 100644 --- a/include/sqlpp11/data_types/text/data_type.h +++ b/include/sqlpp11/data_types/text/data_type.h @@ -38,7 +38,7 @@ namespace sqlpp { using _traits = make_traits; using _cpp_value_type = std::string; - using _result_type = sqlpp::string_view; + using _result_type = sqlpp::compat::string_view; template using _is_valid_operand = is_text_t; diff --git a/include/sqlpp11/data_types/text/operand.h b/include/sqlpp11/data_types/text/operand.h index cee99120..c2f49926 100644 --- a/include/sqlpp11/data_types/text/operand.h +++ b/include/sqlpp11/data_types/text/operand.h @@ -49,8 +49,8 @@ namespace sqlpp text_operand(_value_t t) : _t(std::move(t)) { } - // allow construction from an sqlpp::string_view - text_operand(sqlpp::string_view t) : _t(t) + // allow construction from an sqlpp::compat::string_view + text_operand(sqlpp::compat::string_view t) : _t(t) { } // additional const char* overload, required to disambiguate diff --git a/include/sqlpp11/data_types/text/parameter_value.h b/include/sqlpp11/data_types/text/parameter_value.h index 8a1aeab1..23da1693 100644 --- a/include/sqlpp11/data_types/text/parameter_value.h +++ b/include/sqlpp11/data_types/text/parameter_value.h @@ -49,7 +49,7 @@ namespace sqlpp target._bind_text_parameter(index, &_value, _is_null); } - parameter_value_base& operator=(const sqlpp::string_view& val) + parameter_value_base& operator=(const sqlpp::compat::string_view& val) { _value = val; _is_null = false; diff --git a/include/sqlpp11/data_types/text/wrap_operand.h b/include/sqlpp11/data_types/text/wrap_operand.h index 8d1e4ef5..17ccff47 100644 --- a/include/sqlpp11/data_types/text/wrap_operand.h +++ b/include/sqlpp11/data_types/text/wrap_operand.h @@ -34,7 +34,7 @@ namespace sqlpp { struct text_operand; - using checked_type = sqlpp::string_view; + using checked_type = sqlpp::compat::string_view; template struct wrap_operand< diff --git a/include/sqlpp11/field_spec.h b/include/sqlpp11/field_spec.h index b4152b5b..48a6586e 100644 --- a/include/sqlpp11/field_spec.h +++ b/include/sqlpp11/field_spec.h @@ -45,7 +45,7 @@ namespace sqlpp using _alias_t = NameType; using cpp_type = typename std::conditional, + sqlpp::compat::optional, typename ValueType::_result_type>::type; }; diff --git a/include/sqlpp11/mysql/bind_result.h b/include/sqlpp11/mysql/bind_result.h index 3b3d95d7..9e3245cf 100644 --- a/include/sqlpp11/mysql/bind_result.h +++ b/include/sqlpp11/mysql/bind_result.h @@ -187,7 +187,7 @@ namespace sqlpp param.error = &buffer.error; } - void bind_field(size_t index, sqlpp::string_view& /*value*/) + void bind_field(size_t index, sqlpp::compat::string_view& /*value*/) { if (_handle->debug) std::cerr << "MySQL debug: binding text result at index: " << index @@ -205,7 +205,7 @@ namespace sqlpp param.error = &buffer.error; } - void bind_field(size_t index, sqlpp::span& /*value*/) + void bind_field(size_t index, sqlpp::compat::span& /*value*/) { if (_handle->debug) std::cerr << "MySQL debug: binding blob result at index: " << index @@ -266,7 +266,7 @@ namespace sqlpp } template - void bind_field(size_t index, sqlpp::optional& value) + void bind_field(size_t index, sqlpp::compat::optional& value) { value = T{}; bind_field(index, *value); @@ -327,7 +327,7 @@ namespace sqlpp } } - void read_field(size_t index, sqlpp::string_view& value) + void read_field(size_t index, sqlpp::compat::string_view& value) { if (_handle->debug) std::cerr << "MySQL debug: reading text result at index: " << index @@ -335,10 +335,10 @@ namespace sqlpp refetch_if_required(index); const auto& buffer = _handle->result_buffers[index]; const auto& params = _handle->result_params[index]; - value = sqlpp::string_view(buffer.var_buffer.data(), *params.length); + value = sqlpp::compat::string_view(buffer.var_buffer.data(), *params.length); } - void read_field(size_t index, sqlpp::span& value) + void read_field(size_t index, sqlpp::compat::span& value) { if (_handle->debug) std::cerr << "MySQL debug: reading blob result at index: " << index @@ -346,7 +346,7 @@ namespace sqlpp refetch_if_required(index); const auto& buffer = _handle->result_buffers[index]; const auto& params = _handle->result_params[index]; - value = sqlpp::span(reinterpret_cast(buffer.var_buffer.data()), *params.length); + value = sqlpp::compat::span(reinterpret_cast(buffer.var_buffer.data()), *params.length); } void read_field(size_t index, ::sqlpp::chrono::day_point& value) @@ -386,7 +386,7 @@ namespace sqlpp } template - void read_field(size_t index, sqlpp::optional& value) + void read_field(size_t index, sqlpp::compat::optional& value) { if (_handle->result_buffers[index].is_null) { diff --git a/include/sqlpp11/mysql/char_result.h b/include/sqlpp11/mysql/char_result.h index 9d8f704d..73031192 100644 --- a/include/sqlpp11/mysql/char_result.h +++ b/include/sqlpp11/mysql/char_result.h @@ -125,14 +125,14 @@ namespace sqlpp value = std::strtoull(_char_result_row.data[index], nullptr, 10); } - void read_field(size_t index, sqlpp::span& value) + void read_field(size_t index, sqlpp::compat::span& value) { - value = sqlpp::span(reinterpret_cast(_char_result_row.data[index]), _char_result_row.len[index]); + value = sqlpp::compat::span(reinterpret_cast(_char_result_row.data[index]), _char_result_row.len[index]); } - void read_field(size_t index, sqlpp::string_view& value) + void read_field(size_t index, sqlpp::compat::string_view& value) { - value = sqlpp::string_view(_char_result_row.data[index], _char_result_row.len[index]); + value = sqlpp::compat::string_view(_char_result_row.data[index], _char_result_row.len[index]); } void read_field(size_t index, ::sqlpp::chrono::day_point& value) @@ -184,7 +184,7 @@ namespace sqlpp } template - auto read_field(size_t index, sqlpp::optional& value) -> void + auto read_field(size_t index, sqlpp::compat::optional& value) -> void { const bool is_null = _char_result_row.data[index] == nullptr; if (is_null) diff --git a/include/sqlpp11/postgresql/bind_result.h b/include/sqlpp11/postgresql/bind_result.h index a67b23c9..51328ac8 100644 --- a/include/sqlpp11/postgresql/bind_result.h +++ b/include/sqlpp11/postgresql/bind_result.h @@ -242,7 +242,7 @@ namespace sqlpp value = _handle->result.get_uint64_value(_handle->count, index); } - void read_field(size_t _index, sqlpp::string_view& value) + void read_field(size_t _index, sqlpp::compat::string_view& value) { const auto index = static_cast(_index); if (_handle->debug()) @@ -250,7 +250,7 @@ namespace sqlpp std::cerr << "PostgreSQL debug: reading text result at index: " << index << std::endl; } - value = sqlpp::string_view(_handle->result.get_char_ptr_value(_handle->count, index), + value = sqlpp::compat::string_view(_handle->result.get_char_ptr_value(_handle->count, index), static_cast(_handle->result.length(_handle->count, index))); } @@ -332,7 +332,7 @@ namespace sqlpp } } - void read_field(size_t _index, sqlpp::span& value) + void read_field(size_t _index, sqlpp::compat::span& value) { const auto index = static_cast(_index); if (_handle->debug()) @@ -347,11 +347,11 @@ namespace sqlpp detail::hex_assign(_var_buffers[_index], _handle->result.get_blob_value(_handle->count, index), static_cast(_handle->result.length(_handle->count, index))); - value = sqlpp::span(_var_buffers[_index].data(), size); + value = sqlpp::compat::span(_var_buffers[_index].data(), size); } template - auto read_field(size_t _index, sqlpp::optional& value) -> void + auto read_field(size_t _index, sqlpp::compat::optional& value) -> void { const auto index = static_cast(_index); if (_handle->result.is_null(_handle->count, index)) diff --git a/include/sqlpp11/sqlite3/bind_result.h b/include/sqlpp11/sqlite3/bind_result.h index 790606d5..1bba1463 100644 --- a/include/sqlpp11/sqlite3/bind_result.h +++ b/include/sqlpp11/sqlite3/bind_result.h @@ -135,22 +135,22 @@ namespace sqlpp value = static_cast(sqlite3_column_int64(_handle->sqlite_statement, static_cast(index))); } - void read_field(size_t index, sqlpp::string_view& value) + void read_field(size_t index, sqlpp::compat::string_view& value) { if (_handle->debug) std::cerr << "Sqlite3 debug: binding text result at index: " << index << std::endl; - value = sqlpp::string_view( + value = sqlpp::compat::string_view( reinterpret_cast(sqlite3_column_text(_handle->sqlite_statement, static_cast(index))), static_cast(sqlite3_column_bytes(_handle->sqlite_statement, static_cast(index)))); } - void read_field(size_t index, sqlpp::span& value) + void read_field(size_t index, sqlpp::compat::span& value) { if (_handle->debug) std::cerr << "Sqlite3 debug: binding blob result at index: " << index << std::endl; - value = sqlpp::span( + value = sqlpp::compat::span( reinterpret_cast(sqlite3_column_blob(_handle->sqlite_statement, static_cast(index))), static_cast(sqlite3_column_bytes(_handle->sqlite_statement, static_cast(index)))); } @@ -191,7 +191,7 @@ namespace sqlpp } template - auto read_field(size_t index, sqlpp::optional& value) -> void + auto read_field(size_t index, sqlpp::compat::optional& value) -> void { const bool is_null = sqlite3_column_type(_handle->sqlite_statement, static_cast(index)) == SQLITE_NULL; if (is_null) diff --git a/tests/core/serialize/Insert.cpp b/tests/core/serialize/Insert.cpp index 3dd1a763..c9d4177c 100644 --- a/tests/core/serialize/Insert.cpp +++ b/tests/core/serialize/Insert.cpp @@ -47,10 +47,10 @@ int Insert(int, char* []) "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); compare(__LINE__, insert_into(bar).set(bar.beta = ::sqlpp::null, bar.gamma = true), "INSERT INTO tab_bar (beta,gamma) VALUES(NULL," + getTrue() + ")"); - sqlpp::string_view cheeseCake = "cheesecake"; + sqlpp::compat::string_view cheeseCake = "cheesecake"; compare(__LINE__, insert_into(bar).set(bar.beta = std::string(cheeseCake), bar.gamma = true), "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); - compare(__LINE__, insert_into(bar).set(bar.beta = sqlpp::string_view(cheeseCake), bar.gamma = true), + compare(__LINE__, insert_into(bar).set(bar.beta = sqlpp::compat::string_view(cheeseCake), bar.gamma = true), "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); return 0; diff --git a/tests/core/serialize/Where.cpp b/tests/core/serialize/Where.cpp index 6fe8f7e3..ecf906ec 100644 --- a/tests/core/serialize/Where.cpp +++ b/tests/core/serialize/Where.cpp @@ -73,7 +73,7 @@ int Where(int, char*[]) compare(__LINE__, where(bar.beta == std::string("SQL")), " WHERE (tab_bar.beta='SQL')"); // string_view argument - compare(__LINE__, where(bar.beta == sqlpp::string_view("SQL")), " WHERE (tab_bar.beta='SQL')"); + compare(__LINE__, where(bar.beta == sqlpp::compat::string_view("SQL")), " WHERE (tab_bar.beta='SQL')"); return 0; } diff --git a/tests/core/usage/Insert.cpp b/tests/core/usage/Insert.cpp index 7178cb3e..6eba7c09 100644 --- a/tests/core/usage/Insert.cpp +++ b/tests/core/usage/Insert.cpp @@ -102,7 +102,7 @@ int Insert(int, char*[]) auto prepared_insert_sv = db.prepare(insert_into(t).set(t.gamma = parameter(t.gamma), t.delta = parameter(t.delta), t.beta = parameter(t.beta))); prepared_insert_sv.params.gamma = true; prepared_insert_sv.params.delta = 17; - prepared_insert_sv.params.beta = sqlpp::string_view("string_view");; + prepared_insert_sv.params.beta = sqlpp::compat::string_view("string_view");; db(prepared_insert_sv); return 0; diff --git a/tests/core/usage/Select.cpp b/tests/core/usage/Select.cpp index bfedf4d0..b9d0a8a0 100644 --- a/tests/core/usage/Select.cpp +++ b/tests/core/usage/Select.cpp @@ -57,8 +57,8 @@ struct to_cerr template void print_row(Row const& row) { - const sqlpp::optional a = row.alpha; - const sqlpp::optional b = row.beta; + const sqlpp::compat::optional a = row.alpha; + const sqlpp::compat::optional b = row.beta; std::cout << a << ", " << b << std::endl; } @@ -91,16 +91,16 @@ int Select(int, char*[]) for (const auto& row : db(select(all_of(t)).from(t).unconditionally())) { - const sqlpp::optional a = row.alpha; - const sqlpp::optional b = row.beta; + const sqlpp::compat::optional a = row.alpha; + const sqlpp::compat::optional b = row.beta; std::cout << a << ", " << b << std::endl; } for (const auto& row : db(select(all_of(t), t.gamma.as(t)).from(t).where(t.alpha > 7 and trim(t.beta) == "test").for_update())) { - const sqlpp::optional a = row.alpha; - const sqlpp::optional b = row.beta; + const sqlpp::compat::optional a = row.alpha; + const sqlpp::compat::optional b = row.beta; const bool g = row.tabBar; std::cout << a << ", " << b << ", " << g << std::endl; } @@ -154,7 +154,7 @@ int Select(int, char*[]) #warning add tests for optional everything for (const auto& row : db(db.prepare(s))) { - const sqlpp::optional a = row.alpha; + const sqlpp::compat::optional a = row.alpha; std::cout << a << std::endl; } diff --git a/tests/include/test_helpers.h b/tests/include/test_helpers.h index 1cb83179..5ddd8e04 100644 --- a/tests/include/test_helpers.h +++ b/tests/include/test_helpers.h @@ -45,7 +45,7 @@ std::ostream& operator<<(std::ostream& os, const std::chrono::duration -std::ostream& operator<<(std::ostream& os, const sqlpp::optional& t) +std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional& t) { if (not t) return os << "NULL"; @@ -100,5 +100,5 @@ template struct is_optional : public std::false_type{}; template -struct is_optional> : public std::true_type{}; +struct is_optional> : public std::true_type{}; diff --git a/tests/mysql/usage/Json.cpp b/tests/mysql/usage/Json.cpp index dfe426fc..098d031b 100644 --- a/tests/mysql/usage/Json.cpp +++ b/tests/mysql/usage/Json.cpp @@ -78,7 +78,7 @@ int Json(int, char*[]) if (result.empty()) throw std::runtime_error{"selection result is empty"}; - const sqlpp::optional value = result.front().value; + const sqlpp::compat::optional value = result.front().value; if (value != "value") throw std::runtime_error{std::string{"unexpected value: "} + std::string(value ? value.value() : "NULL")}; diff --git a/tests/mysql/usage/Sample.cpp b/tests/mysql/usage/Sample.cpp index 6f13e7f7..1aacda83 100644 --- a/tests/mysql/usage/Sample.cpp +++ b/tests/mysql/usage/Sample.cpp @@ -121,7 +121,7 @@ int Sample(int, char*[]) if (const auto& row = *result.begin()) { const int64_t a = row.alpha; - const sqlpp::optional m = row.max; + const sqlpp::compat::optional m = row.max; std::cerr << __LINE__ << " row.alpha: " << a << ", row.max: " << m << std::endl; } tx.commit(); diff --git a/tests/mysql/usage/Select.cpp b/tests/mysql/usage/Select.cpp index 2d6e58ac..faa51c2f 100644 --- a/tests/mysql/usage/Select.cpp +++ b/tests/mysql/usage/Select.cpp @@ -154,8 +154,8 @@ int Select(int, char*[]) auto result = db(select(all_of(tab), select(max(tab.alpha)).from(tab)).from(tab).unconditionally()); if (const auto& row = *result.begin()) { - sqlpp::optional a = row.alpha; - sqlpp::optional m = row.max; + sqlpp::compat::optional a = row.alpha; + sqlpp::compat::optional m = row.max; std::cerr << "-----------------------------" << a << ", " << m << std::endl; } tx.commit(); diff --git a/tests/postgresql/usage/Blob.cpp b/tests/postgresql/usage/Blob.cpp index 1c31cd67..92af2294 100644 --- a/tests/postgresql/usage/Blob.cpp +++ b/tests/postgresql/usage/Blob.cpp @@ -103,7 +103,7 @@ int Blob(int, char*[]) { auto result = db(select(blob.data).from(blob).where(blob.id == null_id)); const auto& result_row = result.front(); - std::cerr << "Null blob is_null:\t" << std::boolalpha << (result_row.data == sqlpp::nullopt) << std::endl; + std::cerr << "Null blob is_null:\t" << std::boolalpha << (result_row.data == sqlpp::compat::nullopt) << std::endl; if (result_row.data.has_value()) { throw std::runtime_error("Expected NULL blob has value"); diff --git a/tests/sqlite3/usage/Blob.cpp b/tests/sqlite3/usage/Blob.cpp index 45779f95..212cf84e 100644 --- a/tests/sqlite3/usage/Blob.cpp +++ b/tests/sqlite3/usage/Blob.cpp @@ -86,7 +86,7 @@ int Blob(int, char*[]) { auto result = db(select(tab.data).from(tab).where(tab.id == null_id)); const auto& result_row = result.front(); - std::cerr << "Null blob is_null:\t" << std::boolalpha << (result_row.data == sqlpp::nullopt) << std::endl; + std::cerr << "Null blob is_null:\t" << std::boolalpha << (result_row.data == sqlpp::compat::nullopt) << std::endl; } return 0; } diff --git a/tests/sqlite3/usage/DateTime.cpp b/tests/sqlite3/usage/DateTime.cpp index 1895b46c..1689c966 100644 --- a/tests/sqlite3/usage/DateTime.cpp +++ b/tests/sqlite3/usage/DateTime.cpp @@ -78,8 +78,8 @@ int DateTime(int, char*[]) for (const auto& row : db(select(all_of(tab)).from(tab).unconditionally())) { - require_equal(__LINE__, row.colDayPoint == sqlpp::nullopt, true); - require_equal(__LINE__, row.colTimePoint == sqlpp::nullopt, true); + require_equal(__LINE__, row.colDayPoint == sqlpp::compat::nullopt, true); + require_equal(__LINE__, row.colTimePoint == sqlpp::compat::nullopt, true); } db(update(tab).set(tab.colDayPoint = today, tab.colTimePoint = now).unconditionally()); diff --git a/tests/sqlite3/usage/DynamicSelect.cpp b/tests/sqlite3/usage/DynamicSelect.cpp index 45231a6a..d2f4d335 100644 --- a/tests/sqlite3/usage/DynamicSelect.cpp +++ b/tests/sqlite3/usage/DynamicSelect.cpp @@ -42,7 +42,7 @@ #include template -std::ostream& operator<<(std::ostream& os, const sqlpp::optional& t) { +std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional& t) { if (not t) return os << "NULL"; return os << t.value(); diff --git a/tests/sqlite3/usage/FloatingPoint.cpp b/tests/sqlite3/usage/FloatingPoint.cpp index b7a6e356..8425b459 100644 --- a/tests/sqlite3/usage/FloatingPoint.cpp +++ b/tests/sqlite3/usage/FloatingPoint.cpp @@ -40,7 +40,7 @@ namespace sql = sqlpp::sqlite3; const auto fp = FpSample{}; template -std::ostream& operator<<(std::ostream& os, const sqlpp::optional& t) { +std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional& t) { if (not t) return os << "NULL"; return os << t.value(); diff --git a/tests/sqlite3/usage/Sample.cpp b/tests/sqlite3/usage/Sample.cpp index 44e9b5d9..81e80abb 100644 --- a/tests/sqlite3/usage/Sample.cpp +++ b/tests/sqlite3/usage/Sample.cpp @@ -41,7 +41,7 @@ SQLPP_ALIAS_PROVIDER(pragma) SQLPP_ALIAS_PROVIDER(sub) template -std::ostream& operator<<(std::ostream& os, const sqlpp::optional& t) { +std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional& t) { if (not t) return os << "NULL"; return os << t.value(); @@ -107,8 +107,8 @@ int Sample(int, char*[]) .from(tab) .unconditionally())) { - sqlpp::optional x = row.alpha; - sqlpp::optional a = row.max; + sqlpp::compat::optional x = row.alpha; + sqlpp::compat::optional a = row.max; std::cout << x << ", " << a << std::endl; } tx.commit(); diff --git a/tests/sqlite3/usage/Select.cpp b/tests/sqlite3/usage/Select.cpp index 92415610..5395efea 100644 --- a/tests/sqlite3/usage/Select.cpp +++ b/tests/sqlite3/usage/Select.cpp @@ -42,7 +42,7 @@ namespace sql = sqlpp::sqlite3; const auto tab = TabSample{}; template -std::ostream& operator<<(std::ostream& os, const sqlpp::optional& t) { +std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional& t) { if (not t) return os << "NULL"; return os << t.value(); @@ -166,8 +166,8 @@ int Select(int, char*[]) for (const auto& row : db(select(all_of(tab), select(trim(tab.beta)).from(tab)).from(tab).unconditionally())) { - const sqlpp::optional x = row.alpha; - const sqlpp::optional a = row.trim; + const sqlpp::compat::optional x = row.alpha; + const sqlpp::compat::optional a = row.trim; std::cout << ">>>" << x << ", " << a << std::endl; } diff --git a/tests/sqlite3/usage/Union.cpp b/tests/sqlite3/usage/Union.cpp index 1452844d..f082927a 100644 --- a/tests/sqlite3/usage/Union.cpp +++ b/tests/sqlite3/usage/Union.cpp @@ -38,7 +38,7 @@ namespace sql = sqlpp::sqlite3; const auto tab = TabSample{}; template -std::ostream& operator<<(std::ostream& os, const sqlpp::optional& t) { +std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional& t) { if (not t) return os << "NULL"; return os << t.value(); diff --git a/tests/sqlite3/usage/With.cpp b/tests/sqlite3/usage/With.cpp index 4a13beb2..cde047fc 100644 --- a/tests/sqlite3/usage/With.cpp +++ b/tests/sqlite3/usage/With.cpp @@ -40,7 +40,7 @@ namespace sql = sqlpp::sqlite3; const auto tab = TabSample{}; template -std::ostream& operator<<(std::ostream& os, const sqlpp::optional& t) { +std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional& t) { if (not t) return os << "NULL"; return os << t.value();