The Battle for Wesnoth  1.19.0-dev
Public Member Functions | Private Member Functions | Private Attributes | List of all members
dbconn Class Reference

This class is responsible for handling the database connections as well as executing queries and handling any results. More...

#include <dbconn.hpp>

Public Member Functions

 dbconn (const config &c)
 Initializes the synchronous query connection as well as the account object that has the connection settings. More...
 
int async_test_query (int limit)
 
std::string get_uuid ()
 
std::string get_tournaments ()
 
std::unique_ptr< simple_wml::documentget_game_history (int player_id, int offset, std::string search_game_name, int search_content_type, std::string search_content)
 This is an asynchronous query that is executed on a separate connection to retrieve the game history for the provided player. More...
 
bool user_exists (const std::string &name)
 
long get_forum_id (const std::string &name)
 
bool extra_row_exists (const std::string &name)
 
bool is_user_in_group (const std::string &name, int group_id)
 
std::string get_user_string (const std::string &table, const std::string &column, const std::string &name)
 
int get_user_int (const std::string &table, const std::string &column, const std::string &name)
 
void write_user_int (const std::string &column, const std::string &name, int value)
 The provided value is updated if a row exists or a new row inserted otherwise. More...
 
ban_check get_ban_info (const std::string &name, const std::string &ip)
 
void insert_game_info (const std::string &uuid, int game_id, const std::string &version, const std::string &name, int reload, int observers, int is_public, int has_password)
 
void update_game_end (const std::string &uuid, int game_id, const std::string &replay_location)
 
void insert_game_player_info (const std::string &uuid, int game_id, const std::string &username, int side_number, int is_host, const std::string &faction, const std::string &version, const std::string &source, const std::string &current_user, const std::string &leaders)
 
unsigned long long insert_game_content_info (const std::string &uuid, int game_id, const std::string &type, const std::string &name, const std::string &id, const std::string &addon_id, const std::string &addon_version)
 
void set_oos_flag (const std::string &uuid, int game_id)
 
bool topic_id_exists (int topic_id)
 
void insert_addon_info (const std::string &instance_version, const std::string &id, const std::string &name, const std::string &type, const std::string &version, bool forum_auth, int topic_id, const std::string uploader)
 
unsigned long long insert_login (const std::string &username, const std::string &ip, const std::string &version)
 
void update_logout (unsigned long long login_id)
 
void get_users_for_ip (const std::string &ip, std::ostringstream *out)
 
void get_ips_for_user (const std::string &username, std::ostringstream *out)
 
void update_addon_download_count (const std::string &instance_version, const std::string &id, const std::string &version)
 
bool is_user_author (const std::string &instance_version, const std::string &id, const std::string &username, int is_primary)
 
void delete_addon_authors (const std::string &instance_version, const std::string &id)
 
void insert_addon_author (const std::string &instance_version, const std::string &id, const std::string author, int is_primary)
 
bool do_any_authors_exist (const std::string &instance_version, const std::string &id)
 

Private Member Functions

void log_sql_exception (const std::string &text, const mariadb::exception::base &e)
 This is used to write out error text when an SQL-related exception occurs. More...
 
mariadb::connection_ref create_connection ()
 Creates a new connection object from the account. More...
 
void get_complex_results (mariadb::connection_ref connection, rs_base &base, const std::string &sql, const sql_parameters &params)
 Queries can return data with various types that can't be easily fit into a pre-determined structure. More...
 
std::string get_single_string (mariadb::connection_ref connection, const std::string &sql, const sql_parameters &params)
 
long get_single_long (mariadb::connection_ref connection, const std::string &sql, const sql_parameters &params)
 
bool exists (mariadb::connection_ref connection, const std::string &sql, const sql_parameters &params)
 
mariadb::result_set_ref select (mariadb::connection_ref connection, const std::string &sql, const sql_parameters &params)
 Executes a select statement. More...
 
unsigned long long modify (mariadb::connection_ref connection, const std::string &sql, const sql_parameters &params)
 Executes non-select statements (ie: insert, update, delete). More...
 
unsigned long long modify_get_id (mariadb::connection_ref connection, const std::string &sql, const sql_parameters &params)
 Executes non-select statements (ie: insert, update, delete), but primarily intended for inserts that return a generated ID. More...
 
mariadb::statement_ref query (mariadb::connection_ref connection, const std::string &sql, const sql_parameters &params)
 For a given connection, set the provided SQL and parameters on a statement. More...
 

Private Attributes

mariadb::account_ref account_
 The account used to connect to the database. More...
 
mariadb::connection_ref connection_
 The actual connection to the database. More...
 
std::string db_users_table_
 The name of the table that contains forum user information. More...
 
