MySQL 9.7.0
Source Code Documentation
Mysql_connection Class Reference

Mysql client connection wrapper class to connect MySQL, execute SQL query and fetch query results. More...

#include <rpl_mysql_connect.h>

Public Member Functions

 Mysql_connection (THD *thd, Master_info *mi, std::string host, uint port, std::string network_namespace, bool is_io_thread=false)
 Mysql_connection class constructor. More...
 
 ~Mysql_connection ()
 Mysql_connection class destructor. More...
 
bool is_connected ()
 Determine if its connected to mysql server. More...
 
bool reconnect ()
 Re-connect to mysql server. More...
 
MYSQLget_mysql ()
 Get Mysql client connection object. More...
 
MYSQL_RES_TUPLE execute_query (std::string query) const
 Execute given sql query on connected mysql server. More...
 
bool version_compatible () const
 Checks whether the connected source server's version is compatible with the replica's version. More...
 

Private Member Functions

bool safe_connect (THD *thd, Master_info *mi, std::string host, uint port, std::string network_namespace)
 To connect to mysql server. More...
 
bool safe_reconnect (THD *thd, Master_info *mi, bool suppress_warnings, std::string host, uint port)
 To re-connect to mysql server. More...
 

Private Attributes

MYSQLm_conn {nullptr}
 
bool m_connected {false}
 
bool m_init {false}
 
THDm_thd {nullptr}
 
Master_infom_mi {nullptr}
 
std::string m_host
 
uint m_port {0}
 
std::string m_network_namespace
 
bool m_is_io_thread {false}
 

Detailed Description

Mysql client connection wrapper class to connect MySQL, execute SQL query and fetch query results.

Constructor & Destructor Documentation

◆ Mysql_connection()

Mysql_connection::Mysql_connection ( THD thd,
Master_info mi,
std::string  host,
uint  port,
std::string  network_namespace,
bool  is_io_thread = false 
)

Mysql_connection class constructor.

Parameters
[in]thdThe thread object.
[in]mithe pointer to the Master_info object.
[in]hostthe host or ip address for mysql client connection.
[in]portthe port for mysql client connection.
[in]network_namespacethe network_namespace for mysql client connection.
[in]is_io_threadto determine its IO or Monitor IO thread.

◆ ~Mysql_connection()

Mysql_connection::~Mysql_connection ( )

Mysql_connection class destructor.

Member Function Documentation

◆ execute_query()

MYSQL_RES_TUPLE Mysql_connection::execute_query ( std::string  query) const

Execute given sql query on connected mysql server.

Parameters
[in]querysql query to execute.
Returns
result of executed query in rows<cols<result>> format where rows and cols both are std::vector and result is std::string. So other then character strings need to be converted.

◆ get_mysql()

MYSQL * Mysql_connection::get_mysql ( )
inline

Get Mysql client connection object.

Returns
Mysql client connection object.

◆ is_connected()

bool Mysql_connection::is_connected ( )

Determine if its connected to mysql server.

Returns
true if connected, false otherwise.

◆ reconnect()

bool Mysql_connection::reconnect ( )

Re-connect to mysql server.

Returns
true if successfully reconnected, false otherwise.

◆ safe_connect()

bool Mysql_connection::safe_connect ( THD thd,
Master_info mi,
std::string  host,
uint  port,
std::string  network_namespace 
)
private

To connect to mysql server.

Parameters
[in]thdThe thread object.
[in]mithe pointer to the Master_info object.
[in]hostthe host or ip address for mysql client connection.
[in]portthe port for mysql client connection.
[in]network_namespacethe network_namespace for mysql client connection.

◆ safe_reconnect()

bool Mysql_connection::safe_reconnect ( THD thd,
Master_info mi,
bool  suppress_warnings,
std::string  host,
uint  port 
)
private

To re-connect to mysql server.

Parameters
[in]thdThe thread object.
[in]mithe pointer to the Master_info object.
[in]suppress_warningsSuppress reconnect warning
[in]hostthe host or ip address for mysql client connection.
[in]portthe port for mysql client connection.

◆ version_compatible()

bool Mysql_connection::version_compatible ( ) const

Checks whether the connected source server's version is compatible with the replica's version.

Return values
trueThe source and replica versions are compatible. false The versions are incompatible or the connection is not initialized.

Member Data Documentation

◆ m_conn

MYSQL* Mysql_connection::m_conn {nullptr}
private

◆ m_connected

bool Mysql_connection::m_connected {false}
private

◆ m_host

std::string Mysql_connection::m_host
private

◆ m_init

bool Mysql_connection::m_init {false}
private

◆ m_is_io_thread

bool Mysql_connection::m_is_io_thread {false}
private

◆ m_mi

Master_info* Mysql_connection::m_mi {nullptr}
private

◆ m_network_namespace

std::string Mysql_connection::m_network_namespace
private

◆ m_port

uint Mysql_connection::m_port {0}
private

◆ m_thd

THD* Mysql_connection::m_thd {nullptr}
private

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