Commit 676a0a1e authored by Jean Christophe Roques's avatar Jean Christophe Roques
Browse files

MON-13440 sql layers steal promise object and caller must use a future...

MON-13440 sql layers steal promise object and caller must use a future obtained before sql layer call backport 21.10
parent 0bf8ec92
......@@ -188,8 +188,10 @@ void availability_thread::_build_availabilities(time_t midnight) {
_bas_to_rebuild);
try {
std::promise<database::mysql_result> promise;
thread_id = _mysql->run_query_and_get_result(query_str, &promise);
database::mysql_result res(promise.get_future().get());
std::future<database::mysql_result> future = promise.get_future();
thread_id =
_mysql->run_query_and_get_result(query_str, std::move(promise));
database::mysql_result res(future.get());
if (!_mysql->fetch_row(res))
throw msg_fmt("no events matching BAs to rebuild");
first_day = res.value_as_i32(0);
......@@ -215,8 +217,10 @@ void availability_thread::_build_availabilities(time_t midnight) {
query_str = "SELECT MAX(time_id) FROM mod_bam_reporting_ba_availabilities";
try {
std::promise<database::mysql_result> promise;
thread_id = _mysql->run_query_and_get_result(query_str, &promise);
database::mysql_result res(promise.get_future().get());
std::future<database::mysql_result> future = promise.get_future();
thread_id =
_mysql->run_query_and_get_result(query_str, std::move(promise));
database::mysql_result res(future.get());
if (!_mysql->fetch_row(res)) {
log_v2::bam()->error("no availability in table");
throw msg_fmt("no availability in table");
......@@ -277,13 +281,14 @@ void availability_thread::_build_daily_availabilities(int thread_id,
log_v2::bam()->debug("Query: {}", query);
std::promise<database::mysql_result> promise;
_mysql->run_query_and_get_result(query, &promise, thread_id);
std::future<database::mysql_result> future = promise.get_future();
_mysql->run_query_and_get_result(query, std::move(promise), thread_id);
// Create a builder for each ba_id and associated timeperiod_id.
std::map<std::pair<uint32_t, uint32_t>, std::unique_ptr<availability_builder>>
builders;
try {
database::mysql_result res(promise.get_future().get());
database::mysql_result res(future.get());
while (_mysql->fetch_row(res)) {
uint32_t ba_id = res.value_as_i32(1);
uint32_t timeperiod_id = res.value_as_i32(6);
......@@ -335,11 +340,12 @@ void availability_thread::_build_daily_availabilities(int thread_id,
: "");
log_v2::bam()->debug("Query: {}", query);
promise = std::promise<database::mysql_result>();
_mysql->run_query_and_get_result(query, &promise, thread_id);
std::promise<database::mysql_result> promise_ba;
std::future<database::mysql_result> future_ba = promise_ba.get_future();
_mysql->run_query_and_get_result(query, std::move(promise_ba), thread_id);
try {
database::mysql_result res(promise.get_future().get());
database::mysql_result res(future_ba.get());
while (_mysql->fetch_row(res)) {
uint32_t ba_id = res.value_as_i32(1);
// Get all the timeperiods associated with the ba of this event.
......
......@@ -122,9 +122,10 @@ void reader_v2::_load(state::kpis& kpis) {
" AND pr.poller_id={}",
config::applier::state::instance().poller_id()));
std::promise<database::mysql_result> promise;
_mysql.run_query_and_get_result(query, &promise, 0);
std::future<database::mysql_result> future = promise.get_future();
_mysql.run_query_and_get_result(query, std::move(promise), 0);
try {
database::mysql_result res(promise.get_future().get());
database::mysql_result res(future.get());
while (_mysql.fetch_row(res)) {
// KPI object.
uint32_t kpi_id(res.value_as_u32(0));
......@@ -174,9 +175,10 @@ void reader_v2::_load(state::kpis& kpis) {
" WHERE s.service_description='meta_{}'",
it->second.get_meta_id()));
std::promise<database::mysql_result> promise;
_mysql.run_query_and_get_result(query, &promise, 0);
std::future<database::mysql_result> future = promise.get_future();
_mysql.run_query_and_get_result(query, std::move(promise), 0);
try {
database::mysql_result res(promise.get_future().get());
database::mysql_result res(future.get());
if (!_mysql.fetch_row(res))
throw msg_fmt(
"virtual service of meta-service {}"
......@@ -221,9 +223,10 @@ void reader_v2::_load(state::bas& bas, bam::ba_svc_mapping& mapping) {
" AND pr.poller_id={}",
config::applier::state::instance().poller_id()));
std::promise<database::mysql_result> promise;
_mysql.run_query_and_get_result(query, &promise, 0);
std::future<database::mysql_result> future = promise.get_future();
_mysql.run_query_and_get_result(query, std::move(promise), 0);
try {
database::mysql_result res(promise.get_future().get());
database::mysql_result res(future.get());
while (_mysql.fetch_row(res)) {
// BA object.
uint32_t ba_id(res.value_as_u32(0));
......@@ -265,6 +268,7 @@ void reader_v2::_load(state::bas& bas, bam::ba_svc_mapping& mapping) {
// services have for description 'ba_[id]'.
try {
std::promise<database::mysql_result> promise;
std::future<database::mysql_result> future = promise.get_future();
_mysql.run_query_and_get_result(
"SELECT h.host_name, s.service_description,"
" hsr.host_host_id, hsr.service_service_id"
......@@ -274,8 +278,8 @@ void reader_v2::_load(state::bas& bas, bam::ba_svc_mapping& mapping) {
" INNER JOIN host AS h"
" ON hsr.host_host_id=h.host_id"
" WHERE s.service_description LIKE 'ba\\_%'",
&promise, 0);
database::mysql_result res(promise.get_future().get());
std::move(promise), 0);
database::mysql_result res(future.get());
while (_mysql.fetch_row(res)) {
uint32_t host_id = res.value_as_u32(2);
uint32_t service_id = res.value_as_u32(3);
......@@ -340,8 +344,9 @@ void reader_v2::_load(state::bool_exps& bool_exps) {
" AND pr.poller_id={}",
config::applier::state::instance().poller_id()));
std::promise<database::mysql_result> promise;
_mysql.run_query_and_get_result(query, &promise, 0);
database::mysql_result res(promise.get_future().get());
std::future<database::mysql_result> future = promise.get_future();
_mysql.run_query_and_get_result(query, std::move(promise), 0);
database::mysql_result res(future.get());
while (_mysql.fetch_row(res)) {
bool_exps[res.value_as_u32(0)] =
bool_expression(res.value_as_u32(0), // ID.
......@@ -369,14 +374,15 @@ void reader_v2::_load(bam::hst_svc_mapping& mapping) {
try {
// XXX : expand hostgroups and servicegroups
std::promise<database::mysql_result> promise;
std::future<database::mysql_result> future = promise.get_future();
_mysql.run_query_and_get_result(
"SELECT h.host_id, s.service_id, h.host_name, "
"s.service_description,service_activate FROM "
"service s LEFT JOIN host_service_relation hsr ON "
"s.service_id=hsr.service_service_id "
"LEFT JOIN host h ON hsr.host_host_id=h.host_id",
&promise, 0);
database::mysql_result res(promise.get_future().get());
std::move(promise), 0);
database::mysql_result res(future.get());
while (_mysql.fetch_row(res))
mapping.set_service(res.value_as_str(2), res.value_as_str(3),
res.value_as_u32(0), res.value_as_u32(1),
......@@ -407,11 +413,12 @@ void reader_v2::_load_dimensions() {
// Load the timeperiods themselves.
std::promise<database::mysql_result> promise_tp;
std::future<database::mysql_result> future_tp = promise_tp.get_future();
_mysql.run_query_and_get_result(
"SELECT tp_id, tp_name, tp_sunday, tp_monday, tp_tuesday, "
"tp_wednesday, tp_thursday, tp_friday, tp_saturday"
" FROM timeperiod",
&promise_tp, 0);
std::move(promise_tp), 0);
// Load the BAs.
std::string query_ba(
......@@ -426,14 +433,16 @@ void reader_v2::_load_dimensions() {
" AND pr.poller_id={}",
config::applier::state::instance().poller_id()));
std::promise<database::mysql_result> promise_ba;
_mysql.run_query_and_get_result(query_ba, &promise_ba, 0);
std::future<database::mysql_result> future_ba = promise_ba.get_future();
_mysql.run_query_and_get_result(query_ba, std::move(promise_ba), 0);
// Load the BVs.
std::promise<database::mysql_result> promise_bv;
std::future<database::mysql_result> future_bv = promise_bv.get_future();
_mysql.run_query_and_get_result(
"SELECT id_ba_group, ba_group_name, ba_group_description"
" FROM mod_bam_ba_groups",
&promise_bv, 0);
std::move(promise_bv), 0);
// Load the BA BV relations.
std::string query(
......@@ -447,7 +456,8 @@ void reader_v2::_load_dimensions() {
" AND pr.poller_id={}",
config::applier::state::instance().poller_id()));
std::promise<database::mysql_result> promise_ba_bv;
_mysql.run_query_and_get_result(query, &promise_ba_bv, 0);
std::future<database::mysql_result> future_ba_bv = promise_ba_bv.get_future();
_mysql.run_query_and_get_result(query, std::move(promise_ba_bv), 0);
// Load the KPIs
// Unfortunately, we need to get the names of the
......@@ -495,16 +505,18 @@ void reader_v2::_load_dimensions() {
" AND pr.poller_id={}",
config::applier::state::instance().poller_id())};
std::promise<database::mysql_result> promise_kpi;
_mysql.run_query_and_get_result(query_kpi, &promise_kpi, 0);
std::future<database::mysql_result> future_kpi = promise_kpi.get_future();
_mysql.run_query_and_get_result(query_kpi, std::move(promise_kpi), 0);
// Load the ba-timeperiods relations.
std::promise<database::mysql_result> promise_ba_tp;
std::future<database::mysql_result> future_ba_tp = promise_ba_tp.get_future();
_mysql.run_query_and_get_result(
"SELECT ba_id, tp_id FROM mod_bam_relations_ba_timeperiods",
&promise_ba_tp, 0);
std::move(promise_ba_tp), 0);
try {
database::mysql_result res(promise_tp.get_future().get());
database::mysql_result res(future_tp.get());
while (_mysql.fetch_row(res)) {
auto tp(std::make_shared<dimension_timeperiod>(res.value_as_u32(0),
res.value_as_str(1)));
......@@ -525,7 +537,7 @@ void reader_v2::_load_dimensions() {
}
try {
database::mysql_result res(promise_ba.get_future().get());
database::mysql_result res(future_ba.get());
while (_mysql.fetch_row(res)) {
auto ba{std::make_shared<dimension_ba_event>()};
ba->ba_id = res.value_as_u32(0);
......@@ -554,7 +566,7 @@ void reader_v2::_load_dimensions() {
}
try {
database::mysql_result res(promise_bv.get_future().get());
database::mysql_result res(future_bv.get());
while (_mysql.fetch_row(res)) {
std::shared_ptr<dimension_bv_event> bv(new dimension_bv_event);
bv->bv_id = res.value_as_u32(0);
......@@ -570,7 +582,7 @@ void reader_v2::_load_dimensions() {
}
try {
database::mysql_result res(promise_ba_bv.get_future().get());
database::mysql_result res(future_ba_bv.get());
while (_mysql.fetch_row(res)) {
std::shared_ptr<dimension_ba_bv_relation_event> babv(
new dimension_ba_bv_relation_event);
......@@ -586,7 +598,7 @@ void reader_v2::_load_dimensions() {
}
try {
database::mysql_result res(promise_kpi.get_future().get());
database::mysql_result res(future_kpi.get());
while (_mysql.fetch_row(res)) {
auto k{std::make_shared<dimension_kpi_event>(res.value_as_u32(0))};
......@@ -629,7 +641,7 @@ void reader_v2::_load_dimensions() {
}
try {
database::mysql_result res(promise_ba_tp.get_future().get());
database::mysql_result res(future_ba_tp.get());
while (_mysql.fetch_row(res)) {
std::shared_ptr<dimension_ba_timeperiod_relation> dbtr(
new dimension_ba_timeperiod_relation);
......
......@@ -356,9 +356,10 @@ void monitoring_stream::_rebuild() {
{
std::string query("SELECT ba_id FROM mod_bam WHERE must_be_rebuild='1'");
std::promise<mysql_result> promise;
_mysql.run_query_and_get_result(query, &promise, 0);
std::future<database::mysql_result> future = promise.get_future();
_mysql.run_query_and_get_result(query, std::move(promise), 0);
try {
mysql_result res(promise.get_future().get());
mysql_result res(future.get());
while (_mysql.fetch_row(res))
bas_to_rebuild.push_back(res.value_as_u32(0));
} catch (std::exception const& e) {
......
......@@ -282,10 +282,11 @@ void reporting_stream::_close_inconsistent_events(char const* event_type,
"NULL AND e1.start_time!=e2.max_start_time",
id, table));
std::promise<mysql_result> promise;
std::future<database::mysql_result> future = promise.get_future();
log_v2::bam()->trace("reporting_stream: query: '{}'", query);
_mysql.run_query_and_get_result(query, &promise);
_mysql.run_query_and_get_result(query, std::move(promise));
try {
mysql_result res(promise.get_future().get());
mysql_result res(future.get());
while (_mysql.fetch_row(res))
events.emplace_back(std::make_pair(
res.value_as_u32(0), static_cast<time_t>(res.value_as_i32(1))));
......@@ -304,9 +305,10 @@ void reporting_stream::_close_inconsistent_events(char const* event_type,
table, id, p.first, p.second));
log_v2::bam()->trace("reporting_stream: query: '{}'", query_str);
std::promise<mysql_result> promise;
_mysql.run_query_and_get_result(query_str, &promise);
std::future<database::mysql_result> future = promise.get_future();
_mysql.run_query_and_get_result(query_str, std::move(promise));
try {
mysql_result res(promise.get_future().get());
mysql_result res(future.get());
if (!_mysql.fetch_row(res))
throw msg_fmt("no event following this one");
......@@ -361,10 +363,11 @@ void reporting_stream::_load_timeperiods() {
"SELECT timeperiod_id, name, sunday, monday, tuesday, wednesday, "
"thursday, friday, saturday FROM mod_bam_reporting_timeperiods");
std::promise<mysql_result> promise;
std::future<database::mysql_result> future = promise.get_future();
log_v2::bam()->trace("reporting_stream: query: '{}'", query);
_mysql.run_query_and_get_result(query, &promise);
_mysql.run_query_and_get_result(query, std::move(promise));
try {
mysql_result res(promise.get_future().get());
mysql_result res(future.get());
while (_mysql.fetch_row(res)) {
_timeperiods.add_timeperiod(
res.value_as_u32(0),
......@@ -385,10 +388,11 @@ void reporting_stream::_load_timeperiods() {
"SELECT timeperiod_id, daterange, timerange FROM "
"mod_bam_reporting_timeperiods_exceptions");
std::promise<mysql_result> promise;
std::future<database::mysql_result> future = promise.get_future();
log_v2::bam()->trace("reporting_stream: query: '{}'", query);
_mysql.run_query_and_get_result(query, &promise);
_mysql.run_query_and_get_result(query, std::move(promise));
try {
mysql_result res(promise.get_future().get());
mysql_result res(future.get());
while (_mysql.fetch_row(res)) {
time::timeperiod::ptr tp =
_timeperiods.get_timeperiod(res.value_as_u32(0));
......@@ -411,10 +415,11 @@ void reporting_stream::_load_timeperiods() {
"SELECT timeperiod_id, excluded_timeperiod_id"
" FROM mod_bam_reporting_timeperiods_exclusions");
std::promise<mysql_result> promise;
std::future<database::mysql_result> future = promise.get_future();
log_v2::bam()->trace("reporting_stream: query: '{}'", query);
_mysql.run_query_and_get_result(query, &promise);
_mysql.run_query_and_get_result(query, std::move(promise));
try {
mysql_result res(promise.get_future().get());
mysql_result res(future.get());
while (_mysql.fetch_row(res)) {
time::timeperiod::ptr tp =
_timeperiods.get_timeperiod(res.value_as_u32(0));
......@@ -439,10 +444,11 @@ void reporting_stream::_load_timeperiods() {
"SELECT ba_id, timeperiod_id, is_default"
" FROM mod_bam_reporting_relations_ba_timeperiods");
std::promise<mysql_result> promise;
std::future<database::mysql_result> future = promise.get_future();
log_v2::bam()->trace("reporting_stream: query: '{}'", query);
_mysql.run_query_and_get_result(query, &promise);
_mysql.run_query_and_get_result(query, std::move(promise));
try {
mysql_result res(promise.get_future().get());
mysql_result res(future.get());
while (_mysql.fetch_row(res))
_timeperiods.add_relation(res.value_as_u32(0), res.value_as_u32(1),
res.value_as_bool(2));
......@@ -624,12 +630,13 @@ void reporting_stream::_process_ba_event(std::shared_ptr<io::data> const& e) {
5, static_cast<uint64_t>(be.start_time.get_time_t()));
std::promise<int> promise;
_mysql.run_statement_and_get_int<int>(_ba_event_update, &promise,
std::future<int> future = promise.get_future();
_mysql.run_statement_and_get_int<int>(_ba_event_update, std::move(promise),
mysql_task::int_type::AFFECTED_ROWS);
// Event was not found, insert one.
try {
if (promise.get_future().get() == 0) {
if (future.get() == 0) {
_ba_full_event_insert.bind_value_as_i32(0, be.ba_id);
_ba_full_event_insert.bind_value_as_i32(1, be.first_level);
_ba_full_event_insert.bind_value_as_u64(
......@@ -644,9 +651,11 @@ void reporting_stream::_process_ba_event(std::shared_ptr<io::data> const& e) {
_ba_full_event_insert.bind_value_as_bool(5, be.in_downtime);
std::promise<uint32_t> result;
std::future<uint32_t> future_r = result.get_future();
_mysql.run_statement_and_get_int<uint32_t>(
_ba_full_event_insert, &result, mysql_task::LAST_INSERT_ID, -1);
uint32_t newba = result.get_future().get();
_ba_full_event_insert, std::move(result), mysql_task::LAST_INSERT_ID,
-1);
uint32_t newba = future_r.get();
// check events for BA
if (_last_inserted_kpi.find(be.ba_id) != _last_inserted_kpi.end()) {
std::map<std::time_t, uint64_t>& m_events =
......@@ -708,12 +717,13 @@ void reporting_stream::_process_ba_duration_event(
_ba_duration_event_update.bind_value_as_i32(7, bde.timeperiod_id);
std::promise<int> promise;
std::future<int> future = promise.get_future();
int thread_id(_mysql.run_statement_and_get_int<int>(
_ba_duration_event_update, &promise,
_ba_duration_event_update, std::move(promise),
mysql_task::int_type::AFFECTED_ROWS));
try {
// Insert if no rows was updated.
if (promise.get_future().get() == 0) {
if (future.get() == 0) {
_ba_duration_event_insert.bind_value_as_u64(
0, static_cast<uint64_t>(bde.start_time.get_time_t()));
_ba_duration_event_insert.bind_value_as_u64(
......@@ -763,11 +773,13 @@ void reporting_stream::_process_kpi_event(std::shared_ptr<io::data> const& e) {
5, static_cast<uint64_t>(ke.start_time.get_time_t()));
std::promise<int> promise;
std::future<int> future = promise.get_future();
int thread_id(_mysql.run_statement_and_get_int<int>(
_kpi_event_update, &promise, mysql_task::int_type::AFFECTED_ROWS));
_kpi_event_update, std::move(promise),
mysql_task::int_type::AFFECTED_ROWS));
// No kpis were updated, insert one.
try {
if (promise.get_future().get() == 0) {
if (future.get() == 0) {
_kpi_full_event_insert.bind_value_as_i32(0, ke.kpi_id);
_kpi_full_event_insert.bind_value_as_u64(
1, static_cast<uint64_t>(ke.start_time.get_time_t()));
......@@ -791,12 +803,13 @@ void reporting_stream::_process_kpi_event(std::shared_ptr<io::data> const& e) {
_kpi_event_link.bind_value_as_u32(2, ke.ba_id);
std::promise<uint64_t> result;
std::future<uint64_t> future_r = result.get_future();
_mysql.run_statement_and_get_int<uint64_t>(
_kpi_event_link, &result, mysql_task::LAST_INSERT_ID, thread_id);
_kpi_event_link, std::move(result), mysql_task::LAST_INSERT_ID,
thread_id);
uint64_t evt_id{
result.get_future()
.get()}; //_kpi_event_link.last_insert_id().toUInt()};
future_r.get()}; //_kpi_event_link.last_insert_id().toUInt()};
_last_inserted_kpi[ke.ba_id].insert({ke.start_time.get_time_t(), evt_id});
}
} catch (std::exception const& e) {
......@@ -1367,10 +1380,11 @@ void reporting_stream::_process_rebuild(std::shared_ptr<io::data> const& e) {
"IS NOT NULL AND ba_id IN ({})",
r.bas_to_rebuild));
std::promise<mysql_result> promise;
std::future<mysql_result> future = promise.get_future();
log_v2::bam()->trace("reporting_stream: query: '{}'", query);
_mysql.run_query_and_get_result(query, &promise);
_mysql.run_query_and_get_result(query, std::move(promise));
try {
mysql_result res(promise.get_future().get());
mysql_result res(future.get());
while (_mysql.fetch_row(res)) {
std::shared_ptr<ba_event> baev(new ba_event);
......
......@@ -60,18 +60,51 @@ class mysql_task {
class mysql_task_commit : public mysql_task {
public:
mysql_task_commit(std::promise<bool>* promise, std::atomic_int& count)
: mysql_task(mysql_task::COMMIT), promise(promise), count(count) {}
std::promise<bool>* promise;
std::atomic_int& count;
/**
* @brief the purpose of this class is to set the future once all connections
* are committed
*
*/
class mysql_task_commit_data {
std::promise<bool> _promise;
std::atomic_int _count;
public:
using pointer = std::shared_ptr<mysql_task_commit_data>;
/**
* @brief Construct a new mysql task commit data object
*
* @param connection_count number of connections to commit
*/
mysql_task_commit_data(int connection_count) : _count(connection_count) {}
bool get() { return _promise.get_future().get(); }
bool set_value(bool value) {
int old = _count.fetch_sub(1);
if (old == 1) { // commit is done on each connection => signal to get
_promise.set_value(value);
return true;
}
return false;
}
};
mysql_task_commit_data::pointer _data;
public:
mysql_task_commit(const mysql_task_commit_data::pointer& data)
: mysql_task(mysql_task::COMMIT), _data(data) {}
bool get() { return _data->get(); }
bool set_value(bool value) { return _data->set_value(value); }
};
class mysql_task_fetch : public mysql_task {
public:
mysql_task_fetch(mysql_result* result, std::promise<bool>* promise)
: mysql_task(mysql_task::FETCH_ROW), result(result), promise(promise) {}
mysql_task_fetch(mysql_result* result, std::promise<bool>&& promise)
: mysql_task(mysql_task::FETCH_ROW),
result(result),
promise(std::move(promise)) {}
mysql_result* result;
std::promise<bool>* promise;
std::promise<bool> promise;
};
class mysql_task_prepare : public mysql_task {
......@@ -93,23 +126,25 @@ class mysql_task_run : public mysql_task {
class mysql_task_run_res : public mysql_task {
public:
mysql_task_run_res(std::string const& q, std::promise<mysql_result>* promise)
: mysql_task(mysql_task::RUN_RES), query(q), promise(promise) {}
mysql_task_run_res(std::string const& q, std::promise<mysql_result>&& promise)
: mysql_task(mysql_task::RUN_RES),
query(q),
promise(std::move(promise)) {}
std::string query;
std::promise<mysql_result>* promise;
std::promise<mysql_result> promise;
};
class mysql_task_run_int : public mysql_task {
public:
mysql_task_run_int(std::string const& q,
std::promise<int>* promise,
std::promise<int>&& promise,
int_type type)
: mysql_task(mysql_task::RUN_INT),
query(q),
promise(promise),
promise(std::move(promise)),
return_type(type) {}
std::string query;
std::promise<int>* promise;
std::promise<int> promise;
int_type return_type;
};
......@@ -134,13 +169,13 @@ class mysql_task_statement : public mysql_task {
class mysql_task_statement_res : public mysql_task {
public:
mysql_task_statement_res(database::mysql_stmt& stmt,
std::promise<mysql_result>* promise)
std::promise<mysql_result>&& promise)
: mysql_task(mysql_task::STATEMENT_RES),
promise(promise),
promise(std::move(promise)),
statement_id(stmt.get_id()),
param_count(stmt.get_param_count()),
bind(stmt.get_bind()) {}
std::promise<mysql_result>* promise;
std::promise<mysql_result> promise;
int statement_id;
int param_count;
std::unique_ptr<database::mysql_bind> bind;
......@@ -150,20 +185,21 @@ template <typename T>
class mysql_task_statement_int : public mysql_task {
public:
mysql_task_statement_int(database::mysql_stmt& stmt,
std::promise<T>* promise,
std::promise<T>&& promise,
int_type type)
: mysql_task((std::is_same<T, int>::value) ? mysql_task::STATEMENT_INT
: (std::is_same<T, int64_t>::value)
? mysql_task::STATEMENT_INT64
: (std::is_same<T, uint32_t>::value)
? mysql_task::STATEMENT_UINT
: mysql_task::STATEMENT_UINT64),
promise(promise),
: mysql_task((std::is_same<T, int>::value)
? mysql_task::STATEMENT_INT
: (std::is_same<T, int64_t>::value)
? mysql_task::STATEMENT_INT64
: (std::is_same<T, uint32_t>::value)
? mysql_task::STATEMENT_UINT
: mysql_task::STATEMENT_UINT64),
promise(std::move(promise)),
return_type(type),
statement_id(stmt.get_id()),
param_count(stmt.get_param_count()),
bind(stmt.get_bind()) {}
std::promise<T>* promise;
std::promise<T> promise;
int_type return_type;
int statement_id;
int param_count;
......
......@@ -43,10 +43,10 @@ class mysql {
bool fatal = false,
int thread = -1);
int run_query_and_get_result(std::string const& query,
std::promise<database::mysql_result>* promise,