std::string db_banlist_table_
 The name of the table that contains forum ban information. More...
 
std::string db_extra_table_
 The name of the table that contains additional user information. More...
 
std::string db_game_info_table_
 The name of the table that contains game-level information. More...
 
std::string db_game_player_info_table_
 The name of the table that contains player-level information per game. More...
 
std::string db_game_content_info_table_
 The name of the table that contains game content information. More...
 
std::string db_user_group_table_
 The name of the table that contains forum group information. More...
 
std::string db_tournament_query_
 The text of the SQL query to use to retrieve any currently active tournaments. More...
 
std::string db_topics_table_
 The name of the table that contains phpbb forum thread information. More...
 
std::string db_addon_info_table_
 The name of the table that contains add-on information. More...
 
std::string db_connection_history_table_
 The name of the table that contains user connection history. More...
 
std::string db_addon_authors_table_
 The name of the table that contains the add-on authors information. More...
 

Detailed Description

This class is responsible for handling the database connections as well as executing queries and handling any results.

Note
The account and connection should never ever be provided to anything outside of this class.
!DO NOT APPEND VALUES DIRECTLY TO THE SQL TEXT IN ANY QUERY!

Definition at line 39 of file dbconn.hpp.

Constructor & Destructor Documentation

◆ dbconn()

dbconn::dbconn ( const config c)

Initializes the synchronous query connection as well as the account object that has the connection settings.

Parameters
cThe config object to read information from.

Member Function Documentation

◆ async_test_query()

int dbconn::async_test_query ( int  limit)
See also
forum_user_handler::async_test_query().

◆ create_connection()

mariadb::connection_ref dbconn::create_connection ( )
private

Creates a new connection object from the account.

◆ delete_addon_authors()

void dbconn::delete_addon_authors ( const std::string &  instance_version,
const std::string &  id 
)
See also
forum_user_handler::db_delete_addon_authors().

◆ do_any_authors_exist()

bool dbconn::do_any_authors_exist ( const std::string &  instance_version,
const std::string &  id 
)
See also
forum_user_handler::do_any_authors_exist().

◆ exists()

bool dbconn::exists ( mariadb::connection_ref  connection,
const std::string &  sql,
const sql_parameters params 
)
private
Parameters
connectionThe database connecion that will be used to execute the query.
sqlThe SQL text to be executed.
paramsThe parameterized values to be inserted into the query.
Returns
True if any data was returned by the query, otherwise false.

◆ extra_row_exists()

bool dbconn::extra_row_exists ( const std::string &  name)
Parameters
nameThe player's username.
Returns
Whether the player has a row in the extra table.

◆ get_ban_info()

ban_check dbconn::get_ban_info ( const std::string &  name,
const std::string &  ip 
)
See also
forum_user_handler::user_is_banned().

◆ get_complex_results()

void dbconn::get_complex_results ( mariadb::connection_ref  connection,
rs_base base,
const std::string &  sql,
const sql_parameters params 
)
private

Queries can return data with various types that can't be easily fit into a pre-determined structure.

Therefore for queries that can return multiple rows with multiple columns, a class that extends rs_base handles reading the results.

Parameters
connectionThe database connecion that will be used to execute the query.
baseThe class that will handle reading the results.
sqlThe SQL text to be executed.
paramsThe parameterized values to be inserted into the query.

◆ get_forum_id()

long dbconn::get_forum_id ( const std::string &  name)
See also
forum_user_handler::get_forum_id().

◆ get_game_history()

std::unique_ptr<simple_wml::document> dbconn::get_game_history ( int  player_id,
int  offset,
std::string  search_game_name,
int  search_content_type,
std::string  search_content 
)

This is an asynchronous query that is executed on a separate connection to retrieve the game history for the provided player.

Parameters
player_idThe forum ID of the player to get the game history for.
offsetThe offset to provide to the database for where to start returning rows from.
search_game_nameQuery for games matching this name. Supports leading and/or trailing wildcards.
search_content_typeThe content type to query for (ie: scenario)
search_contentQuery for games using this content ID. Supports leading and/or trailing wildcards.
Returns
The simple_wml document containing the query results, or simply the error attribute if an exception is thrown.

◆ get_ips_for_user()

void dbconn::get_ips_for_user ( const std::string &  username,
std::ostringstream *  out 
)
See also
forum_user_handler::get_ips_for_users().

◆ get_single_long()

long dbconn::get_single_long ( mariadb::connection_ref  connection,
const std::string &  sql,
const sql_parameters params 
)
private
Parameters
connectionThe database connecion that will be used to execute the query.
sqlThe SQL text to be executed.
paramsThe parameterized values to be inserted into the query.
Returns
The single long value queried.
Exceptions
mariadb::exception::basewhen the query finds no value to be retrieved.

◆ get_single_string()

std::string dbconn::get_single_string ( mariadb::connection_ref  connection,
const std::string &  sql,
const sql_parameters params 
)
private
Parameters
connectionThe database connecion that will be used to execute the query.
sqlThe SQL text to be executed.
paramsThe parameterized values to be inserted into the query.
Returns
The single string value queried.
Exceptions
mariadb::exception::basewhen the query finds no value to be retrieved.

◆ get_tournaments()

std::string dbconn::get_tournaments ( )
See also
forum_user_handler::get_tournaments().

◆ get_user_int()

int dbconn::get_user_int ( const std::string &  table,
const std::string &  column,
const std::string &  name 
)
Parameters
tableThe table that will be queried.
columnThe column that will be selected.
nameThe player's username.
Returns
The int value in the provided table and column for the provided username.

◆ get_user_string()

std::string dbconn::get_user_string ( const std::string &  table,
const std::string &  column,
const std::string &  name 
)
Parameters
tableThe table that will be queried.
columnThe column that will be selected.
nameThe player's username.
Returns
The string value in the provided table and column for the provided username.

◆ get_users_for_ip()

void dbconn::get_users_for_ip ( const std::string &  ip,
std::ostringstream *  out 
)
See also
forum_user_handler::get_users_for_ip().

◆ get_uuid()

std::string dbconn::get_uuid ( )
See also
forum_user_handler::get_uuid().

◆ insert_addon_author()

void dbconn::insert_addon_author ( const std::string &  instance_version,
const std::string &  id,
const std::string  author,
int  is_primary 
)
See also
forum_user_handler::db_insert_addon_authors().

◆ insert_addon_info()

void dbconn::insert_addon_info ( const std::string &  instance_version,
const std::string &  id,
const std::string &  name,
const std::string &  type,
const std::string &  version,
bool  forum_auth,
int  topic_id,
const std::string  uploader 
)
See also
forum_user_handler::db_insert_addon_info().

◆ insert_game_content_info()

unsigned long long dbconn::insert_game_content_info ( const std::string &  uuid,
int  game_id,
const std::string &  type,
const std::string &  name,
const std::string &  id,
const std::string &  addon_id,
const std::string &  addon_version 
)
See also
forum_user_handler::db_insert_game_content_info().

◆ insert_game_info()

void dbconn::insert_game_info ( const std::string &  uuid,
int  game_id,
const std::string &  version,
const std::string &  name,
int  reload,
int  observers,
int  is_public,
int  has_password 
)
See also
forum_user_handler::db_insert_game_info().

◆ insert_game_player_info()

void dbconn::insert_game_player_info ( const std::string &  uuid,
int  game_id,
const std::string &  username,
int  side_number,
int  is_host,
const std::string &  faction,
const std::string &  version,
const std::string &  source,
const std::string &  current_user,
const std::string &  leaders 
)
See also
forum_user_handler::db_insert_game_player_info().

◆ insert_login()

unsigned long long dbconn::insert_login ( const std::string &  username,
const std::string &  ip,
const std::string &  version 
)
See also
forum_user_handler::db_insert_login().

◆ is_user_author()

bool dbconn::is_user_author ( const std::string &  instance_version,
const std::string &  id,
const std::string &  username,
int  is_primary 
)
See also
forum_user_handler::is_user_primary_author().
forum_user_handler::is_user_secondary_author().

◆ is_user_in_group()

bool dbconn::is_user_in_group ( const std::string &  name,
int  group_id 
)
Parameters
nameThe player's username.
group_idThe forum group ID to check if the user is part of.
Returns
Whether the user is a member of the forum group.

◆ log_sql_exception()

void dbconn::log_sql_exception ( const std::string &  text,
const mariadb::exception::base &  e 
)
private

This is used to write out error text when an SQL-related exception occurs.

Parameters
textSome custom text to log.
eThe exception that occurred which has information about what went wrong.

◆ modify()

unsigned long long dbconn::modify ( mariadb::connection_ref  connection,
const std::string &  sql,
const sql_parameters params 
)
private

Executes non-select statements (ie: insert, update, delete).

Parameters
connectionThe database connecion that will be used to execute the query.
sqlThe SQL text to be executed.
paramsThe parameterized values to be inserted into the query.
Returns
The number of rows modified.

◆ modify_get_id()

unsigned long long dbconn::modify_get_id ( mariadb::connection_ref  connection,
const std::string &  sql,
const sql_parameters params 
)
private

Executes non-select statements (ie: insert, update, delete), but primarily intended for inserts that return a generated ID.

