The Battle for Wesnoth  1.15.3+dev
worker.cpp
Go to the documentation of this file.
1 //
2 // M A R I A D B + +
3 //
4 // Copyright Sylvain Rochette Langlois 2013,
5 // Frantisek Boranek 2015,
6 // The ViaDuck Project 2016 - 2018.
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 #include "worker.hpp"
13 
14 using namespace mariadb;
15 using namespace mariadb::concurrency;
16 
17 //
18 // Constructors
19 //
21  : m_keep_handle(false),
22  m_handle(0),
23  m_status(status::removed),
24  m_command(command::query),
25  m_result(0) {}
26 
28  const std::string& query)
29  : m_keep_handle(keep_handle),
30  m_handle(handle),
31  m_status(handle > 0 ? status::waiting : status::removed),
32  m_command(command),
33  m_result(0),
34  m_query(query),
35  m_account(account) {}
36 
39  : m_keep_handle(keep_handle),
40  m_handle(handle),
41  m_status(handle > 0 ? status::waiting : status::removed),
42  m_command(command),
43  m_result(0),
44  m_account(account),
45  m_statement(statement) {}
46 
47 //
48 // Get informations
49 //
51 
52 bool worker::keep_handle() const { return m_keep_handle; }
53 
55 
56 //
57 // Get result / result_set
58 //
59 u64 worker::result() const { return m_result; }
60 
62 
63 //
64 // Do the actual job
65 //
68 
69  try {
72 
73  //
74  // Make sure auto commit mode is on before continuing...
75  //
76  connection->set_auto_commit(true);
77  connection->connect();
78 
79  switch (m_command) {
80  case command::execute:
81  if (m_statement)
82  m_result = m_statement->execute();
83  else
84  m_result = connection->execute(m_query.c_str());
85  break;
86 
87  case command::insert:
88  if (m_statement)
89  m_result = m_statement->insert();
90  else
91  m_result = connection->insert(m_query.c_str());
92  break;
93 
94  case command::query:
95  if (m_statement)
96  m_result_set = m_statement->query();
97  else
98  m_result_set = connection->query(m_query.c_str());
99  break;
100  }
101 
103  } catch (const std::exception& e) {
104  std::cout << e.what() << std::endl;
106  }
107 }
std::shared_ptr< result_set > result_set_ref
Definition: result_set.hpp:219
u64 result() const
Definition: worker.cpp:59
bool m_keep_handle
Definition: worker.hpp:57
result_set_ref result_set() const
Definition: worker.cpp:61
std::shared_ptr< account > account_ref
Definition: account.hpp:19
handle query(const std::string &query, bool keep_handle)
command::type m_command
Definition: worker.hpp:60
handle m_handle
Definition: worker.hpp:58
account_ref m_account
Definition: worker.hpp:63
Class used to store account and connection information used by mariadb::connection when connecting...
Definition: account.hpp:46
handle get_handle() const
Definition: worker.cpp:54
void execute()
Definition: worker.cpp:66
bool keep_handle() const
Definition: worker.cpp:52
status::type status() const
Definition: worker.cpp:50
u64 handle
Definition: types.hpp:38
Class representing a prepared statement with binding functionality.
Definition: statement.hpp:39
static connection_ref create(const account_ref &account)
Creates a new connection using the given account.
Definition: connection.cpp:28
Wraps a Database connection.
Definition: connection.hpp:27
statement_ref m_statement
Definition: worker.hpp:65
unsigned long long u64
Definition: types.hpp:34
std::shared_ptr< connection > connection_ref
Definition: statement.hpp:33
#define e
std::shared_ptr< statement > statement_ref
Definition: statement.hpp:109
result_set_ref m_result_set
Definition: worker.hpp:64
std::string m_query
Definition: worker.hpp:62
status::type m_status
Definition: worker.hpp:59