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> #include <optional>
namespace sqlpp namespace sqlpp
{ {
#warning move into compat? namespace compat
{
template <class T> template <class T>
using optional = std::optional<T>; using optional = std::optional<T>;
@ -44,6 +45,7 @@ namespace sqlpp
using std::nullopt; using std::nullopt;
using std::bad_optional_access; using std::bad_optional_access;
} // namespace compat
} // namespace sqlpp } // namespace sqlpp
#else // incomplete backport of std::optional #else // incomplete backport of std::optional
@ -52,6 +54,8 @@ namespace sqlpp
#include <stdexcept> #include <stdexcept>
namespace sqlpp namespace sqlpp
{
namespace compat
{ {
class nullopt_t class nullopt_t
{ {
@ -117,7 +121,8 @@ namespace sqlpp
destroy(); destroy();
} }
~optional() { ~optional()
{
destroy(); destroy();
} }
@ -147,7 +152,8 @@ namespace sqlpp
} }
template <typename... Args> template <typename... Args>
optional& emplace(Args&&... args) { optional& emplace(Args&&... args)
{
create(std::forward<Args>(args)...); create(std::forward<Args>(args)...);
} }
@ -243,6 +249,7 @@ namespace sqlpp
return !right; return !right;
} }
} // namespace compat
} // namespace sqlpp } // namespace sqlpp
#endif #endif

View File

@ -35,20 +35,26 @@
#if CXX_STD_VER >= 202002L #if CXX_STD_VER >= 202002L
#include <span> #include <span>
namespace sqlpp namespace sqlpp
{
namespace compat
{ {
template <typename T> template <typename T>
using span = std::span<T>; using span = std::span<T>;
}
} // namespace sqlpp } // namespace sqlpp
#else // incomplete backport of std::span #else // incomplete backport of std::span
namespace sqlpp namespace sqlpp
{
namespace compat
{ {
template <typename T> template <typename T>
class span class span
{ {
const T* _data = nullptr; const T* _data = nullptr;
size_t _size = 0u; size_t _size = 0u;
public: public:
constexpr span() = default; constexpr span() = default;
constexpr span(const T* data, size_t size) : _data(data), _size(size) constexpr span(const T* data, size_t size) : _data(data), _size(size)
@ -69,9 +75,9 @@ namespace sqlpp
{ {
return *(_data + i); return *(_data + i);
} }
}; };
} // namespace compat
} // namespace sqlpp } // namespace sqlpp
#endif #endif

View File

@ -35,8 +35,11 @@
#if CXX_STD_VER >= 201703L #if CXX_STD_VER >= 201703L
#include <string_view> #include <string_view>
namespace sqlpp namespace sqlpp
{
namespace compat
{ {
using string_view = std::string_view; using string_view = std::string_view;
}
} // namespace sqlpp } // namespace sqlpp
#else // incomplete backport of std::string_view #else // incomplete backport of std::string_view
@ -46,11 +49,14 @@ namespace sqlpp
#include <iosfwd> #include <iosfwd>
namespace sqlpp namespace sqlpp
{
namespace compat
{ {
class string_view class string_view
{ {
const char* _data = nullptr; const char* _data = nullptr;
size_t _size = 0u; size_t _size = 0u;
public: public:
constexpr string_view() = default; constexpr string_view() = default;
string_view(const std::string& source) : _data(source.data()), _size(source.size()) string_view(const std::string& source) : _data(source.data()), _size(source.size())
@ -100,7 +106,7 @@ namespace sqlpp
return os << std::string(sv); return os << std::string(sv);
} }
} // namespace compat
} // namespace sqlpp } // namespace sqlpp
#endif #endif

View File

@ -39,7 +39,7 @@ namespace sqlpp
{ {
using _traits = make_traits<blob, tag::is_value_type>; using _traits = make_traits<blob, tag::is_value_type>;
using _cpp_value_type = std::vector<std::uint8_t>; 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> template <typename T>
using _is_valid_operand = ::sqlpp::logic::any_t<is_blob_t<T>::value, is_text_t<T>::value>; 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 _traits = make_traits<text, tag::is_value_type>;
using _cpp_value_type = std::string; using _cpp_value_type = std::string;
using _result_type = sqlpp::string_view; using _result_type = sqlpp::compat::string_view;
template <typename T> template <typename T>
using _is_valid_operand = is_text_t<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)) text_operand(_value_t t) : _t(std::move(t))
{ {
} }
// allow construction from an sqlpp::string_view // allow construction from an sqlpp::compat::string_view
text_operand(sqlpp::string_view t) : _t(t) text_operand(sqlpp::compat::string_view t) : _t(t)
{ {
} }
// additional const char* overload, required to disambiguate // additional const char* overload, required to disambiguate

View File

@ -49,7 +49,7 @@ namespace sqlpp
target._bind_text_parameter(index, &_value, _is_null); 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; _value = val;
_is_null = false; _is_null = false;

View File

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

View File

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

View File

@ -187,7 +187,7 @@ namespace sqlpp
param.error = &buffer.error; 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) if (_handle->debug)
std::cerr << "MySQL debug: binding text result at index: " << index std::cerr << "MySQL debug: binding text result at index: " << index
@ -205,7 +205,7 @@ namespace sqlpp
param.error = &buffer.error; 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) if (_handle->debug)
std::cerr << "MySQL debug: binding blob result at index: " << index std::cerr << "MySQL debug: binding blob result at index: " << index
@ -266,7 +266,7 @@ namespace sqlpp
} }
template <class T> 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{}; value = T{};
bind_field(index, *value); 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) if (_handle->debug)
std::cerr << "MySQL debug: reading text result at index: " << index std::cerr << "MySQL debug: reading text result at index: " << index
@ -335,10 +335,10 @@ namespace sqlpp
refetch_if_required(index); refetch_if_required(index);
const auto& buffer = _handle->result_buffers[index]; const auto& buffer = _handle->result_buffers[index];
const auto& params = _handle->result_params[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) if (_handle->debug)
std::cerr << "MySQL debug: reading blob result at index: " << index std::cerr << "MySQL debug: reading blob result at index: " << index
@ -346,7 +346,7 @@ namespace sqlpp
refetch_if_required(index); refetch_if_required(index);
const auto& buffer = _handle->result_buffers[index]; const auto& buffer = _handle->result_buffers[index];
const auto& params = _handle->result_params[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) void read_field(size_t index, ::sqlpp::chrono::day_point& value)
@ -386,7 +386,7 @@ namespace sqlpp
} }
template <class T> 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) 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); 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) void read_field(size_t index, ::sqlpp::chrono::day_point& value)
@ -184,7 +184,7 @@ namespace sqlpp
} }
template <typename T> 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; const bool is_null = _char_result_row.data[index] == nullptr;
if (is_null) if (is_null)