Parameters
connectionThe database connecion that will be used to execute the query.
sqlThe SQL text to be executed.
paramsThe parameterized values to be inserted into the query.
Returns
The value of an AUTO_INCREMENT column on the table being modified.

◆ query()

mariadb::statement_ref dbconn::query ( mariadb::connection_ref  connection,
const std::string &  sql,
const sql_parameters params 
)
private

For a given connection, set the provided SQL and parameters on a statement.

Parameters
connectionThe database connecion that will be used to execute the query.
sqlThe SQL text to be executed.
paramsThe parameterized values to be inserted into the query.
Returns
A statement ready to be executed.

◆ select()

mariadb::result_set_ref dbconn::select ( mariadb::connection_ref  connection,
const std::string &  sql,
const sql_parameters params 
)
private

Executes a select statement.

Parameters
connectionThe database connecion that will be used to execute the query.
sqlThe SQL text to be executed.
paramsThe parameterized values to be inserted into the query.
Returns
A result set containing the results of the select statement executed.

◆ set_oos_flag()

void dbconn::set_oos_flag ( const std::string &  uuid,
int  game_id 
)
See also
forum_user_handler::db_set_oos_flag().

◆ topic_id_exists()

bool dbconn::topic_id_exists ( int  topic_id)
See also
forum_user_handler::db_topic_id_exists().

◆ update_addon_download_count()

void dbconn::update_addon_download_count ( const std::string &  instance_version,
const std::string &  id,
const std::string &  version 
)
See also
forum_user_handler::db_update_addon_download_count().

◆ update_game_end()

void dbconn::update_game_end ( const std::string &  uuid,
int  game_id,
const std::string &  replay_location 
)
See also
forum_user_handler::db_update_game_end().

◆ update_logout()

void dbconn::update_logout ( unsigned long long  login_id)
See also
forum_user_handler::db_update_logout().

◆ user_exists()

bool dbconn::user_exists ( const std::string &  name)
See also
forum_user_handler::user_exists().

◆ write_user_int()

void dbconn::write_user_int ( const std::string &  column,
const std::string &  name,
int  value 
)

The provided value is updated if a row exists or a new row inserted otherwise.

Parameters
columnThe column that the value will be put into.
nameThe player's username.
valueThe value to be put into the column.

Member Data Documentation

◆ account_

mariadb::account_ref dbconn::account_
private

The account used to connect to the database.

Also contains the connection settings.

Note
settings put on the connection, rather than the account, are NOT kept if a reconnect occurs!

Definition at line 216 of file dbconn.hpp.

◆ connection_

mariadb::connection_ref dbconn::connection_
private

The actual connection to the database.

Definition at line 218 of file dbconn.hpp.

◆ db_addon_authors_table_

std::string dbconn::db_addon_authors_table_
private

The name of the table that contains the add-on authors information.

Definition at line 243 of file dbconn.hpp.

◆ db_addon_info_table_

std::string dbconn::db_addon_info_table_
private

The name of the table that contains add-on information.

Definition at line 239 of file dbconn.hpp.

◆ db_banlist_table_

std::string dbconn::db_banlist_table_
private

The name of the table that contains forum ban information.

Definition at line 223 of file dbconn.hpp.

◆ db_connection_history_table_

std::string dbconn::db_connection_history_table_
private

The name of the table that contains user connection history.

Definition at line 241 of file dbconn.hpp.

◆ db_extra_table_

std::string dbconn::db_extra_table_
private

The name of the table that contains additional user information.

Definition at line 225 of file dbconn.hpp.

◆ db_game_content_info_table_

std::string dbconn::db_game_content_info_table_
private

The name of the table that contains game content information.

Definition at line 231 of file dbconn.hpp.

◆ db_game_info_table_

std::string dbconn::db_game_info_table_
private

The name of the table that contains game-level information.

Definition at line 227 of file dbconn.hpp.

◆ db_game_player_info_table_

std::string dbconn::db_game_player_info_table_
private

The name of the table that contains player-level information per game.

Definition at line 229 of file dbconn.hpp.

◆ db_topics_table_

std::string dbconn::db_topics_table_
private

The name of the table that contains phpbb forum thread information.

Definition at line 237 of file dbconn.hpp.

◆ db_tournament_query_

std::string dbconn::db_tournament_query_
private

The text of the SQL query to use to retrieve any currently active tournaments.

Definition at line 235 of file dbconn.hpp.

◆ db_user_group_table_

std::string dbconn::db_user_group_table_
private

The name of the table that contains forum group information.

Definition at line 233 of file dbconn.hpp.

◆ db_users_table_

std::string dbconn::db_users_table_
private

The name of the table that contains forum user information.

Definition at line 221 of file dbconn.hpp.


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