0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

is_null() throws for invalid rows

result_row objects can be constructed with raw result rows representing
the end of the result set. Field values must not be accessed for such
rows. Thus, is_null() now throws an exception when called for a field of
an invalid row.
This commit is contained in:
Roland Bock 2013-08-15 09:32:24 +02:00
parent 7370f098b0
commit e4bcc27463
3 changed files with 24 additions and 3 deletions

View File

@ -95,13 +95,20 @@ namespace sqlpp
bool _is_trivial() const { return value() == false; } 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 bool value() const
{ {
if (not _is_valid) if (not _is_valid)
throw exception("accessing value in non-existing row"); throw exception("accessing value in non-existing row");
return _value; return _value;
} }
operator bool() const { return value(); } operator bool() const { return value(); }
private: private:

View File

@ -72,13 +72,20 @@ namespace sqlpp
bool _is_trivial() const { return value() == 0; } 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 int64_t value() const
{ {
if (not _is_valid) if (not _is_valid)
throw exception("accessing value in non-existing row"); throw exception("accessing value in non-existing row");
return _value; return _value;
} }
operator int64_t() const { return value(); } operator int64_t() const { return value(); }
private: private:

View File

@ -86,13 +86,20 @@ namespace sqlpp
bool operator==(const std::string& rhs) const { return value() == rhs; } bool operator==(const std::string& rhs) const { return value() == rhs; }
bool operator!=(const std::string& rhs) const { return not operator==(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 std::string value() const
{ {
if (not _is_valid) if (not _is_valid)
throw exception("accessing value in non-existing row"); throw exception("accessing value in non-existing row");
return _value; return _value;
} }
operator std::string() const { return value(); } operator std::string() const { return value(); }
private: private: