DB Layer:
- Make SQL Transactions actual objects used in code. (Thanks to Derex for the idea) * Uncommitted transactions will be automatically rolled back and cleaned up using ACE_Refcounted_Auto_Ptr, so no need to call Rollback() in the code. * Prevents recursive transactions and makes developers aware of transactions going on. * Gets rid of unneccesary overhead iterating over a concurrent map. - Some cleanups in affected code, including better usage of transaction control in AH / mail related code to prevent data loss. *** Experimental, use at own risk, recommended to backup your DBs. *** --HG-- branch : trunk
This commit is contained in:
1 parent
a7498d2f56
commit
994186f267
49 files changed
+861
-774
No files matched your search
@@ -16,9 +16,9 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "DatabaseEnv.h"
|
||||
#include "SQLOperation.h"
|
||||
#include "MySQLConnection.h"
|
||||
#include "Log.h"
|
||||
|
||||
/*! Basic, ad-hoc queries. */
|
||||
BasicStatementTask::BasicStatementTask(const char* sql) :
|
||||
@@ -53,53 +53,6 @@ bool BasicStatementTask::Execute()
|
||||
return m_conn->Execute(m_sql);
|
||||
}
|
||||
|
||||
/*! Transactions. */
|
||||
TransactionTask::TransactionTask()
|
||||
{
|
||||
}
|
||||
|
||||
TransactionTask::~TransactionTask()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TransactionTask::ForcefulDelete()
|
||||
{
|
||||
while (!m_queries.empty())
|
||||
{
|
||||
free((void*)const_cast<char*>(m_queries.front()));
|
||||
m_queries.pop();
|
||||
}
|
||||
}
|
||||
|
||||
bool TransactionTask::Execute()
|
||||
{
|
||||
if (m_queries.empty())
|
||||
return false;
|
||||
|
||||
const char* sql;
|
||||
|
||||
m_conn->BeginTransaction();
|
||||
while (!m_queries.empty())
|
||||
{
|
||||
sql = m_queries.front();
|
||||
if (!m_conn->Execute(sql))
|
||||
{
|
||||
free((void*)const_cast<char*>(sql));
|
||||
m_queries.pop();
|
||||
m_conn->RollbackTransaction();
|
||||
ForcefulDelete();
|
||||
return false;
|
||||
}
|
||||
|
||||
free((void*)const_cast<char*>(sql));
|
||||
m_queries.pop();
|
||||
}
|
||||
|
||||
m_conn->CommitTransaction();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLQueryHolder::SetQuery(size_t index, const char *sql)
|
||||
{
|
||||
if (m_queries.size() <= index)
|
||||
|
||||
Reference in new issue
Block a user