AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
TransactionBase Class Reference

#include "Transaction.h"

Inheritance diagram for TransactionBase:
Transaction< T >

Public Member Functions

 TransactionBase ()=default
 
virtual ~TransactionBase ()
 
void Append (std::string_view sql)
 
template<typename... Args>
void Append (std::string_view sql, Args &&... args)
 
std::size_t GetSize () const
 

Protected Member Functions

void AppendPreparedStatement (PreparedStatementBase *statement)
 
void Cleanup ()
 

Protected Attributes

std::vector< SQLElementDatam_queries
 

Private Attributes

bool _cleanedUp {false}
 

Friends

class TransactionTask
 
class MySQLConnection
 
template<typename T >
class DatabaseWorkerPool
 

Detailed Description

Transactions, high level class.

Constructor & Destructor Documentation

◆ TransactionBase()

TransactionBase::TransactionBase ( )
default

◆ ~TransactionBase()

virtual TransactionBase::~TransactionBase ( )
inlinevirtual
41{ Cleanup(); }
void Cleanup()
Definition: Transaction.cpp:50

Member Function Documentation

◆ Append() [1/2]

void TransactionBase::Append ( std::string_view  sql)
34{
35 SQLElementData data = {};
36 data.type = SQL_ELEMENT_RAW;
37 data.element = std::string(sql);
38 m_queries.emplace_back(data);
39}
@ SQL_ELEMENT_RAW
Definition: SQLOperation.h:28
Definition: SQLOperation.h:34
std::variant< PreparedStatementBase *, std::string > element
Definition: SQLOperation.h:35
SQLElementDataType type
Definition: SQLOperation.h:36
std::vector< SQLElementData > m_queries
Definition: Transaction.h:56

References SQLElementData::element, m_queries, SQL_ELEMENT_RAW, and SQLElementData::type.

◆ Append() [2/2]

template<typename... Args>
void TransactionBase::Append ( std::string_view  sql,
Args &&...  args 
)
inline
47 {
48 Append(Acore::StringFormat(sql, std::forward<Args>(args)...));
49 }
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
void Append(std::string_view sql)
Definition: Transaction.cpp:33

References Acore::StringFormat().

◆ AppendPreparedStatement()

void TransactionBase::AppendPreparedStatement ( PreparedStatementBase statement)
protected
43{
44 SQLElementData data = {};
46 data.element = stmt;
47 m_queries.emplace_back(data);
48}
@ SQL_ELEMENT_PREPARED
Definition: SQLOperation.h:29

Referenced by Transaction< T >::Append().

◆ Cleanup()

void TransactionBase::Cleanup ( )
protected
51{
52 // This might be called by explicit calls to Cleanup or by the auto-destructor
53 if (_cleanedUp)
54 return;
55
56 for (SQLElementData& data : m_queries)
57 {
58 switch (data.type)
59 {
61 {
62 try
63 {
64 PreparedStatementBase* stmt = std::get<PreparedStatementBase*>(data.element);
65 ASSERT(stmt);
66
67 delete stmt;
68 }
69 catch (const std::bad_variant_access& ex)
70 {
71 LOG_FATAL("sql.sql", "> PreparedStatementBase not found in SQLElementData. {}", ex.what());
72 ABORT();
73 }
74 }
75 break;
76 case SQL_ELEMENT_RAW:
77 {
78 try
79 {
80 std::get<std::string>(data.element).clear();
81 }
82 catch (const std::bad_variant_access& ex)
83 {
84 LOG_FATAL("sql.sql", "> std::string not found in SQLElementData. {}", ex.what());
85 ABORT();
86 }
87 }
88 break;
89 }
90 }
91
92 m_queries.clear();
93 _cleanedUp = true;
94}
#define LOG_FATAL(filterType__,...)
Definition: Log.h:152
#define ABORT
Definition: Errors.h:76
#define ASSERT
Definition: Errors.h:68
Definition: PreparedStatement.h:69
bool _cleanedUp
Definition: Transaction.h:59

References _cleanedUp, ABORT, ASSERT, LOG_FATAL, m_queries, SQL_ELEMENT_PREPARED, and SQL_ELEMENT_RAW.

◆ GetSize()

std::size_t TransactionBase::GetSize ( ) const
inline
51{ return m_queries.size(); }

Friends And Related Function Documentation

◆ DatabaseWorkerPool

template<typename T >
friend class DatabaseWorkerPool
friend

◆ MySQLConnection

friend class MySQLConnection
friend

◆ TransactionTask

friend class TransactionTask
friend

Member Data Documentation

◆ _cleanedUp

bool TransactionBase::_cleanedUp {false}
private

Referenced by Cleanup().

◆ m_queries

std::vector<SQLElementData> TransactionBase::m_queries
protected