aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/acp
diff options
context:
space:
mode:
authorPatrick Webster <noxwizard@phpbb.com>2013-11-03 21:58:05 -0600
committerJoas Schilling <nickvergessen@gmx.de>2014-05-02 15:45:20 +0200
commitb39b0369aa0ac6853bde0504259166f570beb983 (patch)
tree5bc685f9ba2fc59a54cc2fb3d61440052f44dbb8 /phpBB/includes/acp
parentd52c2d1b5caf1382d178e55eff311ceddf4b392f (diff)
downloadforums-b39b0369aa0ac6853bde0504259166f570beb983.tar
forums-b39b0369aa0ac6853bde0504259166f570beb983.tar.gz
forums-b39b0369aa0ac6853bde0504259166f570beb983.tar.bz2
forums-b39b0369aa0ac6853bde0504259166f570beb983.tar.xz
forums-b39b0369aa0ac6853bde0504259166f570beb983.zip
[feature/sqlite3] Add support for SQLite 3
Minimum version requirement is 3.6.15 as that's what ships with PHP 5.3.0 when support for SQLite 3 was added. PHPBB3-9728
Diffstat (limited to 'phpBB/includes/acp')
-rw-r--r--phpBB/includes/acp/acp_database.php112
-rw-r--r--phpBB/includes/acp/acp_icons.php1
-rw-r--r--phpBB/includes/acp/acp_main.php2
-rw-r--r--phpBB/includes/acp/acp_profile.php4
-rw-r--r--phpBB/includes/acp/acp_reasons.php1
5 files changed, 119 insertions, 1 deletions
diff --git a/phpBB/includes/acp/acp_database.php b/phpBB/includes/acp/acp_database.php
index d28ee5b067..fd97e6ee08 100644
--- a/phpBB/includes/acp/acp_database.php
+++ b/phpBB/includes/acp/acp_database.php
@@ -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);
@@ -1052,6 +1058,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 type DESC, name;";
+ $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
+*/
class postgres_extractor extends base_extractor
{
function write_start($prefix)
diff --git a/phpBB/includes/acp/acp_icons.php b/phpBB/includes/acp/acp_icons.php
index 9c7acf506c..e4221a86dc 100644
--- a/phpBB/includes/acp/acp_icons.php
+++ b/phpBB/includes/acp/acp_icons.php
@@ -538,6 +538,7 @@ class acp_icons
switch ($db->sql_layer)
{
case 'sqlite':
+ case 'sqlite3':
case 'firebird':
$db->sql_query('DELETE FROM ' . $table);
break;
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php
index 4512905539..9c1613e24a 100644
--- a/phpBB/includes/acp/acp_main.php
+++ b/phpBB/includes/acp/acp_main.php
@@ -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;
diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php
index b42b852fba..8940410d72 100644
--- a/phpBB/includes/acp/acp_profile.php
+++ b/phpBB/includes/acp/acp_profile.php
@@ -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
diff --git a/phpBB/includes/acp/acp_reasons.php b/phpBB/includes/acp/acp_reasons.php
index 569bb73ab0..3f61a76d3a 100644
--- a/phpBB/includes/acp/acp_reasons.php
+++ b/phpBB/includes/acp/acp_reasons.php
@@ -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