handle connection lost/server gone error when starting a transaction

This commit is contained in:
Guenter Obiltschnig 2016-09-15 12:02:52 +02:00
parent 00b448a0c5
commit f3e0bf540d

View File

@ -150,8 +150,17 @@ void SessionHandle::close()
void SessionHandle::startTransaction()
{
if (mysql_autocommit(_pHandle, false) != 0)
throw TransactionException("Start transaction failed.", _pHandle);
int rc = mysql_autocommit(_pHandle, false);
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);
}