The Battle for Wesnoth  1.15.3+dev
account.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 <mariadb++/account.hpp>
13 
14 using namespace mariadb;
15 
16 account::account(const std::string &host_name, const std::string &user_name,
17  const std::string &password, const std::string &schema, u32 port,
18  const std::string &unix_socket)
19  : m_auto_commit(true),
20  m_port(port),
21  m_host_name(host_name),
22  m_user_name(user_name),
23  m_password(password),
24  m_schema(schema),
25  m_unix_socket(unix_socket) {}
26 
27 const std::string &account::host_name() const { return m_host_name; }
28 
29 const std::string &account::user_name() const { return m_user_name; }
30 
31 const std::string &account::password() const { return m_password; }
32 
34 
35 u32 account::port() const { return m_port; }
36 
37 const std::string &account::ssl_key() const { return m_ssl_key; }
38 
40 
41 const std::string &account::ssl_ca() const { return m_ssl_ca; }
42 
44 
45 const std::string &account::ssl_cipher() const { return m_ssl_cipher; }
46 
47 const std::string &account::schema() const { return m_schema; }
48 
50 
51 void account::set_ssl(const std::string &key, const std::string &certificate, const std::string &ca,
52  const std::string &ca_path, const std::string &cipher) {
53  m_ssl_key = key;
54  m_ssl_certificate = certificate;
55  m_ssl_ca = ca;
56  m_ssl_ca_path = ca_path;
57  m_ssl_cipher = cipher;
58 }
59 
60 bool account::auto_commit() const { return m_auto_commit; }
61 
63 
64 bool account::store_result() const { return m_store_result; }
65 
67 
69 
70 const std::string account::option(const std::string &name) const {
71  const map_options_t::const_iterator value = m_options.find(name);
72 
73  // return option value if found
74  return value == m_options.end() ? "" : value->second;
75 }
76 
77 void account::set_option(const std::string &name, const std::string &value) {
78  m_options[name] = value;
79 }
80 
81 void account::clear_options() { m_options.clear(); }
82 
84 
86 
87 void account::set_connect_option(mysql_option option, bool arg) {
88  m_connect_options[option] = std::unique_ptr<option_arg>(new option_arg_bool(arg));
89 }
90 
91 void account::set_connect_option(mysql_option option, int arg) {
92  m_connect_options[option] = std::unique_ptr<option_arg>(new option_arg_int(arg));
93 }
94 
95 void account::set_connect_option(mysql_option option, const std::string &arg) {
96  m_connect_options[option] = std::unique_ptr<option_arg>(new option_arg_string(arg));
97 }
98 
99 
101  const std::string &password, const std::string &schema, u32 port,
102  const std::string &unix_socket) {
103  return account_ref(new account(host_name, user_name, password, schema, port, unix_socket));
104 }
const std::string option(const std::string &name) const
Gets the current value of any named option that was previously set.
Definition: account.cpp:70
const std::string & ssl_cipher() const
Gets the list of allowed SSL ciphers.
Definition: account.cpp:45
std::string m_ssl_ca
Definition: account.hpp:231
std::string m_schema
Definition: account.hpp:227
std::shared_ptr< account > account_ref
Definition: account.hpp:19
void clear_options()
Deletes all stored key/value pairs of named options.
Definition: account.cpp:81
void clear_connect_options()
Deletes all stored key/value pairs of named options.
Definition: account.cpp:85
std::string m_password
Definition: account.hpp:226
std::string m_ssl_key
Definition: account.hpp:229
void set_option(const std::string &name, const std::string &value)
Sets a named option key/value pair.
Definition: account.cpp:77
const std::string & unix_socket() const
Gets the unix socket path to connect to.
Definition: account.cpp:33
std::string m_host_name
Definition: account.hpp:224
std::map< mysql_option, std::unique_ptr< option_arg > > map_connect_options_t
Definition: account.hpp:49
const std::string & password() const
Gets the password of the user to log in with.
Definition: account.cpp:31
u32 port() const
Gets the port to connect to.
Definition: account.cpp:35
account(const std::string &host_name, const std::string &user_name, const std::string &password, const std::string &schema, u32 port, const std::string &unix_sock)
Private account constructor.
Definition: account.cpp:16
bool store_result() const
Gets the current state of the store_result option.
Definition: account.cpp:64
std::string m_unix_socket
Definition: account.hpp:228
std::string m_ssl_certificate
Definition: account.hpp:230
const map_options_t & options() const
Gets a map of all option key/value pairs previously set.
Definition: account.cpp:68
const std::string & host_name() const
Gets the name of the host to connect to.
Definition: account.cpp:27
const std::string & ssl_ca() const
Gets the path to the certificate authority file.
Definition: account.cpp:41
map_options_t m_options
Definition: account.hpp:234
map_connect_options_t m_connect_options
Definition: account.hpp:235
static account_ref create(const std::string &host_name, const std::string &user_name, const std::string &password, const std::string &schema="", u32 port=3306, const std::string &unix_socket="")
Create an account.
Definition: account.cpp:100
std::string m_ssl_ca_path
Definition: account.hpp:232
const map_connect_options_t & connect_options() const
Gets a map of all connect option key/value pairs previously set.
Definition: account.cpp:83
const std::string & ssl_ca_path() const
Gets the path to the directory containing CA files.
Definition: account.cpp:43
const std::string & schema() const
Gets the name of the database to open on connect.
Definition: account.cpp:47
std::string password(const std::string &server, const std::string &login)
void set_schema(const std::string &schema)
Sets the name of the database to open on connect.
Definition: account.cpp:49
std::map< std::string, std::string > map_options_t
Definition: account.hpp:48
void set_auto_commit(bool auto_commit)
Sets the state of the auto_commit option.
Definition: account.cpp:62
const std::string & ssl_certificate() const
Gets the path to the certificate file.
Definition: account.cpp:39
const std::string & ssl_key() const
Gets the path to the key file.
Definition: account.cpp:37
std::string m_user_name
Definition: account.hpp:225
std::string m_ssl_cipher
Definition: account.hpp:233
bool auto_commit() const
Gets the current state of the auto_commit option.
Definition: account.cpp:60
const std::string & user_name() const
Gets the username to log in with.
Definition: account.cpp:29
void set_ssl(const std::string &key, const std::string &certificate, const std::string &ca, const std::string &ca_path, const std::string &cipher)
Set SSL options.
Definition: account.cpp:51
unsigned int u32
Definition: types.hpp:22
void set_store_result(bool store_result)
Sets the state of the store_result option.
Definition: account.cpp:66
void set_connect_option(mysql_option option, bool arg)
Sets a connect option key/value pair with bool argument.
Definition: account.cpp:87