From 06d1783d81133d1e0773db5009db8c5aeca07b18 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 20 Jun 2014 18:20:24 +0200 Subject: [PATCH] Cleaned a bit of messy _run() code. --- include/sqlpp11/insert.h | 34 ++++++++++++++++++++++- include/sqlpp11/single_table.h | 49 +--------------------------------- include/sqlpp11/update.h | 4 +-- 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 491d9a8c..d1f82eb2 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -41,7 +41,39 @@ namespace sqlpp struct insert_name_t {}; struct insert_t: public statement_name_t - {}; + { + using _traits = make_traits; + struct _name_t {}; + + template + struct _result_methods_t + { + using _statement_t = typename Policies::_statement_t; + + const _statement_t& _get_statement() const + { + return static_cast(*this); + } + + template + 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 + auto _prepare(Db& db) const + -> prepared_insert_t + { + _statement_t::_check_consistency(); + + return {{}, db.prepare_insert(_get_statement())}; + } + }; + }; template struct serializer_t diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index 167323b6..00327fc4 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -57,7 +57,7 @@ namespace sqlpp template struct single_table_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static_assert(is_table_t
::value, "argument has to be a table"); @@ -97,53 +97,6 @@ namespace sqlpp { }; - template - struct _result_methods_t - { - using _statement_t = typename Policies::_statement_t; - - const _statement_t& _get_statement() const - { - return static_cast(*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 - 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 - auto _prepare(Db& db) const - -> prepared_insert_t - { - _check_consistency(); - - return {{}, db.prepare_insert(_get_statement())}; - } - }; }; // NO INTO YET diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index f08e79a6..58bb2b74 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -62,7 +62,7 @@ namespace sqlpp _statement_t::_check_consistency(); 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 @@ -71,7 +71,7 @@ namespace sqlpp { _statement_t::_check_consistency(); - return {{}, db.prepare_update(*this)}; + return {{}, db.prepare_update(_get_statement())}; } }; };