Helper class to run SQL query on existing MySQL database server connection, receive all data and all errors, warnings and notes returned during query execution.
More...
#include <mysql_query_runner.h>
|
| Mysql_query_runner (MYSQL *connection) |
| Standard constructor based on MySQL connection. More...
|
|
| Mysql_query_runner (const Mysql_query_runner &source) |
| Copy constructor. More...
|
|
| ~Mysql_query_runner () |
|
Mysql_query_runner & | add_result_callback (std::function< int64(const Row &)> *result_callback) |
| Adds new callback to be called on every result row of query. More...
|
|
Mysql_query_runner & | add_message_callback (std::function< int64(const Message_data &)> *message_callback, std::function< void()> cleanup_callback=nullptr) |
| Adds new callback to be called on every message after query execution, this includes errors, warnings and other notes. More...
|
|
int64 | run_query (std::string query) |
| Runs specified query and processes result rows and messages to callbacks. More...
|
|
int64 | run_query_store (std::string query, std::vector< const Row * > *result) |
| Runs specified query, fills result vector with processed result rows and processes messages to callbacks. More...
|
|
int64 | run_query (std::string query, std::function< int64(const Row &)> *result_callback) |
| Runs specified query with result callback specified. More...
|
|
std::string | escape_string (const std::string &original) |
| Returns escaped copy of string to use in queries. More...
|
|
void | append_escape_string (std::string *destination_string, const std::string &original) |
| Escapes specified input string and appends it escaped to destination string. More...
|
|
void | append_escape_string (std::string *destination_string, const char *original, size_t original_length) |
| Escapes specified input string specified as characters buffer and its size, and appends it escaped to destination string. More...
|
|
MYSQL * | get_low_level_connection () const |
|
|
static void | append_hex_string (std::string *destination_string, const char *original, size_t original_length) |
| Converts to HEX specified input string specified as characters buffer and its size, and appends it escaped to destination string. More...
|
|
static void | cleanup_result (const Row &result) |
| Empties memory used by result strings. More...
|
|
static void | cleanup_result (std::vector< const Row * > *result) |
| Empties memory used by result strings. More...
|
|
Helper class to run SQL query on existing MySQL database server connection, receive all data and all errors, warnings and notes returned during query execution.
All acquired information is passed to set of callbacks to make data flows more customizable.
◆ Mysql_query_runner() [1/2]
Mysql_query_runner::Mysql_query_runner |
( |
MYSQL * |
connection | ) |
|
|
explicit |
Standard constructor based on MySQL connection.
◆ Mysql_query_runner() [2/2]
◆ ~Mysql_query_runner()
Mysql_query_runner::~Mysql_query_runner |
( |
| ) |
|
◆ add_message_callback()
Adds new callback to be called on every message after query execution, this includes errors, warnings and other notes.
Return value from callback of 0 will lead to next handler being called, positive number return value will cause Mysql_query_runner::run_query() will return immediately this value and negative number will continue query execution and other messages processing, but will not pass current message to rest of callbacks. Callbacks are called in reverse order of addition, i.e. newest are first.
The optional cleanup function is called when the callback is deleted.
◆ add_result_callback()
Adds new callback to be called on every result row of query.
If callback return value other than 0 then query execution, passing current row to other callbacks and error messages processing, and Mysql_query_runner::run_query() will return value returned from this callback. Callbacks are called in reverse order of addition, i.e. newest are first.
◆ append_escape_string() [1/2]
void Mysql_query_runner::append_escape_string |
( |
std::string * |
destination_string, |
|
|
const char * |
original, |
|
|
size_t |
original_length |
|
) |
| |
Escapes specified input string specified as characters buffer and its size, and appends it escaped to destination string.
◆ append_escape_string() [2/2]
void Mysql_query_runner::append_escape_string |
( |
std::string * |
destination_string, |
|
|
const std::string & |
original |
|
) |
| |
Escapes specified input string and appends it escaped to destination string.
◆ append_hex_string()
void Mysql_query_runner::append_hex_string |
( |
std::string * |
destination_string, |
|
|
const char * |
original, |
|
|
size_t |
original_length |
|
) |
| |
|
static |
Converts to HEX specified input string specified as characters buffer and its size, and appends it escaped to destination string.
◆ cleanup_result() [1/2]
void Mysql_query_runner::cleanup_result |
( |
const Row & |
result | ) |
|
|
static |
Empties memory used by result strings.
◆ cleanup_result() [2/2]
void Mysql_query_runner::cleanup_result |
( |
std::vector< const Row * > * |
result | ) |
|
|
static |
Empties memory used by result strings.
◆ escape_string()
std::string Mysql_query_runner::escape_string |
( |
const std::string & |
original | ) |
|
Returns escaped copy of string to use in queries.
◆ get_low_level_connection()
MYSQL * Mysql_query_runner::get_low_level_connection |
( |
| ) |
const |
◆ get_message_type_from_severity()
enum Message_type Mysql_query_runner::get_message_type_from_severity |
( |
std::string |
severity | ) |
|
|
private |
Returns parsed Message_type from given MySQL severity string.
◆ report_message()
Creates error message from mysql_errno and mysql_error and passes it to callbacks.
◆ report_mysql_error()
int64 Mysql_query_runner::report_mysql_error |
( |
| ) |
|
|
private |
Creates error message from mysql_errno and mysql_error and passes it to callbacks.
◆ run_query() [1/2]
int64 Mysql_query_runner::run_query |
( |
std::string |
query | ) |
|
Runs specified query and processes result rows and messages to callbacks.
◆ run_query() [2/2]
int64 Mysql_query_runner::run_query |
( |
std::string |
query, |
|
|
std::function< int64(const Row &)> * |
result_callback |
|
) |
| |
Runs specified query with result callback specified.
Does not add specified callback to list of callbacks, next queries will not process rows to this callback.
◆ run_query_store()
int64 Mysql_query_runner::run_query_store |
( |
std::string |
query, |
|
|
std::vector< const Row * > * |
result |
|
) |
| |
Runs specified query, fills result vector with processed result rows and processes messages to callbacks.
◆ run_query_unguarded()
int64 Mysql_query_runner::run_query_unguarded |
( |
std::string |
query | ) |
|
|
private |
Runs specified query and process result rows and messages to callbacks.
Does not check for multiple queries being executed in parallel.
◆ m_connection
MYSQL* Mysql::Tools::Base::Mysql_query_runner::m_connection |
|
private |
◆ m_is_original_runner
bool Mysql::Tools::Base::Mysql_query_runner::m_is_original_runner |
|
private |
Indicates if this is original runner or a copy.
In case of original the cleanup is performed on destruction.
◆ m_is_processing
std::atomic<bool>* Mysql::Tools::Base::Mysql_query_runner::m_is_processing |
|
private |
Indicates if there is query currently executed.
Only one query can be executed in specified time moment.
◆ m_message_callbacks
std::vector<std::pair<std::function<int64(const Message_data &)> *, std::function<void()> > > Mysql::Tools::Base::Mysql_query_runner::m_message_callbacks |
|
private |
◆ m_result_callbacks
std::vector<std::function<int64(const Row &)> *> Mysql::Tools::Base::Mysql_query_runner::m_result_callbacks |
|
private |
The documentation for this class was generated from the following files: