The Battle for Wesnoth  1.15.5+dev
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
mariadb::account Class Reference

Class used to store account and connection information used by mariadb::connection when connecting. More...

#include <account.hpp>

Public Types

typedef std::map< std::string, std::string > map_options_t
 
typedef std::map< mysql_option, std::unique_ptr< option_arg > > map_connect_options_t
 

Public Member Functions

virtual ~account ()
 Destructs the account. More...
 
const std::string & host_name () const
 Gets the name of the host to connect to. More...
 
const std::string & user_name () const
 Gets the username to log in with. More...
 
const std::string & password () const
 Gets the password of the user to log in with. More...
 
const std::string & unix_socket () const
 Gets the unix socket path to connect to. More...
 
const std::string & ssl_key () const
 Gets the path to the key file. More...
 
const std::string & ssl_certificate () const
 Gets the path to the certificate file. More...
 
const std::string & ssl_ca () const
 Gets the path to the certificate authority file. More...
 
const std::string & ssl_ca_path () const
 Gets the path to the directory containing CA files. More...
 
const std::string & ssl_cipher () const
 Gets the list of allowed SSL ciphers. More...
 
u32 port () const
 Gets the port to connect to. More...
 
const std::string & schema () const
 Gets the name of the database to open on connect. More...
 
void set_schema (const std::string &schema)
 Sets the name of the database to open on connect. More...
 
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. More...
 
bool auto_commit () const
 Gets the current state of the auto_commit option. More...
 
void set_auto_commit (bool auto_commit)
 Sets the state of the auto_commit option. More...
 
bool store_result () const
 Gets the current state of the store_result option. More...
 
void set_store_result (bool store_result)
 Sets the state of the store_result option. More...
 
const std::string option (const std::string &name) const
 Gets the current value of any named option that was previously set. More...
 
const map_options_toptions () const
 Gets a map of all option key/value pairs previously set. More...
 
void set_option (const std::string &name, const std::string &value)
 Sets a named option key/value pair. More...
 
void clear_options ()
 Deletes all stored key/value pairs of named options. More...
 
const map_connect_options_tconnect_options () const
 Gets a map of all connect option key/value pairs previously set. More...
 
void set_connect_option (mysql_option option, bool arg)
 Sets a connect option key/value pair with bool argument. More...
 
void set_connect_option (mysql_option option, int arg)
 Sets a connect option key/value pair with int argument. More...
 
void set_connect_option (mysql_option option, const std::string &arg)
 Sets a connect option key/value pair with string argument. More...
 
void clear_connect_options ()
 Deletes all stored key/value pairs of named options. More...
 

Static Public Member Functions

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. More...
 

Private Member Functions

 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. More...
 

Private Attributes

bool m_auto_commit = true
 
bool m_store_result = true
 
u32 m_port
 
std::string m_host_name
 
std::string m_user_name
 
std::string m_password
 
std::string m_schema
 
std::string m_unix_socket
 
std::string m_ssl_key
 
std::string m_ssl_certificate
 
std::string m_ssl_ca
 
std::string m_ssl_ca_path
 
std::string m_ssl_cipher
 
map_options_t m_options
 
map_connect_options_t m_connect_options
 

Detailed Description

Class used to store account and connection information used by mariadb::connection when connecting.

Note that modifying an account after the connection was established is useless.

Definition at line 46 of file account.hpp.

Member Typedef Documentation

◆ map_connect_options_t

typedef std::map<mysql_option, std::unique_ptr<option_arg> > mariadb::account::map_connect_options_t

Definition at line 49 of file account.hpp.

◆ map_options_t

typedef std::map<std::string, std::string> mariadb::account::map_options_t

Definition at line 48 of file account.hpp.

Constructor & Destructor Documentation

◆ ~account()

virtual mariadb::account::~account ( )
inlinevirtual

Destructs the account.

Definition at line 55 of file account.hpp.

References preferences::options(), preferences::password(), mariadb::value::string, and mariadb::option_arg::value().

◆ account()

account::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

Private account constructor.

Definition at line 16 of file account.cpp.

Referenced by create().

Member Function Documentation

◆ auto_commit()

bool account::auto_commit ( ) const

