crawlserv++
[under development]
Application for crawling and analyzing textual content of websites.
|
RAII wrapper for prepared MySQL statements. More...
#include <PreparedSqlStatement.hpp>
Construction and Destruction | |
PreparedSqlStatement ()=default | |
Default constructor creating an empty statement. More... | |
PreparedSqlStatement (sql::Connection *setConnection, std::string_view sqlQuery) | |
Constructor preparing a MySQL statement for the given connection and SQL query. More... | |
virtual | ~PreparedSqlStatement () |
Destructor clearing the prepared MySQL statement if necessary. More... | |
Getters | |
sql::PreparedStatement & | get () |
Gets a reference to the prepared MySQL statement. More... | |
bool | valid () const noexcept |
Checks whether the prepared MySQL statement is valid. More... | |
Lifetime | |
void | prepare () |
Prepares the MySQL statement. More... | |
void | clear () |
Clears the prepared MySQL statement. More... | |
void | refresh (sql::Connection *newConnection) |
Refreshes the prepared MySQL statement using the new connection given. More... | |
Copy and Move | |
PreparedSqlStatement (PreparedSqlStatement &)=delete | |
Deleted copy constructor. More... | |
PreparedSqlStatement & | operator= (PreparedSqlStatement &)=delete |
Deleted copy assignment operator. More... | |
PreparedSqlStatement (PreparedSqlStatement &&other) noexcept | |
Move constructor. More... | |
PreparedSqlStatement & | operator= (PreparedSqlStatement &&other) noexcept |
Move assignment operator. More... | |
RAII wrapper for prepared MySQL statements.
Prepares the statement on creation and clears it on destruction using a smart pointer, avoiding memory leaks.
Additionally stores the underlying SQL statement as string, to be able to re-create it on connection loss.
At the moment, this class is used exclusively by the Main::Database class.
For more information about the MySQL Connector/C++ used, visit its website.
|
default |
Default constructor creating an empty statement.
|
inline |
Constructor preparing a MySQL statement for the given connection and SQL query.
setConnection | A pointer to the MySQL connection to use. |
sqlQuery | A string view containing the SQL query to prepare. |
References prepare().
|
inlinevirtual |
Destructor clearing the prepared MySQL statement if necessary.
References clear().
|
delete |
Deleted copy constructor.
|
inlinenoexcept |
Move constructor.
Moves the prepared MySQL statement from the specified location into this instance of the class.
other | The prepared MySQL statement to move from. |
|
inline |
Clears the prepared MySQL statement.
The prepared MySQL statement will be invalid and valid() will return false afterwards.
Referenced by operator=(), prepare(), refresh(), and ~PreparedSqlStatement().
|
inline |
Gets a reference to the prepared MySQL statement.
std::runtime_error | if the MySQL statement is invalid. |
|
delete |
Deleted copy assignment operator.
|
inlinenoexcept |
Move assignment operator.
Moves the prepared MySQL statement from the specified location into this instance of the class.
If there already is a prepared MySQL statement in this instance of the class, it will be cleared.
other | The prepared MySQL statement to move from. |
References clear().
|
inline |
Prepares the MySQL statement.
If a statement has been prepared before, it will be cleared if necessary.
References clear().
Referenced by PreparedSqlStatement(), and refresh().
|
inline |
Refreshes the prepared MySQL statement using the new connection given.
The old prepared MySQL statement will be cleared before setting the new connection and preparing the same SQL query using the new connection.
This function is used to handle connection losses, which will invalidate the previous connection pointer.
newConnection | A pointer to the new connection, which will be used from now on. |
|
inlinenoexcept |
Checks whether the prepared MySQL statement is valid.