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

Fixed parameter determination and added execution of void statements

This commit is contained in:
rbock 2014-11-05 17:50:46 +01:00
parent 60042c2dd3
commit be3292b6ce
8 changed files with 44 additions and 13 deletions

View File

@ -55,6 +55,16 @@ namespace sqlpp
using _traits = make_traits<no_value_t>; using _traits = make_traits<no_value_t>;
using _recursive_traits = make_recursive_traits<Parts...>; using _recursive_traits = make_recursive_traits<Parts...>;
custom_query_t(Parts... parts):
_parts(parts...)
{}
custom_query_t(const custom_query_t&) = default;
custom_query_t(custom_query_t&&) = default;
custom_query_t& operator=(const custom_query_t&) = default;
custom_query_t& operator=(custom_query_t&&) = default;
~custom_query_t() = default;
static void _check_consistency() {}; static void _check_consistency() {};
template<typename Db> template<typename Db>
@ -69,15 +79,15 @@ namespace sqlpp
return _methods_t::_prepare(db, *this); return _methods_t::_prepare(db, *this);
} }
custom_query_t(Parts... parts): static constexpr size_t _get_static_no_of_parameters()
_parts(parts...) {
{} return std::tuple_size<parameters_of<custom_query_t>>::value;
}
custom_query_t(const custom_query_t&) = default; size_t _get_no_of_parameters() const
custom_query_t(custom_query_t&&) = default; {
custom_query_t& operator=(const custom_query_t&) = default; return _get_static_no_of_parameters();
custom_query_t& operator=(custom_query_t&&) = default; }
~custom_query_t() = default;
std::tuple<Parts...> _parts; std::tuple<Parts...> _parts;
}; };

View File

@ -62,7 +62,7 @@ namespace sqlpp
-> decltype(db.insert(composite)) -> decltype(db.insert(composite))
{ {
Composite::_check_consistency(); Composite::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead"); static_assert(Composite::_get_static_no_of_parameters() == 0, "cannot run insert directly with parameters, use prepare instead");
return db.insert(composite); return db.insert(composite);
} }

View File

@ -56,7 +56,7 @@ namespace sqlpp
auto _run(Db& db, const Composite& composite) const -> void auto _run(Db& db, const Composite& composite) const -> void
{ {
Composite::_check_consistency(); Composite::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run execute directly with parameters, use prepare instead"); static_assert(Composite::_get_static_no_of_parameters() == 0, "cannot run execute directly with parameters, use prepare instead");
return db.execute(composite); return db.execute(composite);
} }

View File

@ -62,7 +62,7 @@ namespace sqlpp
-> decltype(db.remove(composite)) -> decltype(db.remove(composite))
{ {
Composite::_check_consistency(); Composite::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead"); static_assert(Composite::_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead");
return db.remove(composite); return db.remove(composite);
} }

View File

@ -298,7 +298,7 @@ namespace sqlpp
-> result_t<decltype(db.select(composite)), _result_row_t<Db>> -> result_t<decltype(db.select(composite)), _result_row_t<Db>>
{ {
Composite::_check_consistency(); Composite::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead"); static_assert(Composite::_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead");
return {db.select(composite), get_dynamic_names()}; return {db.select(composite), get_dynamic_names()};
} }

View File

@ -62,7 +62,7 @@ namespace sqlpp
-> decltype(db.update(composite)) -> decltype(db.update(composite))
{ {
Composite::_check_consistency(); Composite::_check_consistency();
static_assert(_statement_t::_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead"); static_assert(Composite::_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead");
return db.update(composite); return db.update(composite);
} }

View File

@ -42,10 +42,14 @@ int main()
db(c); db(c);
auto p = db.prepare(custom_query(select(all_of(t)).from(t).where(t.alpha > sqlpp::parameter(t.alpha)))); auto p = db.prepare(custom_query(select(all_of(t)).from(t).where(t.alpha > sqlpp::parameter(t.alpha))));
p.params.alpha = 8;
printer.reset(); printer.reset();
auto x = custom_query(sqlpp::verbatim<sqlpp::boolean>("PRAGMA writeable_schema") == true); auto x = custom_query(sqlpp::verbatim<sqlpp::boolean>("PRAGMA writeable_schema") == true);
std::cerr << serialize(x, printer).str() << std::endl; std::cerr << serialize(x, printer).str() << std::endl;
db(x);
db.prepare(x);
return 0; return 0;
} }

View File

@ -112,6 +112,15 @@ struct MockDbT: public sqlpp::connection
return t._run(*this); return t._run(*this);
} }
void execute(const std::string& command);
template<typename Statement>
void execute(const Statement& x)
{
_serializer_context_t context;
::sqlpp::serialize(x, context);
}
template<typename Insert> template<typename Insert>
size_t insert(const Insert& x) size_t insert(const Insert& x)
{ {
@ -154,6 +163,14 @@ struct MockDbT: public sqlpp::connection
} }
template<typename Statement>
_prepared_statement_t prepare_execute(Statement& x)
{
_serializer_context_t context;
::sqlpp::serialize(x, context);
return nullptr;
}
template<typename Insert> template<typename Insert>
_prepared_statement_t prepare_insert(Insert& x) _prepared_statement_t prepare_insert(Insert& x)
{ {