0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Move optional, string_view, and span into sqlpp::compat

This commit is contained in:
Roland Bock 2024-06-12 21:31:18 +02:00
parent 8d0f3b3739
commit 0eac55c377
30 changed files with 302 additions and 283 deletions

View File

@ -36,7 +36,8 @@
#include <optional>
namespace sqlpp
{
#warning move into compat?
namespace compat
{
template <class T>
using optional = std::optional<T>;
@ -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 T>
class optional
{
// Unnamed union, injecting members into scope.
union
{
char _nothing;
T _value;
};
bool _active = false;
// Placement new
template<typename... Args>
void create(Args&&... args)
template <class T>
class optional
{
new ((void*)std::addressof(_value)) T(std::forward<Args>(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 <typename... Args>
void create(Args&&... args)
{
new ((void*)std::addressof(_value)) T(std::forward<Args>(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<typename... Args>
optional& emplace(Args&&... args) {
create(std::forward<Args>(args)...);
}
T& value()
{
if (_active)
T& operator*()
{
return _value;
throw bad_optional_access();
}
}
template<typename U>
T value_or(U&& u)
{
if (_active)
const T& operator*() const
{
return _value;
return std::forward<U>(u);
}
}
const T& value() const
{
if (_active)
const T& operator->() const
{
return _value;
throw bad_optional_access();
}
}
void reset()
template <typename... Args>
optional& emplace(Args&&... args)
{
create(std::forward<Args>(args)...);
}
T& value()
{
if (_active)
return _value;
throw bad_optional_access();
}
template <typename U>
T value_or(U&& u)
{
if (_active)
return _value;
return std::forward<U>(u);
}
const T& value() const
{
if (_active)
return _value;
throw bad_optional_access();
}
void reset()
{
destroy();
}
};
template <class L, class R>
bool operator==(const optional<L>& left, const optional<R>& right)
{
destroy();
if (static_cast<bool>(left) != static_cast<bool>(right))
return false;
if (!static_cast<bool>(left))
return true;
return *left == *right;
}
};
template <class L, class R>
bool operator==(const optional<L>& left, const optional<R>& right)
{
if (static_cast<bool>(left) != static_cast<bool>(right))
return false;
if (!static_cast<bool>(left))
return true;
return *left == *right;
}
template <class L, class R>
bool operator==(const optional<L>& left, const R& right)
{
if (!static_cast<bool>(left))
return false;
return *left == right;
}
template <class L, class R>
bool operator==(const optional<L>& left, const R& right)
{
if (!static_cast<bool>(left))
return false;
return *left == right;
}
template <class L, class R>
bool operator==(const L& left, const optional<R>& right)
{
if (!static_cast<bool>(right))
return false;
return left == *right;
}
template <class L, class R>
bool operator==(const L& left, const optional<R>& right)
{
if (!static_cast<bool>(right))
return false;
return left == *right;
}
template <class L, class R>
bool operator!=(const optional<L>& left, const optional<R>& right)
{
if (static_cast<bool>(left) != static_cast<bool>(right))
return true;
if (!static_cast<bool>(left))
return false;
return *left != *right;
}
template <class L, class R>
bool operator!=(const optional<L>& left, const optional<R>& right)
{
if (static_cast<bool>(left) != static_cast<bool>(right))
return true;
if (!static_cast<bool>(left))
return false;
return *left != *right;
}
template <class L, class R>
bool operator!=(const optional<L>& left, const R& right)
{
if (!static_cast<bool>(left))
return true;
return *left != right;
}
template <class L, class R>
bool operator!=(const optional<L>& left, const R& right)
{
if (!static_cast<bool>(left))
return true;
return *left != right;
}
template <class L, class R>
bool operator!=(const L& left, const optional<R>& right)
{
if (!static_cast<bool>(right))
return true;
return left != *right;
}
template <class L, class R>
bool operator!=(const L& left, const optional<R>& right)
{
if (!static_cast<bool>(right))
return true;
return left != *right;
}
template <class T>
bool operator==(const optional<T>& left, const nullopt_t&)
{
return !left;
}
template<class T>
bool operator==(const optional<T>& left, const nullopt_t&)
{
return !left;
}
template<class T>
bool operator==(const nullopt_t& n, const optional<T>& right)
{
return !right;
}
template <class T>
bool operator==(const nullopt_t& n, const optional<T>& right)
{
return !right;
}
} // namespace compat
} // namespace sqlpp
#endif

View File

@ -36,42 +36,48 @@
#include <span>
namespace sqlpp
{
template<typename T>
using span = std::span<T>;
namespace compat
{
template <typename T>
using span = std::span<T>;
}
} // namespace sqlpp
#else // incomplete backport of std::span
namespace sqlpp
{
template <typename T>
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 <typename T>
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

View File

@ -36,7 +36,10 @@
#include <string_view>
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<char>::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<char>::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<char>::compare(left.data(), right.data(), left.size()) != 0;
}
string_view(const char* data) : _data(data), _size(std::char_traits<char>::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<char>::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<char>::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

View File

@ -39,7 +39,7 @@ namespace sqlpp
{
using _traits = make_traits<blob, tag::is_value_type>;
using _cpp_value_type = std::vector<std::uint8_t>;
using _result_type = sqlpp::span<std::uint8_t>;
using _result_type = sqlpp::compat::span<std::uint8_t>;
template <typename T>
using _is_valid_operand = ::sqlpp::logic::any_t<is_blob_t<T>::value, is_text_t<T>::value>;

View File

@ -38,7 +38,7 @@ namespace sqlpp
{
using _traits = make_traits<text, tag::is_value_type>;
using _cpp_value_type = std::string;
using _result_type = sqlpp::string_view;
using _result_type = sqlpp::compat::string_view;
template <typename T>
using _is_valid_operand = is_text_t<T>;

View File

@ -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

View File

@ -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;

View File

@ -34,7 +34,7 @@
namespace sqlpp
{
struct text_operand;
using checked_type = sqlpp::string_view;
using checked_type = sqlpp::compat::string_view;
template <typename T>
struct wrap_operand<

View File

@ -45,7 +45,7 @@ namespace sqlpp
using _alias_t = NameType;
using cpp_type = typename std::conditional<CanBeNull,
sqlpp::optional<typename ValueType::_result_type>,
sqlpp::compat::optional<typename ValueType::_result_type>,
typename ValueType::_result_type>::type;
};

View File

@ -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<uint8_t>& /*value*/)
void bind_field(size_t index, sqlpp::compat::span<uint8_t>& /*value*/)
{
if (_handle->debug)
std::cerr << "MySQL debug: binding blob result at index: " << index
@ -266,7 +266,7 @@ namespace sqlpp
}
template <class T>
void bind_field(size_t index, sqlpp::optional<T>& value)
void bind_field(size_t index, sqlpp::compat::optional<T>& 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<uint8_t>& value)
void read_field(size_t index, sqlpp::compat::span<uint8_t>& 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<uint8_t>(reinterpret_cast<const uint8_t*>(buffer.var_buffer.data()), *params.length);
value = sqlpp::compat::span<uint8_t>(reinterpret_cast<const uint8_t*>(buffer.var_buffer.data()), *params.length);
}
void read_field(size_t index, ::sqlpp::chrono::day_point& value)
@ -386,7 +386,7 @@ namespace sqlpp
}
template <class T>
void read_field(size_t index, sqlpp::optional<T>& value)
void read_field(size_t index, sqlpp::compat::optional<T>& value)
{
if (_handle->result_buffers[index].is_null)
{

View File

@ -125,14 +125,14 @@ namespace sqlpp
value = std::strtoull(_char_result_row.data[index], nullptr, 10);
}
void read_field(size_t index, sqlpp::span<uint8_t>& value)
void read_field(size_t index, sqlpp::compat::span<uint8_t>& value)
{
value = sqlpp::span<uint8_t>(reinterpret_cast<const uint8_t*>(_char_result_row.data[index]), _char_result_row.len[index]);
value = sqlpp::compat::span<uint8_t>(reinterpret_cast<const uint8_t*>(_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 <typename T>
auto read_field(size_t index, sqlpp::optional<T>& value) -> void
auto read_field(size_t index, sqlpp::compat::optional<T>& value) -> void
{
const bool is_null = _char_result_row.data[index] == nullptr;
if (is_null)

View File

@ -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<int>(_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<size_t>(_handle->result.length(_handle->count, index)));
}
@ -332,7 +332,7 @@ namespace sqlpp
}
}
void read_field(size_t _index, sqlpp::span<uint8_t>& value)
void read_field(size_t _index, sqlpp::compat::span<uint8_t>& value)
{
const auto index = static_cast<int>(_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<size_t>(_handle->result.length(_handle->count, index)));
value = sqlpp::span<uint8_t>(_var_buffers[_index].data(), size);
value = sqlpp::compat::span<uint8_t>(_var_buffers[_index].data(), size);
}
template <typename T>
auto read_field(size_t _index, sqlpp::optional<T>& value) -> void
auto read_field(size_t _index, sqlpp::compat::optional<T>& value) -> void
{
const auto index = static_cast<int>(_index);
if (_handle->result.is_null(_handle->count, index))

View File

@ -135,22 +135,22 @@ namespace sqlpp
value = static_cast<uint64_t>(sqlite3_column_int64(_handle->sqlite_statement, static_cast<int>(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<const char*>(sqlite3_column_text(_handle->sqlite_statement, static_cast<int>(index))),
static_cast<size_t>(sqlite3_column_bytes(_handle->sqlite_statement, static_cast<int>(index))));
}
void read_field(size_t index, sqlpp::span<uint8_t>& value)
void read_field(size_t index, sqlpp::compat::span<uint8_t>& value)
{
if (_handle->debug)
std::cerr << "Sqlite3 debug: binding blob result at index: " << index << std::endl;
value = sqlpp::span<uint8_t>(
value = sqlpp::compat::span<uint8_t>(
reinterpret_cast<const uint8_t*>(sqlite3_column_blob(_handle->sqlite_statement, static_cast<int>(index))),
static_cast<size_t>(sqlite3_column_bytes(_handle->sqlite_statement, static_cast<int>(index))));
}
@ -191,7 +191,7 @@ namespace sqlpp
}
template <typename T>
auto read_field(size_t index, sqlpp::optional<T>& value) -> void
auto read_field(size_t index, sqlpp::compat::optional<T>& value) -> void
{
const bool is_null = sqlite3_column_type(_handle->sqlite_statement, static_cast<int>(index)) == SQLITE_NULL;
if (is_null)

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -57,8 +57,8 @@ struct to_cerr
template <typename Row>
void print_row(Row const& row)
{
const sqlpp::optional<int64_t> a = row.alpha;
const sqlpp::optional<sqlpp::string_view> b = row.beta;
const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::compat::optional<sqlpp::compat::string_view> 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<int64_t> a = row.alpha;
const sqlpp::optional<sqlpp::string_view> b = row.beta;
const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::compat::optional<sqlpp::compat::string_view> 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<int64_t> a = row.alpha;
const sqlpp::optional<sqlpp::string_view> b = row.beta;
const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::compat::optional<sqlpp::compat::string_view> 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<int64_t> a = row.alpha;
const sqlpp::compat::optional<int64_t> a = row.alpha;
std::cout << a << std::endl;
}

View File

@ -45,7 +45,7 @@ std::ostream& operator<<(std::ostream& os, const std::chrono::duration<Rep, Peri
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const sqlpp::optional<T>& t)
std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional<T>& t)
{
if (not t)
return os << "NULL";
@ -100,5 +100,5 @@ template <typename T>
struct is_optional : public std::false_type{};
template <typename T>
struct is_optional<sqlpp::optional<T>> : public std::true_type{};
struct is_optional<sqlpp::compat::optional<T>> : public std::true_type{};

View File

@ -78,7 +78,7 @@ int Json(int, char*[])
if (result.empty())
throw std::runtime_error{"selection result is empty"};
const sqlpp::optional<sqlpp::string_view> value = result.front().value;
const sqlpp::compat::optional<sqlpp::compat::string_view> value = result.front().value;
if (value != "value")
throw std::runtime_error{std::string{"unexpected value: "} + std::string(value ? value.value() : "NULL")};

View File

@ -121,7 +121,7 @@ int Sample(int, char*[])
if (const auto& row = *result.begin())
{
const int64_t a = row.alpha;
const sqlpp::optional<long> m = row.max;
const sqlpp::compat::optional<long> m = row.max;
std::cerr << __LINE__ << " row.alpha: " << a << ", row.max: " << m << std::endl;
}
tx.commit();

View File

@ -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<long> a = row.alpha;
sqlpp::optional<long> m = row.max;
sqlpp::compat::optional<long> a = row.alpha;
sqlpp::compat::optional<long> m = row.max;
std::cerr << "-----------------------------" << a << ", " << m << std::endl;
}
tx.commit();

View File

@ -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");

View File

@ -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;
}

View File

@ -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());

View File

@ -42,7 +42,7 @@
#include <vector>
template <typename T>
std::ostream& operator<<(std::ostream& os, const sqlpp::optional<T>& t) {
std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional<T>& t) {
if (not t)
return os << "NULL";
return os << t.value();

View File

@ -40,7 +40,7 @@ namespace sql = sqlpp::sqlite3;
const auto fp = FpSample{};
template <typename T>
std::ostream& operator<<(std::ostream& os, const sqlpp::optional<T>& t) {
std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional<T>& t) {
if (not t)
return os << "NULL";
return os << t.value();

View File

@ -41,7 +41,7 @@ SQLPP_ALIAS_PROVIDER(pragma)
SQLPP_ALIAS_PROVIDER(sub)
template <typename T>
std::ostream& operator<<(std::ostream& os, const sqlpp::optional<T>& t) {
std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional<T>& t) {
if (not t)
return os << "NULL";
return os << t.value();
@ -107,8 +107,8 @@ int Sample(int, char*[])
.from(tab)
.unconditionally()))
{
sqlpp::optional<int64_t> x = row.alpha;
sqlpp::optional<int64_t> a = row.max;
sqlpp::compat::optional<int64_t> x = row.alpha;
sqlpp::compat::optional<int64_t> a = row.max;
std::cout << x << ", " << a << std::endl;
}
tx.commit();

View File

@ -42,7 +42,7 @@ namespace sql = sqlpp::sqlite3;
const auto tab = TabSample{};
template <typename T>
std::ostream& operator<<(std::ostream& os, const sqlpp::optional<T>& t) {
std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional<T>& 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<int64_t> x = row.alpha;
const sqlpp::optional<sqlpp::string_view> a = row.trim;
const sqlpp::compat::optional<int64_t> x = row.alpha;
const sqlpp::compat::optional<sqlpp::compat::string_view> a = row.trim;
std::cout << ">>>" << x << ", " << a << std::endl;
}

View File

@ -38,7 +38,7 @@ namespace sql = sqlpp::sqlite3;
const auto tab = TabSample{};
template <typename T>
std::ostream& operator<<(std::ostream& os, const sqlpp::optional<T>& t) {
std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional<T>& t) {
if (not t)
return os << "NULL";
return os << t.value();

View File

@ -40,7 +40,7 @@ namespace sql = sqlpp::sqlite3;
const auto tab = TabSample{};
template <typename T>
std::ostream& operator<<(std::ostream& os, const sqlpp::optional<T>& t) {
std::ostream& operator<<(std::ostream& os, const sqlpp::compat::optional<T>& t) {
if (not t)
return os << "NULL";
return os << t.value();