View File

@ -242,7 +242,7 @@ namespace sqlpp
value = _handle->result.get_uint64_value(_handle->count, index); 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); const auto index = static_cast<int>(_index);
if (_handle->debug()) if (_handle->debug())
@ -250,7 +250,7 @@ namespace sqlpp
std::cerr << "PostgreSQL debug: reading text result at index: " << index << std::endl; 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))); 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); const auto index = static_cast<int>(_index);
if (_handle->debug()) if (_handle->debug())
@ -347,11 +347,11 @@ namespace sqlpp
detail::hex_assign(_var_buffers[_index], _handle->result.get_blob_value(_handle->count, index), detail::hex_assign(_var_buffers[_index], _handle->result.get_blob_value(_handle->count, index),
static_cast<size_t>(_handle->result.length(_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> 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); const auto index = static_cast<int>(_index);
if (_handle->result.is_null(_handle->count, 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))); 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) if (_handle->debug)
std::cerr << "Sqlite3 debug: binding text result at index: " << index << std::endl; 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))), 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)))); 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) if (_handle->debug)
std::cerr << "Sqlite3 debug: binding blob result at index: " << index << std::endl; 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))), 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)))); static_cast<size_t>(sqlite3_column_bytes(_handle->sqlite_statement, static_cast<int>(index))));
} }
@ -191,7 +191,7 @@ namespace sqlpp
} }
template <typename T> 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; const bool is_null = sqlite3_column_type(_handle->sqlite_statement, static_cast<int>(index)) == SQLITE_NULL;
if (is_null) if (is_null)

View File

@ -47,10 +47,10 @@ int Insert(int, char* [])
"INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")");
compare(__LINE__, insert_into(bar).set(bar.beta = ::sqlpp::null, bar.gamma = true), compare(__LINE__, insert_into(bar).set(bar.beta = ::sqlpp::null, bar.gamma = true),
"INSERT INTO tab_bar (beta,gamma) VALUES(NULL," + getTrue() + ")"); "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), compare(__LINE__, insert_into(bar).set(bar.beta = std::string(cheeseCake), bar.gamma = true),
"INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); "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() + ")"); "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")");
return 0; 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')"); compare(__LINE__, where(bar.beta == std::string("SQL")), " WHERE (tab_bar.beta='SQL')");
// string_view argument // 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; 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))); 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.gamma = true;
prepared_insert_sv.params.delta = 17; 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); db(prepared_insert_sv);
return 0; return 0;

