Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: cs278/phpbb3
...
head fork: cs278/phpbb3
  • 7 commits
  • 19 files changed
  • 0 commit comments
  • 2 contributors
Commits on Sep 20, 2011
Boris Berdichevski [feature/sqlite3] Initial import of SQLite 3 database driver.
- Changed name from 'sqlite_3' to 'sqlite3'
- Fixed code formatting for our coding standards
- Added some comments where items need to be addressed
- Resolved a few minor issues

PHPBB3-9728
fe6268a
Chris Smith [feature/sqlite3] Add changes required for SQLite 3 support.
PHPBB3-9728
a7c2888
Commits on Sep 21, 2011
Chris Smith [feature/sqlite3] Add support for SQLite3 to unit test framework.
PHPBB3-9728
b3f5a96
Chris Smith [feature/sqlite3] Remove uesless extra code.
Not sure what the point of all the extra stuff is but removing it
makes things work properly. 8 unit tests fail currently down from
a lot more with errors.

PHPBB3-9728
21484a1
Chris Smith [feature/sqlite3] Fix condition so it can be true.
PHPBB3-9728
f7722b6
Chris Smith [feature/sqlite3] Fix sql_affectedrows() method.
PHPBB3-9728
f5c465f
Commits on Sep 24, 2011
Chris Smith [feature/sqlite3] Dubious fix to SQLite3 issue.
PHPBB3-9728
e3d51f7
1  phpBB/develop/add_permissions.php
View
@@ -380,6 +380,7 @@ function mass_auth($ug_type, $forum_id, $ug_id, $acl_list, $setting)
case 'mssql':
case 'sqlite':
+ case 'sqlite3':
$sql = implode(' UNION ALL ', preg_replace('#^(.*?)$#', 'SELECT \1', $sql_subary));
break;
1  phpBB/docs/INSTALL.html
View
@@ -133,6 +133,7 @@
<li>MySQL 3.23 or above (MySQLi supported)</li>
<li>PostgreSQL 7.3+</li>
<li>SQLite 2.8.2+</li>
+ <li>SQLite 3+</li>
<li>Firebird 2.1+</li>
<li>MS SQL Server 2000 or above (directly or via ODBC)</li>
<li>Oracle</li>
7 phpBB/includes/acp/acp_database.php
View
@@ -99,6 +99,11 @@ function main($id, $mode)
$extractor = new sqlite_extractor($download, $store, $format, $filename, $time);
break;
+ case 'sqlite3':
+ // @todo Syntax is identical, methods are not.
+ throw new Exception('Somebody forgot to fix this hrm');
+ break;
+
case 'postgres':
$extractor = new postgres_extractor($download, $store, $format, $filename, $time);
break;
@@ -133,6 +138,7 @@ function main($id, $mode)
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$extractor->flush('DELETE FROM ' . $table_name . ";\n");
break;
@@ -325,6 +331,7 @@ function main($id, $mode)
case 'mysql4':
case 'mysqli':
case 'sqlite':
+ case 'sqlite3':
while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false)
{
$db->sql_query($sql);
1  phpBB/includes/acp/acp_icons.php
View
@@ -555,6 +555,7 @@ function main($id, $mode)
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . $table);
break;
2  phpBB/includes/acp/acp_main.php
View
@@ -259,6 +259,7 @@ function main($id, $mode)
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
break;
@@ -359,6 +360,7 @@ function main($id, $mode)
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$db->sql_query("DELETE FROM $table");
break;
6 phpBB/includes/acp/acp_profile.php
View
@@ -124,6 +124,7 @@ function main($id, $mode)
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
$sql = "SELECT sql
FROM sqlite_master
WHERE type = 'table'
@@ -1406,6 +1407,7 @@ function add_field_ident($field_ident, $field_type)
break;
case 'sqlite':
+ case 'sqlite3':
switch ($field_type)
{
@@ -1437,7 +1439,9 @@ function add_field_ident($field_ident, $field_type)
}
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
- if (version_compare(sqlite_libversion(), '3.0') == -1)
+ // SQLite2 always has to do this mess, or SQLite3 <= 3.1.3 per the following:
+ // "After ADD COLUMN has been run on a database, that database will not be readable by SQLite version 3.1.3 and earlier." -- http://www.sqlite.org/lang_altertable.html
+ if ($db->sql_layer == 'sqlite' || version_compare($db->sql_server_info(true), '3.1.3', '<='))
{
$sql = "SELECT sql
FROM sqlite_master
1  phpBB/includes/acp/acp_reasons.php
View
@@ -253,6 +253,7 @@ function main($id, $mode)
case 'oracle':
case 'firebird':
case 'sqlite':
+ case 'sqlite3':
// Change the reports using this reason to 'other'
$sql = 'UPDATE ' . REPORTS_TABLE . '
SET reason_id = ' . $other_reason_id . ", report_text = '" . $db->sql_escape($reason_row['reason_description']) . "\n\n' || report_text
128 phpBB/includes/db/db_tools.php
View
@@ -250,6 +250,36 @@ class phpbb_db_tools
'VARBINARY' => 'blob',
),
+ 'sqlite3' => array(
+ 'INT:' => 'int(%d)',
+ 'BINT' => 'bigint(20)',
+ 'UINT' => 'INTEGER UNSIGNED', //'mediumint(8) UNSIGNED',
+ 'UINT:' => 'INTEGER UNSIGNED', // 'int(%d) UNSIGNED',
+ 'TINT:' => 'tinyint(%d)',
+ 'USINT' => 'INTEGER UNSIGNED', //'mediumint(4) UNSIGNED',
+ 'BOOL' => 'INTEGER UNSIGNED', //'tinyint(1) UNSIGNED',
+ 'VCHAR' => 'varchar(255)',
+ 'VCHAR:' => 'varchar(%d)',
+ 'CHAR:' => 'char(%d)',
+ 'XSTEXT' => 'text(65535)',
+ 'STEXT' => 'text(65535)',
+ 'TEXT' => 'text(65535)',
+ 'MTEXT' => 'mediumtext(16777215)',
+ 'XSTEXT_UNI'=> 'text(65535)',
+ 'STEXT_UNI' => 'text(65535)',
+ 'TEXT_UNI' => 'text(65535)',
+ 'MTEXT_UNI' => 'mediumtext(16777215)',
+ 'TIMESTAMP' => 'INTEGER UNSIGNED', //'int(11) UNSIGNED',
+ 'DECIMAL' => 'decimal(5,2)',
+ 'DECIMAL:' => 'decimal(%d,2)',
+ 'PDECIMAL' => 'decimal(6,3)',
+ 'PDECIMAL:' => 'decimal(%d,3)',
+ 'VCHAR_UNI' => 'varchar(255)',
+ 'VCHAR_UNI:'=> 'varchar(%d)',
+ 'VCHAR_CI' => 'varchar(255)',
+ 'VARBINARY' => 'blob',
+ ),
+
'postgres' => array(
'INT:' => 'INT4',
'BINT' => 'INT8',
@@ -291,7 +321,7 @@ class phpbb_db_tools
* A list of supported DBMS. We change this class to support more DBMS, the DBMS itself only need to follow some rules.
* @var array
*/
- var $supported_dbms = array('firebird', 'mssql', 'mssqlnative', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite');
+ var $supported_dbms = array('firebird', 'mssql', 'mssqlnative', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite', 'sqlite3');
/**
* This is set to true if user only wants to return the 'to-be-executed' SQL statement(s) (as an array).
@@ -490,6 +520,7 @@ function sql_create_table($table_name, $table_data)
case 'mysql_41':
case 'postgres':
case 'sqlite':
+ case 'sqlite3':
$table_sql .= ",\n\t PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ')';
break;
@@ -527,6 +558,7 @@ function sql_create_table($table_name, $table_data)
case 'mysql_40':
case 'sqlite':
+ case 'sqlite3':
$table_sql .= "\n);";
$statements[] = $table_sql;
break;
@@ -643,7 +675,7 @@ function perform_schema_changes($schema_changes)
$sqlite = false;
// For SQLite we need to perform the schema changes in a much more different way
- if ($this->db->sql_layer == 'sqlite' && $this->return_statements)
+ if (strpos($this->db->sql_layer, 'sqlite') === 0 && $this->return_statements)
{
$sqlite_data = array();
$sqlite = true;
@@ -1124,6 +1156,7 @@ function sql_column_exists($table, $column_name)
// ugh, SQLite
case 'sqlite':
+ case 'sqlite3':
$sql = "SELECT sql
FROM sqlite_master
WHERE type = 'table'
@@ -1632,6 +1665,7 @@ function sql_prepare_column_data($table_name, $column_name, $column_data)
break;
case 'sqlite':
+ case 'sqlite3':
$return_array['primary_key_set'] = false;
if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
{
@@ -1714,13 +1748,16 @@ function sql_column_add($table_name, $column_name, $column_data, $inline = false
break;
case 'sqlite':
+ case 'sqlite3':
if ($inline && $this->return_statements)
{
return $column_name . ' ' . $column_data['column_type_sql'];
}
- if (version_compare(sqlite_libversion(), '3.0') == -1)
+ // SQLite2 always has to do this mess, or SQLite3 <= 3.1.3 per the following:
+ // "After ADD COLUMN has been run on a database, that database will not be readable by SQLite version 3.1.3 and earlier." -- http://www.sqlite.org/lang_altertable.html
+ if ($db->sql_layer == 'sqlite' || version_compare($db->sql_server_info(true), '3.1.3', '<='))
{
$sql = "SELECT sql
FROM sqlite_master
@@ -1813,67 +1850,61 @@ function sql_column_remove($table_name, $column_name, $inline = false)
break;
case 'sqlite':
+ case 'sqlite3':
if ($inline && $this->return_statements)
{
return $column_name;
}
- if (version_compare(sqlite_libversion(), '3.0') == -1)
- {
- $sql = "SELECT sql
- FROM sqlite_master
- WHERE type = 'table'
- AND name = '{$table_name}'
- ORDER BY type DESC, name;";
- $result = $this->db->sql_query($sql);
+ $sql = "SELECT sql
+ FROM sqlite_master
+ WHERE type = 'table'
+ AND name = '{$table_name}'
+ ORDER BY type DESC, name;";
+ $result = $this->db->sql_query($sql);
- if (!$result)
- {
- break;
- }
+ if (!$result)
+ {
+ break;
+ }
- $row = $this->db->sql_fetchrow($result);
- $this->db->sql_freeresult($result);
+ $row = $this->db->sql_fetchrow($result);
+ $this->db->sql_freeresult($result);
- $statements[] = 'begin';
+ $statements[] = 'begin';
- // Create a backup table and populate it, destroy the existing one
- $statements[] = preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']);
- $statements[] = 'INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name;
- $statements[] = 'DROP TABLE ' . $table_name;
+ // Create a backup table and populate it, destroy the existing one
+ $statements[] = preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']);
+ $statements[] = 'INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name;
+ $statements[] = 'DROP TABLE ' . $table_name;
- preg_match('#\((.*)\)#s', $row['sql'], $matches);
+ preg_match('#\((.*)\)#s', $row['sql'], $matches);
- $new_table_cols = trim($matches[1]);
- $old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
- $column_list = array();
+ $new_table_cols = trim($matches[1]);
+ $old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
+ $column_list = array();
- foreach ($old_table_cols as $declaration)
+ foreach ($old_table_cols as $declaration)
+ {
+ $entities = preg_split('#\s+#', trim($declaration));
+ if ($entities[0] == 'PRIMARY' || $entities[0] === $column_name)
{
- $entities = preg_split('#\s+#', trim($declaration));
- if ($entities[0] == 'PRIMARY' || $entities[0] === $column_name)
- {
- continue;
- }
- $column_list[] = $entities[0];
+ continue;
}
+ $column_list[] = $entities[0];
+ }
- $columns = implode(',', $column_list);
+ $columns = implode(',', $column_list);
- $new_table_cols = preg_replace('/' . $column_name . '[^,]+(?:,|$)/m', '', $new_table_cols);
+ $new_table_cols = preg_replace('/' . $column_name . '[^,]+(?:,|$)/m', '', $new_table_cols);
- // create a new table and fill it up. destroy the temp one
- $statements[] = 'CREATE TABLE ' . $table_name . ' (' . $new_table_cols . ');';
- $statements[] = 'INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;';
- $statements[] = 'DROP TABLE ' . $table_name . '_temp';
+ // create a new table and fill it up. destroy the temp one
+ $statements[] = 'CREATE TABLE ' . $table_name . ' (' . $new_table_cols . ');';
+ $statements[] = 'INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;';
+ $statements[] = 'DROP TABLE ' . $table_name . '_temp';
- $statements[] = 'commit';
- }
- else
- {
- $statements[] = 'ALTER TABLE ' . $table_name . ' DROP COLUMN ' . $column_name;
- }
+ $statements[] = 'commit';
break;
}
@@ -1903,6 +1934,7 @@ function sql_index_drop($table_name, $index_name)
case 'oracle':
case 'postgres':
case 'sqlite':
+ case 'sqlite3':
$statements[] = 'DROP INDEX ' . $table_name . '_' . $index_name;
break;
}
@@ -2009,6 +2041,7 @@ function sql_create_primary_key($table_name, $column, $inline = false)
break;
case 'sqlite':
+ case 'sqlite3':
if ($inline && $this->return_statements)
{
@@ -2087,6 +2120,7 @@ function sql_create_unique_index($table_name, $index_name, $column)
case 'postgres':
case 'oracle':
case 'sqlite':
+ case 'sqlite3':
$statements[] = 'CREATE UNIQUE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
break;
@@ -2130,6 +2164,7 @@ function sql_create_index($table_name, $index_name, $column)
case 'postgres':
case 'oracle':
case 'sqlite':
+ case 'sqlite3':
$statements[] = 'CREATE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
break;
@@ -2221,6 +2256,7 @@ function sql_list_index($table_name)
break;
case 'sqlite':
+ case 'sqlite3':
$sql = "PRAGMA index_info('" . $table_name . "');";
$col = 'name';
break;
@@ -2240,6 +2276,7 @@ function sql_list_index($table_name)
case 'oracle':
case 'postgres':
case 'sqlite':
+ case 'sqlite3':
$row[$col] = substr($row[$col], strlen($table_name) + 1);
break;
}
@@ -2375,6 +2412,7 @@ function sql_column_change($table_name, $column_name, $column_data, $inline = fa
break;
case 'sqlite':
+ case 'sqlite3':
if ($inline && $this->return_statements)
{
373 phpBB/includes/db/sqlite3.php
View
@@ -0,0 +1,373 @@
+<?php
+/**
+*
+* @package dbal
+* @copyright (c) 2005, 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
+
+/**
+* SQLite3 database abstraction layer
+*
+* This file is largely based upon
+* <http://www.phpbb.com/community/viewtopic.php?f=70&t=1059695>
+*
+* @package dbal
+* @author Boris Berdichevski <borisba@borisba.com>
+*/
+class dbal_sqlite3 extends dbal
+{
+ var $db;
+
+ /**
+ * Connect to server
+ */
+ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
+ {
+ $this->server = $sqlserver;
+ $this->persistency = $persistency;
+
+ try
+ {
+ $this->db = new SQLite3($this->server);
+ $this->db->exec('PRAGMA short_column_names = 1');
+ }
+ catch (Exception $error)
+ {
+ return array(
+ 'code' => $error->getCode(),
+ 'message' => $error->getMessage(),
+ );
+ }
+
+ return true;
+ }
+
+ /**
+ * 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
+ */
+ function sql_server_info($raw = false, $use_cache = true)
+ {
+ global $cache;
+
+ if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('sqlite3_version')) === false)
+ {
+ $vers = SQLite3::version();
+
+ $this->sql_server_version = $vers['versionString'];
+
+ if (!empty($cache) && $use_cache)
+ {
+ $cache->put('sqlite3_version', $this->sql_server_version);
+ }
+ }
+
+ return ($raw) ? $this->sql_server_version : 'SQLite ' . $this->sql_server_version;
+ }
+
+ /**
+ * SQL Transaction
+ */
+ function _sql_transaction($status = 'begin')
+ {
+ switch ($status)
+ {
+ case 'begin':
+ return $this->db->query('BEGIN');
+ break;
+
+ case 'commit':
+ return $this->db->query('COMMIT');
+ break;
+
+ case 'rollback':
+ return $this->db->query('ROLLBACK');
+ break;
+ }
+
+ return true;
+ }
+
+ /**
+ * 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
+ *
+ */
+ function sql_query($query = '', $cache_ttl = 0)
+ {
+ global $cache;
+
+ if ($query != '')
+ {
+ // EXPLAIN only in extra debug mode
+ if (defined('DEBUG_EXTRA'))
+ {
+ $this->sql_report('start', $query);
+ }
+
+ $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
+
+ $this->sql_add_num_queries($this->query_result);
+
+ if ($this->query_result === false)
+ {
+ $this->query_result = @$this->db->query($query);
+
+ if ($this->query_result === false)
+ {
+ $this->sql_error($query);
+ }
+
+ if (defined('DEBUG_EXTRA'))
+ {
+ $this->sql_report('stop', $query);
+ }
+
+ if ($cache_ttl && method_exists($cache, 'sql_save'))
+ {
+ $this->open_queries[(int) $this->query_result] = $this->query_result;
+
+ $cache->sql_save($query, $this->query_result, $cache_ttl);
+ }
+ else if (is_object($this->query_result))
+ {
+ $this->open_queries[spl_object_hash($this->query_result)] = $this->query_result;
+ }
+ }
+ else if (defined('DEBUG_EXTRA'))
+ {
+ $this->sql_report('fromcache', $query);
+ }
+ }
+ else
+ {
+ return false;
+ }
+
+ return ($this->query_result) ? $this->query_result : false;
+ }
+
+ /**
+ * Build LIMIT query
+ */
+ function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
+ {
+ $this->query_result = false;
+
+ // if $total is set to 0 we do not want to limit the number of rows
+ if ($total == 0)
+ {
+ $total = -1;
+ }
+
+ $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
+
+ return $this->sql_query($query, $cache_ttl);
+ }
+
+ /**
+ * Return number of affected rows
+ */
+ function sql_affectedrows()
+ {
+ return ($this->db instanceof SQLite3) ? $this->db->changes() : false;
+ }
+
+ /**
+ * Fetch current row
+ */
+ function sql_fetchrow($query_id = false)
+ {
+ global $cache;
+
+ if ($query_id === false)
+ {
+ $query_id = $this->query_result;
+ }
+
+ if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
+ {
+ return $cache->sql_fetchrow($query_id);
+ }
+
+ if (!is_object($query_id))
+ {
+ return false;
+ }
+
+ return $query_id->fetchArray(SQLITE3_ASSOC);
+ }
+
+ /**
+ * Seek to given row number
+ * rownum is zero-based
+ */
+ function sql_rowseek($rownum, &$query_id)
+ {
+ global $cache;
+
+ if ($query_id === false)
+ {
+ $query_id = $this->query_result;
+ }
+
+ if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
+ {
+ return $cache->sql_rowseek($rownum, $query_id);
+ }
+
+ // @todo Implement seeking the hard way.
+ throw new BadMethodCallException('sqlite3 does not support row seeking.');
+ }
+
+ /**
+ * Get last inserted id after insert statement
+ */
+ function sql_nextid()
+ {
+ return $this->db->lastInsertRowID();
+ }
+
+ /**
+ * Free sql result
+ */
+ function sql_freeresult($query_id = false)
+ {
+ global $cache;
+
+ if ($query_id === false)
+ {
+ $query_id = $this->query_result;
+ }
+
+ if (isset($cache->sql_rowset[$query_id]))
+ {
+ return $cache->sql_freeresult($query_id);
+ }
+
+ if (is_object($query_id) && isset($this->open_queries[spl_object_hash($query_id)]))
+ {
+ unset($this->open_queries[spl_object_hash($query_id)]);
+ $query_id->finalize();
+ }
+
+ return true;
+ }
+
+ function _sql_validate_value($var)
+ {
+ if (is_string($var) && strpos($var, "\x00") !== false)
+ {
+ $var = current(unpack('H*', $var));
+
+ $var = SQLite3::escapeString($var);
+
+ return "x'$var'";
+ }
+ else
+ {
+ return parent::_sql_validate_value($var);
+ }
+ }
+
+ /**
+ * Escape string used in sql query
+ */
+ function sql_escape($msg)
+ {
+ return SQLite3::escapeString($msg);
+ }
+
+ /**
+ * Correctly adjust LIKE expression for special characters
+ * For SQLite an underscore is a not-known character... this may change with SQLite3
+ *
+ * @todo Does this still stand for SQLite3?
+ */
+ function sql_like_expression($expression)
+ {
+ // Unlike LIKE, GLOB is case sensitive (unfortunatly). SQLite users need to live with it!
+ // 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 'GLOB \'' . $this->sql_escape($expression) . '\'';
+ }
+
+ /**
+ * return sql error array
+ */
+ function _sql_error()
+ {
+ return array(
+ 'message' => $this->db->lastErrorMsg(),
+ 'code' => $this->db->lastErrorCode()
+ );
+ }
+
+ /**
+ * Build db-specific query data
+ */
+ function _sql_custom_build($stage, $data)
+ {
+ return $data;
+ }
+
+ /**
+ * Close sql connection
+ */
+ function _sql_close()
+ {
+ return $this->db->close();
+ }
+
+ /**
+ * Build db-specific report
+ */
+ function _sql_report($mode, $query = '')
+ {
+ switch ($mode)
+ {
+ case 'start':
+ break;
+
+ case 'fromcache':
+ $endtime = microtime(true);
+
+ $results = $this->db->query( $query);
+
+ while ($result= $results->fetchArray(SQLITE3_ASSOC))
+ {
+ // Take the time spent on parsing rows into account
+ }
+
+ $splittime = explode(' ', microtime());
+ $splittime = $splittime[0] + $splittime[1];
+
+ $this->sql_report('record_fromcache', $query, $endtime, $splittime);
+
+ $results->finalize();
+ break;
+ }
+ }
+}
2  phpBB/includes/functions.php
View
@@ -3966,7 +3966,7 @@ function obtain_guest_count($item_id = 0, $item = 'forum')
// Get number of online guests
- if ($db->sql_layer === 'sqlite')
+ if ($db->sql_layer === 'sqlite' || $db->sql_layer === 'sqlite3')
{
$sql = 'SELECT COUNT(session_ip) as num_guests
FROM (
2  phpBB/includes/functions_admin.php
View
@@ -2344,6 +2344,7 @@ function cache_moderators()
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . MODERATOR_CACHE_TABLE);
break;
@@ -3041,6 +3042,7 @@ function get_database_size()
break;
case 'sqlite':
+ case 'sqlite3':
global $dbhost;
if (file_exists($dbhost))
2  phpBB/includes/functions_convert.php
View
@@ -1648,6 +1648,7 @@ function mass_auth($ug_type, $forum_id, $ug_id, $acl_list, $setting = ACL_NO)
case 'mssql':
case 'sqlite':
+ case 'sqlite3':
case 'mssqlnative':
$sql = implode(' UNION ALL ', preg_replace('#^(.*?)$#', 'SELECT \1', $sql_subary));
break;
@@ -2003,6 +2004,7 @@ function update_topics_posted()
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
break;
18 phpBB/includes/functions_install.php
View
@@ -135,6 +135,16 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20
'AVAILABLE' => true,
'2.0.x' => false,
),
+ 'sqlite3' => array(
+ 'LABEL' => 'SQLite3',
+ 'SCHEMA' => 'sqlite',
+ 'MODULE' => 'sqlite3',
+ 'DELIM' => ';',
+ 'COMMENTS' => 'remove_remarks',
+ 'DRIVER' => 'sqlite3',
+ 'AVAILABLE' => true,
+ '2.0.x' => false,
+ ),
);
if ($dbms)
@@ -223,6 +233,7 @@ function get_tables($db)
break;
case 'sqlite':
+ case 'sqlite3':
$sql = 'SELECT name
FROM sqlite_master
WHERE type = "table"';
@@ -292,14 +303,14 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
$db->sql_return_on_error(true);
// Check that we actually have a database name before going any further.....
- if ($dbms_details['DRIVER'] != 'sqlite' && $dbms_details['DRIVER'] != 'oracle' && $dbname === '')
+ if ($dbms_details['DRIVER'] != 'sqlite' && $dbms_details['DRIVER'] != 'sqlite3' && $dbms_details['DRIVER'] != 'oracle' && $dbname === '')
{
$error[] = $lang['INST_ERR_DB_NO_NAME'];
return false;
}
// Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea
- if ($dbms_details['DRIVER'] == 'sqlite' && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0)
+ if (strpos($dbms_details['DRIVER'], 'sqlite') === 0 && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0)
{
$error[] = $lang['INST_ERR_DB_FORUM_PATH'];
return false;
@@ -329,6 +340,7 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
break;
case 'sqlite':
+ case 'sqlite3':
$prefix_length = 200;
break;
@@ -385,6 +397,8 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
}
break;
+ // @todo Do we need something here for sqlite3?
+
case 'firebird':
// check the version of FB, use some hackery if we can't get access to the server info
if ($db->service_handle !== false && function_exists('ibase_server_info'))
1  phpBB/includes/functions_profile_fields.php
View
@@ -376,6 +376,7 @@ function update_profile_field_data($user_id, &$cp_data)
break;
case 'sqlite':
+ case 'sqlite3':
case 'mssql':
case 'mssql_odbc':
case 'mssqlnative':
1  phpBB/install/convertors/functions_phpbb20.php
View
@@ -1785,6 +1785,7 @@ function phpbb_create_userconv_table()
break;
case 'sqlite':
+ case 'sqlite3':
$create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
user_id INTEGER NOT NULL DEFAULT \'0\',
username_clean varchar(255) NOT NULL DEFAULT \'\'
3  phpBB/install/install_convert.php
View
@@ -234,6 +234,7 @@ function main($mode, $sub)
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . SESSIONS_KEYS_TABLE);
$db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
@@ -659,6 +660,7 @@ function convert_data($sub)
switch ($src_db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$convert->src_truncate_statement = 'DELETE FROM ';
break;
@@ -691,6 +693,7 @@ function convert_data($sub)
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$convert->truncate_statement = 'DELETE FROM ';
break;
2  phpBB/language/en/install.php
View
@@ -153,6 +153,7 @@
'DLL_ORACLE' => 'Oracle',
'DLL_POSTGRES' => 'PostgreSQL 7.x/8.x',
'DLL_SQLITE' => 'SQLite',
+ 'DLL_SQLITE3' => 'SQLite 3',
'DLL_XML' => 'XML support [ Jabber ]',
'DLL_ZLIB' => 'zlib compression support [ gz, .tar.gz, .zip ]',
'DL_CONFIG' => 'Download config',
@@ -213,6 +214,7 @@
<li>MySQL 3.23 or above (MySQLi supported)</li>
<li>PostgreSQL 7.3+</li>
<li>SQLite 2.8.2+</li>
+ <li>SQLite 3+</li>
<li>Firebird 2.1+</li>
<li>MS SQL Server 2000 or above (directly or via ODBC)</li>
<li>MS SQL Server 2005 or above (native)</li>
1  phpBB/viewonline.php
View
@@ -100,6 +100,7 @@
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
$sql = 'SELECT COUNT(session_ip) as num_guests
FROM (
SELECT DISTINCT session_ip
10 tests/test_framework/phpbb_database_test_connection_manager.php
View
@@ -47,6 +47,7 @@ public function connect($use_db = true)
switch ($this->dbms['PDO'])
{
case 'sqlite2':
+ case 'sqlite':
$dsn .= $this->config['dbhost'];
break;
@@ -112,6 +113,7 @@ public function recreate_db()
switch ($this->config['dbms'])
{
case 'sqlite':
+ case 'sqlite3':
if (file_exists($this->config['dbhost']))
{
unlink($this->config['dbhost']);
@@ -157,6 +159,7 @@ public function get_tables()
break;
case 'sqlite':
+ case 'sqlite3':
$sql = 'SELECT name
FROM sqlite_master
WHERE type = "table"';
@@ -266,7 +269,7 @@ protected function split_sql($sql)
unset($data[key($data)]);
}
- if ($this->config['dbms'] == 'sqlite')
+ if (strpos($this->config['dbms'], 'sqlite') === 0)
{
// remove comment lines starting with # - they are not proper sqlite
// syntax and break sqlite2
@@ -330,6 +333,11 @@ protected function get_dbms_data($dbms)
'DELIM' => ';',
'PDO' => 'sqlite2',
),
+ 'sqlite3' => array(
+ 'SCHEMA' => 'sqlite',
+ 'DELIM' => ';',
+ 'PDO' => 'sqlite',
+ ),
);
if (isset($available_dbms[$dbms]))

No commit comments for this range

Something went wrong with that request. Please try again.