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:
parent
60042c2dd3
commit
be3292b6ce
@ -55,6 +55,16 @@ namespace sqlpp
|
||||
using _traits = make_traits<no_value_t>;
|
||||
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() {};
|
||||
|
||||
template<typename Db>
|
||||
@ -69,15 +79,15 @@ namespace sqlpp
|
||||
return _methods_t::_prepare(db, *this);
|
||||
}
|
||||
|
||||
custom_query_t(Parts... parts):
|
||||
_parts(parts...)
|
||||
{}
|
||||
static constexpr size_t _get_static_no_of_parameters()
|
||||
{
|
||||
return std::tuple_size<parameters_of<custom_query_t>>::value;
|
||||
}
|
||||
|
||||
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;
|
||||
size_t _get_no_of_parameters() const
|
||||
{
|
||||
return _get_static_no_of_parameters();
|
||||
}
|
||||
|
||||
std::tuple<Parts...> _parts;
|
||||
};
|
||||
|
@ -62,7 +62,7 @@ namespace sqlpp
|
||||
-> decltype(db.insert(composite))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ namespace sqlpp
|
||||
auto _run(Db& db, const Composite& composite) const -> void
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace sqlpp
|
||||
-> decltype(db.remove(composite))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ namespace sqlpp
|
||||
-> result_t<decltype(db.select(composite)), _result_row_t<Db>>
|
||||
{
|
||||
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()};
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace sqlpp
|
||||
-> decltype(db.update(composite))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -42,10 +42,14 @@ int main()
|
||||
db(c);
|
||||
|
||||
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();
|
||||
auto x = custom_query(sqlpp::verbatim<sqlpp::boolean>("PRAGMA writeable_schema") == true);
|
||||
std::cerr << serialize(x, printer).str() << std::endl;
|
||||
db(x);
|
||||
|
||||
db.prepare(x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -112,6 +112,15 @@ struct MockDbT: public sqlpp::connection
|
||||
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>
|
||||
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>
|
||||
_prepared_statement_t prepare_insert(Insert& x)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user