[SF 2580108] Improve transaction handling

This commit is contained in:
Aleksandar Fabijanic
2009-02-08 23:14:54 +00:00
parent ad543acb58
commit d11f007d23
41 changed files with 3484 additions and 2142 deletions

View File

@@ -44,12 +44,8 @@ namespace MySQL {
SessionHandle::SessionHandle(MYSQL* mysql)
{
h = mysql_init(mysql);
if (!h)
{
if (!(_pHandle = mysql_init(mysql)))
throw ConnectionException("mysql_init error");
}
}
@@ -61,74 +57,54 @@ SessionHandle::~SessionHandle()
void SessionHandle::options(mysql_option opt)
{
int res = mysql_options(h, opt, 0);
if (res != 0)
{
throw ConnectionException("mysql_options error", h);
}
if (mysql_options(_pHandle, opt, 0) != 0)
throw ConnectionException("mysql_options error", _pHandle);
}
void SessionHandle::options(mysql_option opt, bool b)
{
my_bool tmp = b;
int res = mysql_options(h, opt, &tmp);
if (res != 0)
{
throw ConnectionException("mysql_options error", h);
}
if (mysql_options(_pHandle, opt, &tmp) != 0)
throw ConnectionException("mysql_options error", _pHandle);
}
void SessionHandle::connect(const char* host, const char* user, const char* password, const char* db, unsigned int port)
{
if (!mysql_real_connect(h, host, user, password, db, port, 0, 0))
{
throw ConnectionException("create session: mysql_real_connect error", h);
}
if (!mysql_real_connect(_pHandle, host, user, password, db, port, 0, 0))
throw ConnectionException("create session: mysql_real_connect error", _pHandle);
}
void SessionHandle::close()
{
if (h)
if (_pHandle)
{
mysql_close(h);
h = 0;
mysql_close(_pHandle);
_pHandle = 0;
}
}
void SessionHandle::startTransaction()
{
int res = mysql_autocommit(h, false);
if (res != 0)
{
throw TransactionException("Start transaction failed.", h);
}
if (mysql_autocommit(_pHandle, false) != 0)
throw TransactionException("Start transaction failed.", _pHandle);
}
void SessionHandle::commit()
{
int res = mysql_commit(h);
if (res != 0)
{
throw TransactionException("Commit failed.", h);
}
if (mysql_commit(_pHandle) != 0)
throw TransactionException("Commit failed.", _pHandle);
}
void SessionHandle::rollback()
{
int res = mysql_rollback(h);
if (res != 0)
{
throw TransactionException("Rollback failed.", h);
}
if (mysql_rollback(_pHandle) != 0)
throw TransactionException("Rollback failed.", _pHandle);
}