Added default constructor to result field types

This commit is contained in:
Roland Bock
2013-12-15 18:52:05 +01:00
parent 9597c3712c
commit 2b43d3bc15
4 changed files with 30 additions and 16 deletions
+3 -3
View File
@@ -103,19 +103,19 @@ namespace sqlpp
return _is_null;
}
bool value() const
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
return _value;
}
operator bool() const { return value(); }
operator _cpp_value_type() const { return value(); }
private:
bool _is_valid;
bool _is_null;
bool _value;
_cpp_value_type _value;
};
template<typename T>
+10 -3
View File
@@ -52,6 +52,13 @@ namespace sqlpp
struct _result_entry_t
{
using _value_type = floating_point;
_result_entry_t():
_is_valid(false),
_is_null(true),
_value(0)
{}
_result_entry_t(const raw_result_row_t& row):
_is_valid(row.data != nullptr),
_is_null(row.data == nullptr or row.data[index] == nullptr),
@@ -81,19 +88,19 @@ namespace sqlpp
return _is_null;
}
double value() const
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
return _value;
}
operator double() const { return value(); }
operator _cpp_value_type() const { return value(); }
private:
bool _is_valid;
bool _is_null;
double _value;
_cpp_value_type _value;
};
struct plus_
+10 -3
View File
@@ -52,6 +52,13 @@ namespace sqlpp
struct _result_entry_t
{
using _value_type = integral;
_result_entry_t():
_is_valid(false),
_is_null(true),
_value(0)
{}
_result_entry_t(const raw_result_row_t& row):
_is_valid(row.data != nullptr),
_is_null(row.data == nullptr or row.data[index] == nullptr),
@@ -81,19 +88,19 @@ namespace sqlpp
return _is_null;
}
int64_t value() const
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
return _value;
}
operator int64_t() const { return value(); }
operator _cpp_value_type() const { return value(); }
private:
bool _is_valid;
bool _is_null;
int64_t _value;
_cpp_value_type _value;
};
template<typename T>
+7 -7
View File
@@ -54,14 +54,14 @@ namespace sqlpp
_result_entry_t(const raw_result_row_t& row):
_is_valid(row.data != nullptr),
_is_null(row.data == nullptr or row.data[index] == nullptr),
_value(_is_null ? "" : std::string(row.data[index], row.data[index] + row.len[index]))
_value(_is_null ? "" : _cpp_value_type(row.data[index], row.data[index] + row.len[index]))
{}
_result_entry_t& operator=(const raw_result_row_t& row)
{
_is_valid = (row.data != nullptr);
_is_null = row.data == nullptr or row.data[index] == nullptr;
_value = _is_null ? "" : std::string(row.data[index], row.data[index] + row.len[index]);
_value = _is_null ? "" : _cpp_value_type(row.data[index], row.data[index] + row.len[index]);
return *this;
}
@@ -73,8 +73,8 @@ namespace sqlpp
bool _is_trivial() const { return value().empty(); }
bool operator==(const std::string& rhs) const { return value() == rhs; }
bool operator!=(const std::string& rhs) const { return not operator==(rhs); }
bool operator==(const _cpp_value_type& rhs) const { return value() == rhs; }
bool operator!=(const _cpp_value_type& rhs) const { return not operator==(rhs); }
bool is_null() const
{
@@ -83,19 +83,19 @@ namespace sqlpp
return _is_null;
}
std::string value() const
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
return _value;
}
operator std::string() const { return value(); }
operator _cpp_value_type() const { return value(); }
private:
bool _is_valid;
bool _is_null;
std::string _value;
_cpp_value_type _value;
};
template<typename T>