aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/db/driver/sqlite.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/db/driver/sqlite.php')
-rw-r--r--phpBB/phpbb/db/driver/sqlite.php103
1 files changed, 64 insertions, 39 deletions
diff --git a/phpBB/phpbb/db/driver/sqlite.php b/phpBB/phpbb/db/driver/sqlite.php
index 59ec895c0f..8e205ebb81 100644
--- a/phpBB/phpbb/db/driver/sqlite.php
+++ b/phpBB/phpbb/db/driver/sqlite.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package dbal
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
*
*/
@@ -12,14 +16,13 @@ namespace phpbb\db\driver;
/**
* Sqlite Database Abstraction Layer
* Minimum Requirement: 2.8.2+
-* @package dbal
*/
class sqlite extends \phpbb\db\driver\driver
{
var $connect_error = '';
/**
- * Connect to server
+ * {@inheritDoc}
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
{
@@ -58,10 +61,7 @@ class sqlite extends \phpbb\db\driver\driver
}
/**
- * Version information about used database
- * @param bool $raw if true, only return the fetched sql_server_version
- * @param bool $use_cache if true, it is safe to retrieve the stored value from the cache
- * @return string sql server version
+ * {@inheritDoc}
*/
function sql_server_info($raw = false, $use_cache = true)
{
@@ -70,13 +70,16 @@ class sqlite extends \phpbb\db\driver\driver
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('sqlite_version')) === false)
{
$result = @sqlite_query('SELECT sqlite_version() AS version', $this->db_connect_id);
- $row = @sqlite_fetch_array($result, SQLITE_ASSOC);
+ if ($result)
+ {
+ $row = sqlite_fetch_array($result, SQLITE_ASSOC);
- $this->sql_server_version = (!empty($row['version'])) ? $row['version'] : 0;
+ $this->sql_server_version = (!empty($row['version'])) ? $row['version'] : 0;
- if (!empty($cache) && $use_cache)
- {
- $cache->put('sqlite_version', $this->sql_server_version);
+ if (!empty($cache) && $use_cache)
+ {
+ $cache->put('sqlite_version', $this->sql_server_version);
+ }
}
}
@@ -108,13 +111,7 @@ class sqlite extends \phpbb\db\driver\driver
}
/**
- * Base query method
- *
- * @param string $query Contains the SQL query which shall be executed
- * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
- * @return mixed When casted to bool the returned value returns true on success and false on failure
- *
- * @access public
+ * {@inheritDoc}
*/
function sql_query($query = '', $cache_ttl = 0)
{
@@ -127,6 +124,10 @@ class sqlite extends \phpbb\db\driver\driver
{
$this->sql_report('start', $query);
}
+ else if (defined('PHPBB_DISPLAY_LOAD_TIME'))
+ {
+ $this->curtime = microtime(true);
+ }
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
@@ -142,15 +143,19 @@ class sqlite extends \phpbb\db\driver\driver
{
$this->sql_report('stop', $query);
}
+ else if (defined('PHPBB_DISPLAY_LOAD_TIME'))
+ {
+ $this->sql_time += microtime(true) - $this->curtime;
+ }
- if ($cache && $cache_ttl)
+ if (!$this->query_result)
{
- $this->open_queries[(int) $this->query_result] = $this->query_result;
- $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
+ return false;
}
- else if (strpos($query, 'SELECT') === 0 && $this->query_result)
+
+ if ($cache && $cache_ttl)
{
- $this->open_queries[(int) $this->query_result] = $this->query_result;
+ $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
}
else if (defined('DEBUG'))
@@ -185,7 +190,7 @@ class sqlite extends \phpbb\db\driver\driver
}
/**
- * Return number of affected rows
+ * {@inheritDoc}
*/
function sql_affectedrows()
{
@@ -193,7 +198,7 @@ class sqlite extends \phpbb\db\driver\driver
}
/**
- * Fetch current row
+ * {@inheritDoc}
*/
function sql_fetchrow($query_id = false)
{
@@ -209,12 +214,11 @@ class sqlite extends \phpbb\db\driver\driver
return $cache->sql_fetchrow($query_id);
}
- return ($query_id !== false) ? @sqlite_fetch_array($query_id, SQLITE_ASSOC) : false;
+ return ($query_id) ? sqlite_fetch_array($query_id, SQLITE_ASSOC) : false;
}
/**
- * Seek to given row number
- * rownum is zero-based
+ * {@inheritDoc}
*/
function sql_rowseek($rownum, &$query_id)
{
@@ -230,11 +234,11 @@ class sqlite extends \phpbb\db\driver\driver
return $cache->sql_rowseek($rownum, $query_id);
}
- return ($query_id !== false) ? @sqlite_seek($query_id, $rownum) : false;
+ return ($query_id) ? @sqlite_seek($query_id, $rownum) : false;
}
/**
- * Get last inserted id after insert statement
+ * {@inheritDoc}
*/
function sql_nextid()
{
@@ -242,7 +246,7 @@ class sqlite extends \phpbb\db\driver\driver
}
/**
- * Free sql result
+ * {@inheritDoc}
*/
function sql_freeresult($query_id = false)
{
@@ -262,7 +266,7 @@ class sqlite extends \phpbb\db\driver\driver
}
/**
- * Escape string used in sql query
+ * {@inheritDoc}
*/
function sql_escape($msg)
{
@@ -270,12 +274,13 @@ class sqlite extends \phpbb\db\driver\driver
}
/**
- * Correctly adjust LIKE expression for special characters
+ * {@inheritDoc}
+ *
* For SQLite an underscore is a not-known character... this may change with SQLite3
*/
function sql_like_expression($expression)
{
- // Unlike LIKE, GLOB is case sensitive (unfortunatly). SQLite users need to live with it!
+ // Unlike LIKE, GLOB is unfortunately case sensitive.
// We only catch * and ? here, not the character map possible on file globbing.
$expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression);
@@ -286,6 +291,23 @@ class sqlite extends \phpbb\db\driver\driver
}
/**
+ * {@inheritDoc}
+ *
+ * For SQLite an underscore is a not-known character...
+ */
+ function sql_not_like_expression($expression)
+ {
+ // Unlike NOT LIKE, NOT GLOB is unfortunately case sensitive.
+ // We only catch * and ? here, not the character map possible on file globbing.
+ $expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression);
+
+ $expression = str_replace(array('?', '*'), array("\?", "\*"), $expression);
+ $expression = str_replace(array(chr(0) . "\?", chr(0) . "\*"), array('?', '*'), $expression);
+
+ return 'NOT GLOB \'' . $this->sql_escape($expression) . '\'';
+ }
+
+ /**
* return sql error array
* @access private
*/
@@ -343,9 +365,12 @@ class sqlite extends \phpbb\db\driver\driver
$endtime = $endtime[0] + $endtime[1];
$result = @sqlite_query($query, $this->db_connect_id);
- while ($void = @sqlite_fetch_array($result, SQLITE_ASSOC))
+ if ($result)
{
- // Take the time spent on parsing rows into account
+ while ($void = sqlite_fetch_array($result, SQLITE_ASSOC))
+ {
+ // Take the time spent on parsing rows into account
+ }
}
$splittime = explode(' ', microtime());