1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-07 01:06:48 +02:00

Merge remote-tracking branch 'github-nickvergessen/feature/sqlite3' into develop-ascraeus

* github-nickvergessen/feature/sqlite3:
  [feature/sqlite3] Add sqlite3 database to .gitignore
  [feature/sqlite3] Use SQLite3 by default
  [feature/sqlite3] Remove invalid comment
  [feature/sqlite3] Remove unneeded ORDER BY type from sqlite_master queries
  [feature/sqlite3] Correctly recreate indexes when recreating a table
  [feature/sqlite3] Fix sql_index_drop() for sqlite3
  [feature/sqlite3] Remove trailing comma from column list
  [feature/sqlite3] Update docblocks and function visibility
  [feature/sqlite3] Add support for SQLite 3
This commit is contained in:
Nils Adermann
2014-05-02 17:57:22 +02:00
25 changed files with 857 additions and 145 deletions

View File

@@ -101,6 +101,10 @@ class acp_database
$extractor = new sqlite_extractor($format, $filename, $time, $download, $store);
break;
case 'sqlite3':
$extractor = new sqlite3_extractor($format, $filename, $time, $download, $store);
break;
case 'postgres':
$extractor = new postgres_extractor($format, $filename, $time, $download, $store);
break;
@@ -135,6 +139,7 @@ class acp_database
switch ($db->sql_layer)
{
case 'sqlite':
case 'sqlite3':
case 'firebird':
$extractor->flush('DELETE FROM ' . $table_name . ";\n");
break;
@@ -325,6 +330,7 @@ class acp_database
case 'mysql4':
case 'mysqli':
case 'sqlite':
case 'sqlite3':
while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false)
{
$db->sql_query($sql);
@@ -1049,6 +1055,112 @@ class sqlite_extractor extends base_extractor
}
}
/**
* @package acp
*/
class sqlite3_extractor extends base_extractor
{
function write_start($prefix)
{
$sql_data = "--\n";
$sql_data .= "-- phpBB Backup Script\n";
$sql_data .= "-- Dump of tables for $prefix\n";
$sql_data .= "-- DATE : " . gmdate("d-m-Y H:i:s", $this->time) . " GMT\n";
$sql_data .= "--\n";
$sql_data .= "BEGIN TRANSACTION;\n";
$this->flush($sql_data);
}
function write_table($table_name)
{
global $db;
$sql_data = '-- Table: ' . $table_name . "\n";
$sql_data .= "DROP TABLE $table_name;\n";
$sql = "SELECT sql
FROM sqlite_master
WHERE type = 'table'
AND name = '" . $db->sql_escape($table_name) . "'
ORDER BY name ASC;";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Create Table
$sql_data .= $row['sql'] . ";\n";
$result = $db->sql_query("PRAGMA index_list('" . $db->sql_escape($table_name) . "');");
while ($row = $db->sql_fetchrow($result))
{
if (strpos($row['name'], 'autoindex') !== false)
{
continue;
}
$result2 = $db->sql_query("PRAGMA index_info('" . $db->sql_escape($row['name']) . "');");
$fields = array();
while ($row2 = $db->sql_fetchrow($result2))
{
$fields[] = $row2['name'];
}
$db->sql_freeresult($result2);
$sql_data .= 'CREATE ' . ($row['unique'] ? 'UNIQUE ' : '') . 'INDEX ' . $row['name'] . ' ON ' . $table_name . ' (' . implode(', ', $fields) . ");\n";
}
$db->sql_freeresult($result);
$this->flush($sql_data . "\n");
}
function write_data($table_name)
{
global $db;
$result = $db->sql_query("PRAGMA table_info('" . $db->sql_escape($table_name) . "');");
$col_types = array();
while ($row = $db->sql_fetchrow($result))
{
$col_types[$row['name']] = $row['type'];
}
$db->sql_freeresult($result);
$sql_insert = 'INSERT INTO ' . $table_name . ' (' . implode(', ', array_keys($col_types)) . ') VALUES (';
$sql = "SELECT *
FROM $table_name";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
foreach ($row as $column_name => $column_data)
{
if (is_null($column_data))
{
$row[$column_name] = 'NULL';
}
else if ($column_data === '')
{
$row[$column_name] = "''";
}
else if (stripos($col_types[$column_name], 'text') !== false || stripos($col_types[$column_name], 'char') !== false || stripos($col_types[$column_name], 'blob') !== false)
{
$row[$column_name] = sanitize_data_generic(str_replace("'", "''", $column_data));
}
}
$this->flush($sql_insert . implode(', ', $row) . ");\n");
}
}
function write_end()
{
$this->flush("COMMIT;\n");
parent::write_end();
}
}
/**
* @package acp
*/

