diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index a1a36947..85658aeb 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -95,13 +95,20 @@ namespace sqlpp bool _is_trivial() const { return value() == false; } - bool is_null() const { return _is_null; } + bool is_null() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _is_null; + } + bool value() const { if (not _is_valid) throw exception("accessing value in non-existing row"); return _value; } + operator bool() const { return value(); } private: diff --git a/include/sqlpp11/numeric.h b/include/sqlpp11/numeric.h index cfbed5d3..1c9af404 100644 --- a/include/sqlpp11/numeric.h +++ b/include/sqlpp11/numeric.h @@ -72,13 +72,20 @@ namespace sqlpp bool _is_trivial() const { return value() == 0; } - bool is_null() const { return _is_null; } + bool is_null() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _is_null; + } + int64_t value() const { if (not _is_valid) throw exception("accessing value in non-existing row"); return _value; } + operator int64_t() const { return value(); } private: diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 6eeb64ab..0a906486 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -86,13 +86,20 @@ namespace sqlpp bool operator==(const std::string& rhs) const { return value() == rhs; } bool operator!=(const std::string& rhs) const { return not operator==(rhs); } - bool is_null() const { return _is_null; } + bool is_null() const + { + if (not _is_valid) + throw exception("accessing is_null in non-existing row"); + return _is_null; + } + std::string value() const { if (not _is_valid) throw exception("accessing value in non-existing row"); return _value; } + operator std::string() const { return value(); } private: