0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Cleaned a bit of messy _run() code.

This commit is contained in:
rbock 2014-06-20 18:20:24 +02:00
parent 1d82cf7f09
commit 06d1783d81
3 changed files with 36 additions and 51 deletions

View File

@ -41,7 +41,39 @@ namespace sqlpp
struct insert_name_t {}; struct insert_name_t {};
struct insert_t: public statement_name_t<insert_name_t> struct insert_t: public statement_name_t<insert_name_t>
{}; {
using _traits = make_traits<no_value_t, tag::return_value>;
struct _name_t {};
template<typename Policies>
struct _result_methods_t
{
using _statement_t = typename Policies::_statement_t;
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
template<typename Db>
auto _run(Db& db) const -> decltype(db.insert(_get_statement()))
{
_statement_t::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead");
return db.insert(_get_statement());
}
template<typename Db>
auto _prepare(Db& db) const
-> prepared_insert_t<Db, _statement_t>
{
_statement_t::_check_consistency();
return {{}, db.prepare_insert(_get_statement())};
}
};
};
template<typename Context> template<typename Context>
struct serializer_t<Context, insert_name_t> struct serializer_t<Context, insert_name_t>

View File

@ -57,7 +57,7 @@ namespace sqlpp
template<typename Database, typename Table> template<typename Database, typename Table>
struct single_table_t struct single_table_t
{ {
using _traits = make_traits<no_value_t, ::sqlpp::tag::single_table, tag::return_value>; using _traits = make_traits<no_value_t, ::sqlpp::tag::single_table>;
using _recursive_traits = make_recursive_traits<Table>; using _recursive_traits = make_recursive_traits<Table>;
static_assert(is_table_t<Table>::value, "argument has to be a table"); static_assert(is_table_t<Table>::value, "argument has to be a table");
@ -97,53 +97,6 @@ namespace sqlpp
{ {
}; };
template<typename Policies>
struct _result_methods_t
{
using _statement_t = typename Policies::_statement_t;
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
static constexpr size_t _get_static_no_of_parameters()
{
#warning need to fix this
return 0;
//return _parameter_list_t::size::value;
}
size_t _get_no_of_parameters() const
{
#warning need to fix this
return 0;
//return _parameter_list_t::size::value;
}
void _check_consistency() const
{
// FIXME: Read up on what is allowed/prohibited in INSERT
}
template<typename Db>
auto _run(Db& db) const -> decltype(db.insert(_get_statement()))
{
_check_consistency();
static_assert(_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead");
return db.insert(_get_statement());
}
template<typename Db>
auto _prepare(Db& db) const
-> prepared_insert_t<Db, _statement_t>
{
_check_consistency();
return {{}, db.prepare_insert(_get_statement())};
}
};
}; };
// NO INTO YET // NO INTO YET

View File

@ -62,7 +62,7 @@ namespace sqlpp
_statement_t::_check_consistency(); _statement_t::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead"); static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead");
return db.update(*this); return db.update(_get_statement());
} }
template<typename Db> template<typename Db>
@ -71,7 +71,7 @@ namespace sqlpp
{ {
_statement_t::_check_consistency(); _statement_t::_check_consistency();
return {{}, db.prepare_update(*this)}; return {{}, db.prepare_update(_get_statement())};
} }
}; };
}; };