From 27c00a8cbbfb684630a8977ccd1b007d9e69d441 Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Sat, 4 Sep 2010 16:49:23 +0200 Subject: Core/DBLayer: - Allow transactions to contain both raw ad-hoc queries and prepared statement elements * When coding on high level code, just make sure you use the right argument type for Transaction::Append and the proper execution will be done automagically --HG-- branch : trunk --- src/server/shared/Database/Transaction.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/server/shared/Database/Transaction.h') diff --git a/src/server/shared/Database/Transaction.h b/src/server/shared/Database/Transaction.h index 58c87b61270..cd749b0c2d7 100644 --- a/src/server/shared/Database/Transaction.h +++ b/src/server/shared/Database/Transaction.h @@ -21,6 +21,30 @@ #include "SQLOperation.h" +//- Forward declare (don't include header to prevent circular includes) +class PreparedStatement; + +//- Union that holds element data +union TransactionElementUnion +{ + PreparedStatement* stmt; + const char* query; +}; + +//- Type specifier of our element data +enum TransactionElementDataType +{ + TRANSACTION_ELEMENT_RAW, + TRANSACTION_ELEMENT_PREPARED, +}; + +//- The transaction element +struct TransactionElementData +{ + TransactionElementUnion element; + TransactionElementDataType type; +}; + /*! Transactions, high level class. */ class Transaction { @@ -28,6 +52,7 @@ class Transaction public: ~Transaction() { Cleanup(); } + void Append(PreparedStatement* statement); void Append(const char* sql); void PAppend(const char* sql, ...); @@ -35,7 +60,7 @@ class Transaction protected: void Cleanup(); - std::queue m_queries; + std::queue m_queries; private: bool m_actioned; -- cgit v1.2.3