View File

@ -57,8 +57,8 @@ struct to_cerr
template <typename Row> template <typename Row>
void print_row(Row const& row) void print_row(Row const& row)
{ {
const sqlpp::optional<int64_t> a = row.alpha; const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::optional<sqlpp::string_view> b = row.beta; const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.beta;
std::cout << a << ", " << b << std::endl; 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())) for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
{ {
const sqlpp::optional<int64_t> a = row.alpha; const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::optional<sqlpp::string_view> b = row.beta; const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.beta;
std::cout << a << ", " << b << std::endl; std::cout << a << ", " << b << std::endl;
} }
for (const auto& row : 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())) 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::compat::optional<int64_t> a = row.alpha;
const sqlpp::optional<sqlpp::string_view> b = row.beta; const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.beta;
const bool g = row.tabBar; const bool g = row.tabBar;
std::cout << a << ", " << b << ", " << g << std::endl; std::cout << a << ", " << b << ", " << g << std::endl;
} }
@ -154,7 +154,7 @@ int Select(int, char*[])
#warning add tests for optional everything #warning add tests for optional everything
for (const auto& row : db(db.prepare(s))) 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; 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> 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) if (not t)
return os << "NULL"; return os << "NULL";
@ -100,5 +100,5 @@ template <typename T>
struct is_optional : public std::false_type{}; struct is_optional : public std::false_type{};
template <typename T> 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()) if (result.empty())
throw std::runtime_error{"selection result is 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") if (value != "value")
throw std::runtime_error{std::string{"unexpected value: "} + std::string(value ? value.value() : "NULL")}; 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()) if (const auto& row = *result.begin())
{ {
const int64_t a = row.alpha; 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; std::cerr << __LINE__ << " row.alpha: " << a << ", row.max: " << m << std::endl;
} }
tx.commit(); 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()); auto result = db(select(all_of(tab), select(max(tab.alpha)).from(tab)).from(tab).unconditionally());
if (const auto& row = *result.begin()) if (const auto& row = *result.begin())
{ {
sqlpp::optional<long> a = row.alpha; sqlpp::compat::optional<long> a = row.alpha;
sqlpp::optional<long> m = row.max; sqlpp::compat::optional<long> m = row.max;
std::cerr << "-----------------------------" << a << ", " << m << std::endl; std::cerr << "-----------------------------" << a << ", " << m << std::endl;
} }
tx.commit(); 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)); auto result = db(select(blob.data).from(blob).where(blob.id == null_id));
const auto& result_row = result.front(); 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()) if (result_row.data.has_value())
{ {
throw std::runtime_error("Expected NULL blob 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)); auto result = db(select(tab.data).from(tab).where(tab.id == null_id));
const auto& result_row = result.front(); 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; return 0;
} }

View File

@ -78,8 +78,8 @@ int DateTime(int, char*[])
for (const auto& row : db(select(all_of(tab)).from(tab).unconditionally())) for (const auto& row : db(select(all_of(tab)).from(tab).unconditionally()))
{ {
require_equal(__LINE__, row.colDayPoint == sqlpp::nullopt, true); require_equal(__LINE__, row.colDayPoint == sqlpp::compat::nullopt, true);
require_equal(__LINE__, row.colTimePoint == sqlpp::nullopt, true); require_equal(__LINE__, row.colTimePoint == sqlpp::compat::nullopt, true);
} }
db(update(tab).set(tab.colDayPoint = today, tab.colTimePoint = now).unconditionally()); db(update(tab).set(tab.colDayPoint = today, tab.colTimePoint = now).unconditionally());

View File

@ -42,7 +42,7 @@
#include <vector> #include <vector>
template <typename T> 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) if (not t)
return os << "NULL"; return os << "NULL";
return os << t.value(); return os << t.value();

View File

@ -40,7 +40,7 @@ namespace sql = sqlpp::sqlite3;
const auto fp = FpSample{}; const auto fp = FpSample{};
template <typename T> 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) if (not t)
return os << "NULL"; return os << "NULL";
return os << t.value(); return os << t.value();

View File

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

View File

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

View File

@ -38,7 +38,7 @@ namespace sql = sqlpp::sqlite3;
const auto tab = TabSample{}; const auto tab = TabSample{};
template <typename T> 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) if (not t)
return os << "NULL"; return os << "NULL";
return os << t.value(); return os << t.value();

View File

@ -40,7 +40,7 @@ namespace sql = sqlpp::sqlite3;
const auto tab = TabSample{}; const auto tab = TabSample{};
template <typename T> 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) if (not t)
return os << "NULL"; return os << "NULL";
return os << t.value(); return os << t.value();