From 2276c1c0f246a39dee8d0e979c89e8de0ee7a5de Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 22 Jun 2014 18:08:38 +0200 Subject: [ticket/12387] Cleanup *_free_result call and remove @ on that call PHPBB3-12387 --- phpBB/phpbb/db/driver/sqlite3.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/db/driver/sqlite3.php') diff --git a/phpBB/phpbb/db/driver/sqlite3.php b/phpBB/phpbb/db/driver/sqlite3.php index 2c6bf99497..4ca3d8f91d 100644 --- a/phpBB/phpbb/db/driver/sqlite3.php +++ b/phpBB/phpbb/db/driver/sqlite3.php @@ -50,7 +50,7 @@ class sqlite3 extends \phpbb\db\driver\driver $this->dbo = new \SQLite3($this->server, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); $this->db_connect_id = true; } - catch (Exception $e) + catch (\Exception $e) { return array('message' => $e->getMessage()); } @@ -138,6 +138,11 @@ class sqlite3 extends \phpbb\db\driver\driver $this->sql_report('stop', $query); } + if (!$this->query_result) + { + return false; + } + if ($cache && $cache_ttl) { $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -362,9 +367,12 @@ class sqlite3 extends \phpbb\db\driver\driver $endtime = $endtime[0] + $endtime[1]; $result = $this->dbo->query($query); - while ($void = $result->fetchArray(SQLITE3_ASSOC)) + if ($result) { - // Take the time spent on parsing rows into account + while ($void = $result->fetchArray(SQLITE3_ASSOC)) + { + // Take the time spent on parsing rows into account + } } $splittime = explode(' ', microtime()); -- cgit v1.2.1 From e0d06ee83ebf9ae72ef9746385155168fb083fa9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Oct 2015 11:27:03 +0200 Subject: [ticket/14044] Fix Sqlite error in tests PHPBB3-14044 --- phpBB/phpbb/db/driver/sqlite3.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/db/driver/sqlite3.php') diff --git a/phpBB/phpbb/db/driver/sqlite3.php b/phpBB/phpbb/db/driver/sqlite3.php index b7f6e60337..2000acb251 100644 --- a/phpBB/phpbb/db/driver/sqlite3.php +++ b/phpBB/phpbb/db/driver/sqlite3.php @@ -136,7 +136,19 @@ class sqlite3 extends \phpbb\db\driver\driver { if (($this->query_result = @$this->dbo->query($query)) === false) { - $this->sql_error($query); + // Try to recover a lost database connection + if ($this->dbo && !@$this->dbo->lastErrorMsg()) + { + if ($this->sql_connect($this->server, $this->user, '', $this->dbname)) + { + $this->query_result = @$this->dbo->query($query); + } + } + + if ($this->query_result === false) + { + $this->sql_error($query); + } } if (defined('DEBUG')) -- cgit v1.2.1 From df53d409226dd9a0ccbeac93f017a4363a1c98cf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 23 Oct 2015 16:34:01 +0200 Subject: [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 --- phpBB/phpbb/db/driver/sqlite3.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/db/driver/sqlite3.php') diff --git a/phpBB/phpbb/db/driver/sqlite3.php b/phpBB/phpbb/db/driver/sqlite3.php index 2000acb251..0508500c52 100644 --- a/phpBB/phpbb/db/driver/sqlite3.php +++ b/phpBB/phpbb/db/driver/sqlite3.php @@ -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; } /** -- cgit v1.2.1