View File

@@ -538,6 +538,7 @@ class acp_icons
switch ($db->sql_layer)
{
case 'sqlite':
case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . $table);
break;

View File

@@ -271,6 +271,7 @@ class acp_main
switch ($db->sql_layer)
{
case 'sqlite':
case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
break;
@@ -376,6 +377,7 @@ class acp_main
switch ($db->sql_layer)
{
case 'sqlite':
case 'sqlite3':
case 'firebird':
$db->sql_query("DELETE FROM $table");
break;

View File

@@ -114,6 +114,7 @@ class acp_profile
switch ($db->sql_layer)
{
case 'sqlite':
case 'sqlite3':
$sql = "SELECT sql
FROM sqlite_master
WHERE type = 'table'
@@ -1204,7 +1205,8 @@ class acp_profile
break;
case 'sqlite':
if (version_compare(sqlite_libversion(), '3.0') == -1)
case 'sqlite3':
if (version_compare($db->sql_server_info(true), '3.0') == -1)
{
$sql = "SELECT sql
FROM sqlite_master

View File

@@ -253,6 +253,7 @@ class acp_reasons
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

View File

@@ -3989,7 +3989,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 (

View File

@@ -2440,6 +2440,7 @@ function phpbb_cache_moderators($db, $cache, $auth)
switch ($db->sql_layer)
{
case 'sqlite':
case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . MODERATOR_CACHE_TABLE);
break;
@@ -2907,6 +2908,7 @@ function get_database_size()
break;
case 'sqlite':
case 'sqlite3':
global $dbhost;
if (file_exists($dbhost))

View File

@@ -1650,6 +1650,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;
@@ -2037,6 +2038,7 @@ function update_topics_posted()
switch ($db->sql_layer)
{
case 'sqlite':
case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
break;

View File

@@ -106,6 +106,15 @@ 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' => ';',
'DRIVER' => 'phpbb\db\driver\sqlite3',
'AVAILABLE' => true,
'2.0.x' => false,
),
);
if ($dbms)
@@ -206,14 +215,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'] != 'phpbb\db\driver\sqlite' && $dbms_details['DRIVER'] != 'phpbb\db\driver\oracle' && $dbname === '')
if ($dbms_details['DRIVER'] != 'phpbb\db\driver\sqlite' && $dbms_details['DRIVER'] != 'phpbb\db\driver\sqlite3' && $dbms_details['DRIVER'] != 'phpbb\db\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'] == 'phpbb\db\driver\sqlite' && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0)
if (($dbms_details['DRIVER'] == 'phpbb\db\driver\sqlite' || $dbms_details['DRIVER'] == 'phpbb\db\driver\sqlite3') && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0)
{
$error[] = $lang['INST_ERR_DB_FORUM_PATH'];
return false;
@@ -243,6 +252,7 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
break;
case 'phpbb\db\driver\sqlite':
case 'phpbb\db\driver\sqlite3':
$prefix_length = 200;
break;
@@ -299,6 +309,14 @@ function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix,
}
break;
case 'phpbb\db\driver\sqlite3':
$version = \SQLite3::version();
if (version_compare($version['versionString'], '3.6.15', '<'))
{
$error[] = $lang['INST_ERR_DB_NO_SQLITE3'];
}
break;
case 'phpbb\db\driver\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'))