mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 05:50:42 +02:00
[ticket/14044] Automatically trigger rollback on insert in transaction
This will cause the sqlite3 driver to automatically rollback transactions if an insert fails during a transaction. Other dbms trigger a rollback inside the sql_error() function with a rollback command. However, this manual rollback command might fail on sqlite3 due to ongoing queries. With this change, sqlite3 itself will abort any ongoing queries and initiate the rollback automatically. Since manually triggered rollbacks will fail after the rollback was started automatically, we catch exceptions output by the exec() command during rollback and any exception that might be thrown by fetchArray() due to aborted queries. PHPBB3-14044
This commit is contained in:
committed by
Mate Bartus
parent
d34d6378bc
commit
df53d40922
@@ -102,7 +102,7 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
break;
|
||||
|
||||
case 'rollback':
|
||||
return $this->dbo->exec('ROLLBACK');
|
||||
return @$this->dbo->exec('ROLLBACK');
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -134,6 +134,11 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
|
||||
if ($this->query_result === false)
|
||||
{
|
||||
if ($this->transaction === true && strpos($query, 'INSERT') === 0)
|
||||
{
|
||||
$query = preg_replace('/^INSERT INTO/', 'INSERT OR ROLLBACK INTO', $query);
|
||||
}
|
||||
|
||||
if (($this->query_result = @$this->dbo->query($query)) === false)
|
||||
{
|
||||
// Try to recover a lost database connection
|
||||
@@ -225,6 +230,7 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
|
||||
if ($query_id === false)
|
||||
{
|
||||
/** @var \SQLite3Result $query_id */
|
||||
$query_id = $this->query_result;
|
||||
}
|
||||
|
||||
@@ -233,7 +239,7 @@ class sqlite3 extends \phpbb\db\driver\driver
|
||||
return $cache->sql_fetchrow($query_id);
|
||||
}
|
||||
|
||||
return is_object($query_id) ? $query_id->fetchArray(SQLITE3_ASSOC) : false;
|
||||
return is_object($query_id) ? @$query_id->fetchArray(SQLITE3_ASSOC) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user