Gets the current state of the auto_commit option.

This option is turned on by default.

Definition at line 60 of file account.cpp.

References m_auto_commit.

Referenced by set_auto_commit().

◆ clear_connect_options()

void account::clear_connect_options ( )

Deletes all stored key/value pairs of named options.

Definition at line 85 of file account.cpp.

References m_connect_options.

◆ clear_options()

void account::clear_options ( )

Deletes all stored key/value pairs of named options.

Definition at line 81 of file account.cpp.

References m_options.

◆ connect_options()

const account::map_connect_options_t & account::connect_options ( ) const

Gets a map of all connect option key/value pairs previously set.

Definition at line 83 of file account.cpp.

References m_connect_options.

◆ create()

account_ref account::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 = "" 
)
static

Create an account.

Parameters
host_nameHostname to connect to
user_nameUsername to log in with
passwordPassword for the user to log in with (may be empty)
schemaDatabase name to select on connect. Can also be set after connecting
portPort of host to connect to (defaults to 3306)
unix_sockPath of unix socket to connect to. If specified, host and port will be ignored

Definition at line 100 of file account.cpp.

References account().

Referenced by SkeletonTest::SetUp().

◆ host_name()

const std::string & account::host_name ( ) const

Gets the name of the host to connect to.

Definition at line 27 of file account.cpp.

References m_host_name.

◆ option()

const std::string account::option ( const std::string &  name) const

Gets the current value of any named option that was previously set.

Returns
Value of the found option or empty string if not found

Definition at line 70 of file account.cpp.

References m_options.

Referenced by set_connect_option().

◆ options()

const account::map_options_t & account::options ( ) const

Gets a map of all option key/value pairs previously set.

Definition at line 68 of file account.cpp.

References m_options.

◆ password()

const std::string & account::password ( ) const

Gets the password of the user to log in with.

Definition at line 31 of file account.cpp.

References m_password.

◆ port()

u32 account::port ( ) const

Gets the port to connect to.

Definition at line 35 of file account.cpp.

References m_port.

◆ schema()

const std::string & account::schema ( ) const

Gets the name of the database to open on connect.

Definition at line 47 of file account.cpp.

References m_schema.

Referenced by set_schema().

◆ set_auto_commit()

void account::set_auto_commit ( bool  auto_commit)

Sets the state of the auto_commit option.

Definition at line 62 of file account.cpp.

References auto_commit(), and m_auto_commit.

◆ set_connect_option() [1/3]

void account::set_connect_option ( mysql_option  option,
bool  arg 
)

Sets a connect option key/value pair with bool argument.

Definition at line 87 of file account.cpp.

References m_connect_options, and option().

◆ set_connect_option() [2/3]

void account::set_connect_option ( mysql_option  option,
int  arg 
)

Sets a connect option key/value pair with int argument.

Definition at line 91 of file account.cpp.

References m_connect_options, and option().

◆ set_connect_option() [3/3]

void account::set_connect_option ( mysql_option  option,
const std::string &  arg 
)

Sets a connect option key/value pair with string argument.

Definition at line 95 of file account.cpp.

References m_connect_options, and option().

◆ set_option()

void account::set_option ( const std::string &  name,
const std::string &  value 
)

Sets a named option key/value pair.

Definition at line 77 of file account.cpp.

References m_options.

◆ set_schema()

void account::set_schema ( const std::string &  schema)

Sets the name of the database to open on connect.

Definition at line 49 of file account.cpp.

References m_schema, and schema().

◆ set_ssl()

void account::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.

All files should be PEM format

Parameters
keyPath to the key file
certificatePath to the certificate file
caPath to the certificate authority file
ca_pathPath to a directory containing CA files
cipherList of allowed SSL ciphers. See MariaDB manual for possible values

Definition at line 51 of file account.cpp.

References m_ssl_ca, m_ssl_ca_path, m_ssl_certificate, m_ssl_cipher, and m_ssl_key.

◆ set_store_result()

void account::set_store_result ( bool  store_result)

Sets the state of the store_result option.

Definition at line 66 of file account.cpp.

References m_store_result, and store_result().

◆ ssl_ca()

const std::string & account::ssl_ca ( ) const

