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

Successfully running the first prepared select statement including result evaluation

This commit is contained in:
Roland Bock 2014-01-03 14:27:06 +01:00
parent 6e5ee56577
commit 099250945c
14 changed files with 94 additions and 35 deletions

View File

@ -52,6 +52,8 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T any; T any;
T& operator()() { return any; }
const T& operator()() const { return any; }
}; };
}; };

View File

@ -51,6 +51,8 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T avg; T avg;
T& operator()() { return avg; }
const T& operator()() const { return avg; }
}; };
}; };

View File

@ -51,6 +51,8 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T count; T count;
T& operator()() { return count; }
const T& operator()() const { return count; }
}; };
}; };

View File

@ -51,6 +51,8 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T exists; T exists;
T& operator()() { return exists; }
const T& operator()() const { return exists; }
}; };
}; };

View File

@ -48,25 +48,31 @@ namespace sqlpp
using _is_expression = std::true_type; using _is_expression = std::true_type;
using _cpp_value_type = double; using _cpp_value_type = double;
template<bool TrivialValueIsNull>
struct _parameter_t struct _parameter_t
{ {
using _value_type = floating_point; using _value_type = integral;
_parameter_t(): _parameter_t(const std::true_type&):
_trivial_value_is_null(true),
_value(0), _value(0),
_is_null(TrivialValueIsNull and _is_trivial()) _is_null(_trivial_value_is_null and _is_trivial())
{}
_parameter_t(const std::false_type&):
_trivial_value_is_null(false),
_value(0),
_is_null(_trivial_value_is_null and _is_trivial())
{} {}
_parameter_t(const _cpp_value_type& value): _parameter_t(const _cpp_value_type& value):
_value(value), _value(value),
_is_null(TrivialValueIsNull and _is_trivial()) _is_null(_trivial_value_is_null and _is_trivial())
{} {}
_parameter_t& operator=(const _cpp_value_type& value) _parameter_t& operator=(const _cpp_value_type& value)
{ {
_value = value; _value = value;
_is_null = (TrivialValueIsNull and _is_trivial()); _is_null = (_trivial_value_is_null and _is_trivial());
return *this; return *this;
} }
@ -90,22 +96,28 @@ namespace sqlpp
return _is_null; return _is_null;
} }
_cpp_value_type value() const const _cpp_value_type& value() const
{ {
return _value; return _value;
} }
operator _cpp_value_type() const { return value(); } operator _cpp_value_type() const { return _value; }
template<typename Target>
void bind(Target& target, size_t index) const
{
target.bind_floating_point_parameter(index, &_value, _is_null);
}
private: private:
bool _trivial_value_is_null;
_cpp_value_type _value; _cpp_value_type _value;
bool _is_null; bool _is_null;
}; };
template<size_t index>
struct _result_entry_t struct _result_entry_t
{ {
using _value_type = floating_point; using _value_type = integral;
_result_entry_t(): _result_entry_t():
_is_valid(false), _is_valid(false),
@ -113,18 +125,24 @@ namespace sqlpp
_value(0) _value(0)
{} {}
_result_entry_t(const char_result_row_t& row): _result_entry_t(const char* data, size_t):
_is_valid(row.data != nullptr), _is_valid(true),
_is_null(row.data == nullptr or row.data[index] == nullptr), _is_null(data == nullptr),
_value(_is_null ? 0 : std::strtod(row.data[index], nullptr)) _value(_is_null ? 0 : std::strtoll(data, nullptr, 10))
{} {}
_result_entry_t& operator=(const char_result_row_t& row) void assign(const char* data, size_t)
{ {
_is_valid = (row.data != nullptr); _is_valid = true;
_is_null = row.data == nullptr or row.data[index] == nullptr; _is_null = data == nullptr;
_value = _is_null ? 0 : std::strtod(row.data[index], nullptr); _value = _is_null ? 0 : std::strtoll(data, nullptr, 10);
return *this; }
void invalidate()
{
_is_valid = false;
_is_null = true;
_value = 0;
} }
template<typename Db> template<typename Db>
@ -151,6 +169,12 @@ namespace sqlpp
operator _cpp_value_type() const { return value(); } operator _cpp_value_type() const { return value(); }
template<typename Target>
void bind(Target& target, size_t i)
{
target.bind_floating_point_result(i, &_value, &_is_null);
}
private: private:
bool _is_valid; bool _is_valid;
bool _is_null; bool _is_null;
@ -243,8 +267,7 @@ namespace sqlpp
}; };
}; };
template<size_t index> inline std::ostream& operator<<(std::ostream& os, const floating_point::_result_entry_t& e)
std::ostream& operator<<(std::ostream& os, const floating_point::_result_entry_t<index>& e)
{ {
return os << e.value(); return os << e.value();
} }

View File

@ -63,13 +63,7 @@ namespace sqlpp
_is_null(_trivial_value_is_null and _is_trivial()) _is_null(_trivial_value_is_null and _is_trivial())
{} {}
_parameter_t(bool trivial_value_is_null): explicit _parameter_t(const _cpp_value_type& value):
_trivial_value_is_null(trivial_value_is_null),
_value(0),
_is_null(_trivial_value_is_null and _is_trivial())
{}
_parameter_t(const _cpp_value_type& value):
_value(value), _value(value),
_is_null(_trivial_value_is_null and _is_trivial()) _is_null(_trivial_value_is_null and _is_trivial())
{} {}
@ -81,11 +75,10 @@ namespace sqlpp
return *this; return *this;
} }
_parameter_t& operator=(const std::nullptr_t&) void set_null()
{ {
_value = 0; _value = 0;
_is_null = true; _is_null = true;
return *this;
} }
template<typename Db> template<typename Db>
@ -150,6 +143,11 @@ namespace sqlpp
_value = 0; _value = 0;
} }
void validate()
{
_is_valid = true;
}
template<typename Db> template<typename Db>
void serialize(std::ostream& os, Db& db) const void serialize(std::ostream& os, Db& db) const
{ {

View File

@ -51,6 +51,8 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T max; T max;
T& operator()() { return max; }
const T& operator()() const { return max; }
}; };
}; };

View File

@ -51,6 +51,8 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T min; T min;
T& operator()() { return min; }
const T& operator()() const { return min; }
}; };
}; };

View File

@ -43,7 +43,7 @@ namespace sqlpp
auto run(Db& db) const auto run(Db& db) const
-> result_t<decltype(db.run_prepared_select(*this)), _result_row_t> -> result_t<decltype(db.run_prepared_select(*this)), _result_row_t>
{ {
return {db.run_prepared_select(*this)}; return {db.run_prepared_select(*this), _dynamic_names};
} }
void bind_params() const void bind_params() const

View File

@ -90,7 +90,7 @@ namespace sqlpp
void operator++() void operator++()
{ {
_result.next(result_row); _result.next(_result_row);
} }
db_result_t& _result; db_result_t& _result;

View File

@ -65,6 +65,12 @@ namespace sqlpp
return *this; return *this;
} }
void validate()
{
_field::operator()().validate();
_rest::validate();
}
void invalidate() void invalidate()
{ {
_field::operator()().invalidate(); _field::operator()().invalidate();
@ -97,14 +103,20 @@ namespace sqlpp
result_row_impl& operator=(const char_result_row_t& char_result_row_t) result_row_impl& operator=(const char_result_row_t& char_result_row_t)
{ {
_multi_field::operator=({char_result_row_t}); _multi_field::operator()() = char_result_row_t;
_rest::operator=(char_result_row_t); _rest::operator=(char_result_row_t);
return *this; return *this;
} }
void validate()
{
_multi_field::operator()().validate();
_rest::validate();
}
void invalidate() void invalidate()
{ {
_multi_field::invalidate(); _multi_field::operator()().invalidate();
_rest::invalidate(); _rest::invalidate();
} }
@ -130,6 +142,10 @@ namespace sqlpp
return *this; return *this;
} }
void validate()
{
}
void invalidate() void invalidate()
{ {
} }
@ -173,6 +189,12 @@ namespace sqlpp
return *this; return *this;
} }
void validate()
{
_impl::validate();
_is_valid = true;
}
void invalidate() void invalidate()
{ {
_impl::invalidate(); _impl::invalidate();

View File

@ -594,7 +594,7 @@ namespace sqlpp
// FIXME: Check for missing aliases (if references are used) // FIXME: Check for missing aliases (if references are used)
// FIXME: Check for missing tables, well, actually, check for missing tables at the where(), order_by(), etc. // FIXME: Check for missing tables, well, actually, check for missing tables at the where(), order_by(), etc.
return {db.select(*this)}; return {db.select(*this), get_dynamic_names()};
} }
template<typename Db> template<typename Db>

View File

@ -52,6 +52,8 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T some; T some;
T& operator()() { return some; }
const T& operator()() const { return some; }
}; };
}; };

View File

@ -51,6 +51,8 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T sum; T sum;
T& operator()() { return sum; }
const T& operator()() const { return sum; }
}; };
}; };