31 #ifndef WRAPPER_PREPAREDSQLSTATEMENT_HPP_ 32 #define WRAPPER_PREPAREDSQLSTATEMENT_HPP_ 34 #include "../Helper/Portability/mysqlcppconn.h" 36 #include <cppconn/prepared_statement.h> 37 #include <mysql_connection.h> 42 #include <string_view> 87 [[nodiscard]] sql::PreparedStatement&
get();
88 [[nodiscard]]
bool valid()
const noexcept;
96 void refresh(sql::Connection * newConnection);
117 sql::Connection * connection{
nullptr};
123 std::unique_ptr<sql::PreparedStatement> ptr;
141 sql::Connection * setConnection,
142 std::string_view sqlQuery
143 ) : connection(setConnection), query(sqlQuery) {
163 if(this->ptr ==
nullptr) {
164 throw std::runtime_error(
"get(): No SQL statement prepared");
176 return this->ptr.operator bool();
194 if(!(this->query.empty())) {
195 this->ptr.reset(this->connection->prepareStatement(this->query));
208 if(this->ptr !=
nullptr) {
230 this->connection = newConnection;
251 : connection(other.connection), query(std::move(other.query)), ptr(std::move(other.ptr)) {}
276 this->connection = other.connection;
278 this->query = std::move(other.query);
280 this->ptr = std::move(other.ptr);
282 other.connection =
nullptr;
void refresh(sql::Connection *newConnection)
Refreshes the prepared MySQL statement using the new connection given.
Definition: PreparedSqlStatement.hpp:227
bool valid() const noexcept
Checks whether the prepared MySQL statement is valid.
Definition: PreparedSqlStatement.hpp:175
void prepare()
Prepares the MySQL statement.
Definition: PreparedSqlStatement.hpp:191
RAII wrapper for prepared MySQL statements.
Definition: PreparedSqlStatement.hpp:68
sql::PreparedStatement & get()
Gets a reference to the prepared MySQL statement.
Definition: PreparedSqlStatement.hpp:162
void clear()
Clears the prepared MySQL statement.
Definition: PreparedSqlStatement.hpp:207
virtual ~PreparedSqlStatement()
Destructor clearing the prepared MySQL statement if necessary.
Definition: PreparedSqlStatement.hpp:148
Namespace for RAII wrappers and Wrapper::Database.
Definition: Database.hpp:109
PreparedSqlStatement()=default
Default constructor creating an empty statement.
PreparedSqlStatement & operator=(PreparedSqlStatement &)=delete
Deleted copy assignment operator.