mirror of
https://github.com/boostorg/mysql.git
synced 2026-02-17 13:52:18 +00:00
default_completion_tokens
This commit is contained in:
@@ -5,47 +5,47 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "er_network_variant.hpp"
|
||||
#include "er_connection.hpp"
|
||||
#include "er_resultset.hpp"
|
||||
#include "er_statement.hpp"
|
||||
#include "network_result.hpp"
|
||||
#include "streams.hpp"
|
||||
#include "er_impl_common.hpp"
|
||||
#include "get_endpoint.hpp"
|
||||
#include "handler_call_tracker.hpp"
|
||||
#include <boost/mysql/handshake_params.hpp>
|
||||
#include <boost/mysql/connection.hpp>
|
||||
#include <boost/mysql/errc.hpp>
|
||||
#include <boost/mysql/error.hpp>
|
||||
#include <boost/mysql/execute_params.hpp>
|
||||
#include <boost/mysql/statement_base.hpp>
|
||||
#include <boost/mysql/row.hpp>
|
||||
#include <boost/mysql/handshake_params.hpp>
|
||||
#include <boost/mysql/resultset_base.hpp>
|
||||
#include <boost/mysql/connection.hpp>
|
||||
#include <boost/mysql/row.hpp>
|
||||
#include <boost/mysql/row_view.hpp>
|
||||
#include <boost/mysql/rows_view.hpp>
|
||||
#include <boost/mysql/statement_base.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "er_connection.hpp"
|
||||
#include "er_impl_common.hpp"
|
||||
#include "er_network_variant.hpp"
|
||||
#include "er_resultset.hpp"
|
||||
#include "er_statement.hpp"
|
||||
#include "get_endpoint.hpp"
|
||||
#include "handler_call_tracker.hpp"
|
||||
#include "network_result.hpp"
|
||||
#include "streams.hpp"
|
||||
|
||||
using namespace boost::mysql::test;
|
||||
using boost::mysql::row;
|
||||
using boost::mysql::error_code;
|
||||
using boost::mysql::error_info;
|
||||
using boost::mysql::field_view;
|
||||
using boost::mysql::connection_params;
|
||||
using boost::mysql::handshake_params;
|
||||
using boost::mysql::row_view;
|
||||
using boost::mysql::rows_view;
|
||||
|
||||
namespace {
|
||||
|
||||
template <class Callable>
|
||||
auto impl(
|
||||
Callable&& cb
|
||||
) -> network_result<decltype(cb().get())>
|
||||
auto impl(Callable&& cb) -> network_result<decltype(cb().get())>
|
||||
{
|
||||
using R = decltype(cb().get()); // Callable returns a future<R>
|
||||
using R = decltype(cb().get()); // Callable returns a future<R>
|
||||
std::future<R> fut = cb();
|
||||
try
|
||||
{
|
||||
return network_result<R>(
|
||||
error_code(),
|
||||
fut.get()
|
||||
);
|
||||
return network_result<R>(error_code(), fut.get());
|
||||
}
|
||||
catch (const boost::system::system_error& err)
|
||||
{
|
||||
@@ -54,9 +54,7 @@ auto impl(
|
||||
}
|
||||
|
||||
template <class Callable>
|
||||
network_result<no_result> impl_no_result(
|
||||
Callable&& cb
|
||||
)
|
||||
network_result<no_result> impl_no_result(Callable&& cb)
|
||||
{
|
||||
std::future<void> fut = cb();
|
||||
try
|
||||
@@ -74,138 +72,95 @@ template <class Stream>
|
||||
class default_completion_tokens_resultset : public er_resultset_base<Stream>
|
||||
{
|
||||
public:
|
||||
using er_resultset_base<Stream>::er_resultset_base;
|
||||
network_result<bool> read_one(row& output) override
|
||||
network_result<row_view> read_one() override
|
||||
{
|
||||
return impl([&] {
|
||||
return this->r_.async_read_one(output);
|
||||
});
|
||||
return impl([&] { return this->obj().async_read_one(); });
|
||||
}
|
||||
network_result<std::vector<row>> read_many(std::size_t count) override
|
||||
network_result<rows_view> read_some() override
|
||||
{
|
||||
return impl([&] {
|
||||
return this->r_.async_read_many(count);
|
||||
});
|
||||
return impl([&] { return this->obj().async_read_some(); });
|
||||
}
|
||||
network_result<std::vector<row>> read_all() override
|
||||
network_result<rows_view> read_all() override
|
||||
{
|
||||
return impl([&] {
|
||||
return this->r_.async_read_all();
|
||||
});
|
||||
return impl([&] { return this->obj().async_read_all(); });
|
||||
}
|
||||
};
|
||||
|
||||
template <class Stream>
|
||||
network_result<er_resultset_ptr> erase_network_result(
|
||||
network_result<boost::mysql::resultset_base<Stream>>&& r
|
||||
)
|
||||
{
|
||||
return network_result<er_resultset_ptr> (
|
||||
r.err,
|
||||
erase_resultset<default_completion_tokens_resultset>(std::move(r.value))
|
||||
);
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
class default_completion_tokens_statement : public er_statement_base<Stream>
|
||||
{
|
||||
public:
|
||||
using er_statement_base<Stream>::er_statement_base;
|
||||
using resultset_type = boost::mysql::resultset_base<Stream>;
|
||||
|
||||
network_result<er_resultset_ptr> execute_params(
|
||||
const boost::mysql::execute_params<value_list_it>& params
|
||||
network_result<no_result> execute_params(
|
||||
const boost::mysql::execute_params<value_list_it>& params,
|
||||
er_resultset& result
|
||||
) override
|
||||
{
|
||||
return erase_network_result(impl([&] {
|
||||
return this->stmt_.async_execute(params);
|
||||
}));
|
||||
return impl_no_result([&] { return this->obj().async_execute(params, this->cast(result)); }
|
||||
);
|
||||
}
|
||||
network_result<er_resultset_ptr> execute_container(
|
||||
const std::vector<field_view>& values
|
||||
network_result<no_result> execute_collection(
|
||||
const std::vector<field_view>& values,
|
||||
er_resultset& result
|
||||
) override
|
||||
{
|
||||
return erase_network_result(impl([&] {
|
||||
return this->stmt_.async_execute(values);
|
||||
}));
|
||||
return impl_no_result([&] { return this->obj().async_execute(values, this->cast(result)); }
|
||||
);
|
||||
}
|
||||
network_result<no_result> close() override
|
||||
{
|
||||
return impl_no_result([&] {
|
||||
return this->stmt_.async_close();
|
||||
});
|
||||
return impl_no_result([&] { return this->obj().async_close(); });
|
||||
}
|
||||
};
|
||||
|
||||
template <class Stream>
|
||||
network_result<er_statement_ptr> erase_network_result(
|
||||
network_result<boost::mysql::statement_base<Stream>>&& r
|
||||
)
|
||||
{
|
||||
return network_result<er_statement_ptr> (
|
||||
r.err,
|
||||
erase_statement<default_completion_tokens_statement>(std::move(r.value))
|
||||
);
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
class default_completion_tokens_connection : public er_connection_base<Stream>
|
||||
{
|
||||
public:
|
||||
using er_connection_base<Stream>::er_connection_base;
|
||||
using statement_type = boost::mysql::statement_base<Stream>;
|
||||
using resultset_type = boost::mysql::resultset_base<Stream>;
|
||||
|
||||
network_result<no_result> physical_connect(er_endpoint kind) override
|
||||
{
|
||||
return impl_no_result([&] {
|
||||
return this->conn_.next_layer().lowest_layer().async_connect(get_endpoint<Stream>(kind));
|
||||
return this->conn_.stream().lowest_layer().async_connect(get_endpoint<Stream>(kind));
|
||||
});
|
||||
}
|
||||
network_result<no_result> connect(
|
||||
er_endpoint kind,
|
||||
const boost::mysql::connection_params& params
|
||||
) override
|
||||
network_result<no_result> connect(er_endpoint kind, const handshake_params& params) override
|
||||
{
|
||||
return impl_no_result([&] {
|
||||
return this->conn_.async_connect(get_endpoint<Stream>(kind), params);
|
||||
});
|
||||
}
|
||||
network_result<no_result> handshake(const connection_params& params) override
|
||||
network_result<no_result> handshake(const handshake_params& params) override
|
||||
{
|
||||
return impl_no_result([&] { return this->conn_.async_handshake(params); });
|
||||
}
|
||||
network_result<no_result> query(boost::string_view query, er_resultset& result) override
|
||||
{
|
||||
return impl_no_result([&] { return this->conn_.async_query(query, this->cast(result)); });
|
||||
}
|
||||
network_result<no_result> prepare_statement(boost::string_view statement, er_statement& stmt)
|
||||
override
|
||||
{
|
||||
return impl_no_result([&] {
|
||||
return this->conn_.async_handshake(params);
|
||||
return this->conn_.async_prepare_statement(statement, this->cast(stmt));
|
||||
});
|
||||
}
|
||||
network_result<er_resultset_ptr> query(boost::string_view query) override
|
||||
{
|
||||
return erase_network_result(impl([&] {
|
||||
return this->conn_.async_query(query);
|
||||
}));
|
||||
}
|
||||
network_result<er_statement_ptr> prepare_statement(boost::string_view statement) override
|
||||
{
|
||||
return erase_network_result(impl([&] {
|
||||
return this->conn_.async_prepare_statement(statement);
|
||||
}));
|
||||
}
|
||||
network_result<no_result> quit() override
|
||||
{
|
||||
return impl_no_result([&] {
|
||||
return this->conn_.async_quit();
|
||||
});
|
||||
return impl_no_result([&] { return this->conn_.async_quit(); });
|
||||
}
|
||||
network_result<no_result> close() override
|
||||
{
|
||||
return impl_no_result([&] {
|
||||
return this->conn_.async_close();
|
||||
});
|
||||
return impl_no_result([&] { return this->conn_.async_close(); });
|
||||
}
|
||||
};
|
||||
|
||||
template <class Stream>
|
||||
class default_completion_tokens_variant :
|
||||
public er_network_variant_base<Stream, default_completion_tokens_connection>
|
||||
class default_completion_tokens_variant : public er_network_variant_base<
|
||||
Stream,
|
||||
default_completion_tokens_connection,
|
||||
default_completion_tokens_statement,
|
||||
default_completion_tokens_resultset>
|
||||
{
|
||||
public:
|
||||
const char* variant_name() const override { return "default_completion_tokens"; }
|
||||
@@ -213,11 +168,9 @@ public:
|
||||
|
||||
default_completion_tokens_variant<tcp_ssl_future_socket> obj;
|
||||
|
||||
} // anon namespace
|
||||
} // namespace
|
||||
|
||||
void boost::mysql::test::add_default_completion_tokens(
|
||||
std::vector<er_network_variant*>& output
|
||||
)
|
||||
void boost::mysql::test::add_default_completion_tokens(std::vector<er_network_variant*>& output)
|
||||
{
|
||||
output.push_back(&obj);
|
||||
}
|
||||
Reference in New Issue
Block a user