Gets the path to the certificate authority file.

Definition at line 41 of file account.cpp.

References m_ssl_ca.

◆ ssl_ca_path()

const std::string & account::ssl_ca_path ( ) const

Gets the path to the directory containing CA files.

Definition at line 43 of file account.cpp.

References m_ssl_ca_path.

◆ ssl_certificate()

const std::string & account::ssl_certificate ( ) const

Gets the path to the certificate file.

Definition at line 39 of file account.cpp.

References m_ssl_certificate.

◆ ssl_cipher()

const std::string & account::ssl_cipher ( ) const

Gets the list of allowed SSL ciphers.

Definition at line 45 of file account.cpp.

References m_ssl_cipher.

◆ ssl_key()

const std::string & account::ssl_key ( ) const

Gets the path to the key file.

Definition at line 37 of file account.cpp.

References m_ssl_key.

◆ store_result()

bool account::store_result ( ) const

Gets the current state of the store_result option.

When set, the connection uses buffered store (mysql_store_result) instead of unbuffered store (mysql_use_result). This option is turned on by default.

Note: Unbuffered store has some restrictions and might lead to unexpected behavior. See the documentation (https://mariadb.com/kb/en/library/mysql_use_result/) for more information.

Definition at line 64 of file account.cpp.

References m_store_result.

Referenced by set_store_result().

◆ unix_socket()

const std::string & account::unix_socket ( ) const

Gets the unix socket path to connect to.

If this option is set, host and port will be ignored

Definition at line 33 of file account.cpp.

References m_unix_socket.

◆ user_name()

const std::string & account::user_name ( ) const

Gets the username to log in with.

Definition at line 29 of file account.cpp.

References m_user_name.

Member Data Documentation

◆ m_auto_commit

bool mariadb::account::m_auto_commit = true
private

Definition at line 221 of file account.hpp.

Referenced by auto_commit(), and set_auto_commit().

◆ m_connect_options

map_connect_options_t mariadb::account::m_connect_options
private

Definition at line 235 of file account.hpp.

Referenced by clear_connect_options(), connect_options(), and set_connect_option().

◆ m_host_name

std::string mariadb::account::m_host_name
private

Definition at line 224 of file account.hpp.

Referenced by host_name().

◆ m_options

map_options_t mariadb::account::m_options
private

Definition at line 234 of file account.hpp.

Referenced by clear_options(), option(), options(), and set_option().

◆ m_password

std::string mariadb::account::m_password
private

Definition at line 226 of file account.hpp.

Referenced by password().

◆ m_port

u32 mariadb::account::m_port
private

Definition at line 223 of file account.hpp.

Referenced by port().

◆ m_schema

std::string mariadb::account::m_schema
private

Definition at line 227 of file account.hpp.

Referenced by schema(), and set_schema().

◆ m_ssl_ca

std::string mariadb::account::m_ssl_ca
private

Definition at line 231 of file account.hpp.

Referenced by set_ssl(), and ssl_ca().

◆ m_ssl_ca_path

std::string mariadb::account::m_ssl_ca_path
private

Definition at line 232 of file account.hpp.

Referenced by set_ssl(), and ssl_ca_path().

◆ m_ssl_certificate

std::string mariadb::account::m_ssl_certificate
private

Definition at line 230 of file account.hpp.

Referenced by set_ssl(), and ssl_certificate().

◆ m_ssl_cipher

std::string mariadb::account::m_ssl_cipher
private

Definition at line 233 of file account.hpp.

Referenced by set_ssl(), and ssl_cipher().

◆ m_ssl_key

std::string mariadb::account::m_ssl_key
private

Definition at line 229 of file account.hpp.

Referenced by set_ssl(), and ssl_key().

◆ m_store_result

bool mariadb::account::m_store_result = true
private

Definition at line 222 of file account.hpp.

Referenced by set_store_result(), and store_result().

◆ m_unix_socket

std::string mariadb::account::m_unix_socket
private

Definition at line 228 of file account.hpp.

Referenced by unix_socket().

◆ m_user_name

std::string mariadb::account::m_user_name
private

Definition at line 225 of file account.hpp.

Referenced by user_name().


The documentation for this class was generated from the following files: