mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-20 05:49:04 +02:00
[SF 2580108] Improve transaction handling
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user