mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
handle MySQL connection lost/server gone when starting a transaction
This commit is contained in:
parent
dcdcee5afa
commit
e87a8fe962
@ -150,8 +150,17 @@ void SessionHandle::close()
|
|||||||
|
|
||||||
void SessionHandle::startTransaction()
|
void SessionHandle::startTransaction()
|
||||||
{
|
{
|
||||||
if (mysql_autocommit(_pHandle, false) != 0)
|
int rc = mysql_autocommit(_pHandle, false);
|
||||||
throw TransactionException("Start transaction failed.", _pHandle);
|
if (rc != 0)
|
||||||
|
{
|
||||||
|
// retry if connection lost
|
||||||
|
int err = mysql_errno(_pHandle);
|
||||||
|
if (err == 2006 /* CR_SERVER_GONE_ERROR */ || err == 2013 /* CR_SERVER_LOST */)
|
||||||
|
{
|
||||||
|
rc = mysql_autocommit(_pHandle, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rc != 0) throw TransactionException("Start transaction failed.", _pHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user