0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00
Moved check_consistency call to statement
This commit is contained in:
rbock 2014-06-13 09:33:08 +02:00
parent f8e0e90477
commit 4d1b60d93a
6 changed files with 49 additions and 104 deletions

View File

@ -56,31 +56,12 @@ namespace sqlpp
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.remove(_get_statement()))
{
_check_consistency();
_statement_t::_check_consistency();
static_assert(_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead");
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead");
return db.remove(*this);
}

View File

@ -117,13 +117,6 @@ namespace sqlpp
using _provided_tables = detail::type_set<>;
using _extra_tables = detail::type_set<>;
};
static void _check_consistency()
{
#warning check for missing terms here, and for missing tables
static_assert(not required_tables_of<statement_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement");
}
};
}
@ -165,6 +158,27 @@ namespace sqlpp
statement_t& operator=(const statement_t& r) = default;
statement_t& operator=(statement_t&& r) = default;
~statement_t() = default;
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
{
return _get_static_no_of_parameters();
}
static void _check_consistency()
{
// FIXME: Check each "methods" or each member...
#warning check for missing terms here, and for missing tables
static_assert(not required_tables_of<_policies_t>::size::value, "one sub expression requires tables which are otherwise not known in the statement");
}
};
namespace vendor

View File

@ -56,31 +56,12 @@ namespace sqlpp
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.update(_get_statement()))
{
_check_consistency();
_statement_t::_check_consistency();
static_assert(_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);
}
@ -89,9 +70,9 @@ namespace sqlpp
auto _prepare(Db& db) const
-> prepared_update_t<Db, update_t>
{
_check_consistency();
_statement_t::_check_consistency();
return {{}, db.prepare_update(*this)};
return {{}, db.prepare_update(*this)};
}
*/
};

View File

@ -107,44 +107,25 @@ namespace sqlpp
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;
}
template<typename Db>
auto _run(Db& db) const -> decltype(db.insert(_get_statement()))
{
_statement_t::_check_consistency();
size_t _get_no_of_parameters() const
{
#warning need to fix this
return 0;
//return _parameter_list_t::size::value;
}
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead");
return db.insert(*this);
}
void _check_consistency() const
{
// FIXME: Read up on what is allowed/prohibited in INSERT
}
/*
template<typename Db>
auto _prepare(Db& db) const
-> prepared_insert_t<Db, insert_t>
{
_statement_t::_check_consistency();
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(*this);
}
/*
template<typename Db>
auto _prepare(Db& db) const
-> prepared_insert_t<Db, insert_t>
{
_check_consistency();
return {{}, db.prepare_insert(*this)};
}
*/
return {{}, db.prepare_insert(*this)};
}
*/
};
};

View File

@ -281,18 +281,6 @@ namespace sqlpp
return _get_statement().selected_columns._data._dynamic_columns._dynamic_expression_names;
}
static constexpr size_t _get_static_no_of_parameters()
{
#warning need to fix this
return 0;
}
size_t _get_no_of_parameters() const
{
#warning need to fix this
return 0;
}
size_t get_no_of_result_columns() const
{
return sizeof...(Columns) + get_dynamic_names().size();
@ -303,8 +291,8 @@ namespace sqlpp
auto _run(Db& db) const
-> result_t<decltype(db.select(_get_statement())), _result_row_t<Db>>
{
Policies::_check_consistency();
static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead");
_statement_t::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead");
return {db.select(_get_statement()), get_dynamic_names()};
}
@ -315,7 +303,7 @@ namespace sqlpp
auto _prepare(Db& db) const
-> prepared_select_t<Db, select_t>
{
Policies::_check_consistency();
_statement_t::_check_consistency();
return {{}, get_dynamic_names(), db.prepare_select(*this)};
}

View File

@ -8,9 +8,9 @@ endmacro ()
#build_and_run(InterpretTest)
build_and_run(InsertTest)
build_and_run(RemoveTest)
build_and_run(UpdateTest)
build_and_run(SelectTest)
#build_and_run(RemoveTest)
#build_and_run(UpdateTest)
#build_and_run(SelectTest)
#build_and_run(SelectTypeTest)
#build_and_run(FunctionTest)
#build_and_run(PreparedTest)