aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/db
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/db')
-rw-r--r--phpBB/phpbb/db/driver/driver.php19
-rw-r--r--phpBB/phpbb/db/driver/mssqlnative.php5
-rw-r--r--phpBB/phpbb/db/driver/oracle.php6
-rw-r--r--phpBB/phpbb/db/extractor/mssql_extractor.php4
-rw-r--r--phpBB/phpbb/db/extractor/oracle_extractor.php4
-rw-r--r--phpBB/phpbb/db/migration/data/v310/style_update_p1.php2
-rw-r--r--phpBB/phpbb/db/migration/data/v310/teampage.php4
-rw-r--r--phpBB/phpbb/db/migration/data/v31x/v3112.php36
-rw-r--r--phpBB/phpbb/db/migration/data/v320/remove_outdated_media.php13
-rw-r--r--phpBB/phpbb/db/migration/tool/config.php2
-rw-r--r--phpBB/phpbb/db/migration/tool/config_text.php2
-rw-r--r--phpBB/phpbb/db/migration/tool/module.php4
-rw-r--r--phpBB/phpbb/db/migration/tool/permission.php2
-rw-r--r--phpBB/phpbb/db/migrator.php4
-rw-r--r--phpBB/phpbb/db/sql_insert_buffer.php4
-rw-r--r--phpBB/phpbb/db/tools/mssql.php86
-rw-r--r--phpBB/phpbb/db/tools/tools.php15
17 files changed, 156 insertions, 56 deletions
diff --git a/phpBB/phpbb/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php
index 214c5590e7..5851469806 100644
--- a/phpBB/phpbb/db/driver/driver.php
+++ b/phpBB/phpbb/db/driver/driver.php
@@ -537,7 +537,9 @@ abstract class driver implements driver_interface
*/
function sql_in_set($field, $array, $negate = false, $allow_empty_set = false)
{
- if (!sizeof($array))
+ $array = (array) $array;
+
+ if (!count($array))
{
if (!$allow_empty_set)
{
@@ -559,12 +561,7 @@ abstract class driver implements driver_interface
}
}
- if (!is_array($array))
- {
- $array = array($array);
- }
-
- if (sizeof($array) == 1)
+ if (count($array) == 1)
{
@reset($array);
$var = current($array);
@@ -632,7 +629,7 @@ abstract class driver implements driver_interface
*/
function sql_multi_insert($table, $sql_ary)
{
- if (!sizeof($sql_ary))
+ if (!count($sql_ary))
{
return false;
}
@@ -738,7 +735,7 @@ abstract class driver implements driver_interface
// We run the following code to determine if we need to re-order the table array. ;)
// The reason for this is that for multi-aliased tables (two equal tables) in the FROM statement the last table need to match the first comparison.
// DBMS who rely on this: Oracle, PostgreSQL and MSSQL. For all other DBMS it makes absolutely no difference in which order the table is.
- if (!empty($array['LEFT_JOIN']) && sizeof($array['FROM']) > 1 && $used_multi_alias !== false)
+ if (!empty($array['LEFT_JOIN']) && count($array['FROM']) > 1 && $used_multi_alias !== false)
{
// Take first LEFT JOIN
$join = current($array['LEFT_JOIN']);
@@ -848,7 +845,7 @@ abstract class driver implements driver_interface
default:
- switch (sizeof($condition))
+ switch (count($condition))
{
case 3:
@@ -1138,7 +1135,7 @@ abstract class driver implements driver_interface
$html_table = func_get_arg(2);
$row = func_get_arg(3);
- if (!$html_table && sizeof($row))
+ if (!$html_table && count($row))
{
$html_table = true;
$this->html_hold .= '<table cellspacing="1"><tr>';
diff --git a/phpBB/phpbb/db/driver/mssqlnative.php b/phpBB/phpbb/db/driver/mssqlnative.php
index 50dce35baa..de81a6a0c8 100644
--- a/phpBB/phpbb/db/driver/mssqlnative.php
+++ b/phpBB/phpbb/db/driver/mssqlnative.php
@@ -50,7 +50,8 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
$this->db_connect_id = sqlsrv_connect($this->server, array(
'Database' => $this->dbname,
'UID' => $this->user,
- 'PWD' => $sqlpassword
+ 'PWD' => $sqlpassword,
+ 'CharacterSet' => 'UTF-8'
));
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
@@ -267,7 +268,7 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
unset($row['line2'], $row['line3']);
}
}
- return (sizeof($row)) ? $row : false;
+ return (count($row)) ? $row : false;
}
/**
diff --git a/phpBB/phpbb/db/driver/oracle.php b/phpBB/phpbb/db/driver/oracle.php
index 54238a15ef..5fd14709f8 100644
--- a/phpBB/phpbb/db/driver/oracle.php
+++ b/phpBB/phpbb/db/driver/oracle.php
@@ -136,7 +136,7 @@ class oracle extends \phpbb\db\driver\driver
*/
function _rewrite_col_compare($args)
{
- if (sizeof($args) == 4)
+ if (count($args) == 4)
{
if ($args[2] == '=')
{
@@ -290,7 +290,7 @@ class oracle extends \phpbb\db\driver\driver
and/or need the db restore script, uncomment this.
- if (sizeof($cols) !== sizeof($vals))
+ if (count($cols) !== count($vals))
{
// Try to replace some common data we know is from our restore script or from other sources
$regs[3] = str_replace("'||chr(47)||'", '/', $regs[3]);
@@ -332,7 +332,7 @@ class oracle extends \phpbb\db\driver\driver
if ($string)
{
// New value if cols != value
- $vals[(sizeof($cols) !== sizeof($vals)) ? $i : $i - 1] .= $string;
+ $vals[(count($cols) !== count($vals)) ? $i : $i - 1] .= $string;
}
$vals = array(0 => $vals);
diff --git a/phpBB/phpbb/db/extractor/mssql_extractor.php b/phpBB/phpbb/db/extractor/mssql_extractor.php
index 2817d3ebcc..4eeab4780e 100644
--- a/phpBB/phpbb/db/extractor/mssql_extractor.php
+++ b/phpBB/phpbb/db/extractor/mssql_extractor.php
@@ -132,14 +132,14 @@ class mssql_extractor extends base_extractor
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
- if (!sizeof($rows))
+ if (!count($rows))
{
$sql_data .= "ALTER TABLE [$table_name] WITH NOCHECK ADD\n";
$sql_data .= "\tCONSTRAINT [{$row['CONSTRAINT_NAME']}] PRIMARY KEY CLUSTERED \n\t(\n";
}
$rows[] = "\t\t[{$row['COLUMN_NAME']}]";
}
- if (sizeof($rows))
+ if (count($rows))
{
$sql_data .= implode(",\n", $rows);
$sql_data .= "\n\t) ON [PRIMARY] \nGO\n";
diff --git a/phpBB/phpbb/db/extractor/oracle_extractor.php b/phpBB/phpbb/db/extractor/oracle_extractor.php
index 79a991889b..bc43a37b10 100644
--- a/phpBB/phpbb/db/extractor/oracle_extractor.php
+++ b/phpBB/phpbb/db/extractor/oracle_extractor.php
@@ -82,7 +82,7 @@ class oracle_extractor extends base_extractor
}
$this->db->sql_freeresult($result);
- if (sizeof($primary_key))
+ if (count($primary_key))
{
$rows[] = " CONSTRAINT {$constraint_name} PRIMARY KEY (" . implode(', ', $primary_key) . ')';
}
@@ -103,7 +103,7 @@ class oracle_extractor extends base_extractor
}
$this->db->sql_freeresult($result);
- if (sizeof($unique))
+ if (count($unique))
{
$rows[] = " CONSTRAINT {$constraint_name} UNIQUE (" . implode(', ', $unique) . ')';
}
diff --git a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php
index f50ab33830..a7e30a9cb7 100644
--- a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php
+++ b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php
@@ -133,7 +133,7 @@ class style_update_p1 extends \phpbb\db\migration\migration
}
// Remove old entries from styles table
- if (!sizeof($valid_styles))
+ if (!count($valid_styles))
{
// No valid styles: remove everything and add prosilver
$this->sql_query('DELETE FROM ' . STYLES_TABLE);
diff --git a/phpBB/phpbb/db/migration/data/v310/teampage.php b/phpBB/phpbb/db/migration/data/v310/teampage.php
index f8edbc3492..3a37b17e97 100644
--- a/phpBB/phpbb/db/migration/data/v310/teampage.php
+++ b/phpBB/phpbb/db/migration/data/v310/teampage.php
@@ -93,13 +93,13 @@ class teampage extends \phpbb\db\migration\migration
$teampage_entries[] = array(
'group_id' => (int) $row['group_id'],
'teampage_name' => '',
- 'teampage_position' => sizeof($teampage_entries) + 1,
+ 'teampage_position' => count($teampage_entries) + 1,
'teampage_parent' => 0,
);
}
$this->db->sql_freeresult($result);
- if (sizeof($teampage_entries))
+ if (count($teampage_entries))
{
$this->db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries);
}
diff --git a/phpBB/phpbb/db/migration/data/v31x/v3112.php b/phpBB/phpbb/db/migration/data/v31x/v3112.php
new file mode 100644
index 0000000000..0d75d35184
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v31x/v3112.php
@@ -0,0 +1,36 @@
+<?php
+/**
+*
+* 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.
+*
+*/
+
+namespace phpbb\db\migration\data\v31x;
+
+class v3112 extends \phpbb\db\migration\migration
+{
+ public function effectively_installed()
+ {
+ return phpbb_version_compare($this->config['version'], '3.1.12', '>=');
+ }
+
+ static public function depends_on()
+ {
+ return array(
+ '\phpbb\db\migration\data\v31x\v3111',
+ );
+ }
+
+ public function update_data()
+ {
+ return array(
+ array('config.update', array('version', '3.1.12')),
+ );
+ }
+}
diff --git a/phpBB/phpbb/db/migration/data/v320/remove_outdated_media.php b/phpBB/phpbb/db/migration/data/v320/remove_outdated_media.php
index c14d31f1c0..98b1c2d039 100644
--- a/phpBB/phpbb/db/migration/data/v320/remove_outdated_media.php
+++ b/phpBB/phpbb/db/migration/data/v320/remove_outdated_media.php
@@ -15,10 +15,17 @@ namespace phpbb\db\migration\data\v320;
class remove_outdated_media extends \phpbb\db\migration\migration
{
+ // Following constants were deprecated in 3.2
+ // and moved from constants.php to compatibility_globals.php,
+ // thus define them as class constants
+ const ATTACHMENT_CATEGORY_WM = 2;
+ const ATTACHMENT_CATEGORY_RM = 3;
+ const ATTACHMENT_CATEGORY_QUICKTIME = 6;
+
protected $cat_id = array(
- ATTACHMENT_CATEGORY_WM,
- ATTACHMENT_CATEGORY_RM,
- ATTACHMENT_CATEGORY_QUICKTIME,
+ self::ATTACHMENT_CATEGORY_WM,
+ self::ATTACHMENT_CATEGORY_RM,
+ self::ATTACHMENT_CATEGORY_QUICKTIME,
);
static public function depends_on()
diff --git a/phpBB/phpbb/db/migration/tool/config.php b/phpBB/phpbb/db/migration/tool/config.php
index 33aa8ff026..a351c4858e 100644
--- a/phpBB/phpbb/db/migration/tool/config.php
+++ b/phpBB/phpbb/db/migration/tool/config.php
@@ -134,7 +134,7 @@ class config implements \phpbb\db\migration\tool\tool_interface
case 'remove':
$call = 'add';
- if (sizeof($arguments) == 1)
+ if (count($arguments) == 1)
{
$arguments[] = '';
}
diff --git a/phpBB/phpbb/db/migration/tool/config_text.php b/phpBB/phpbb/db/migration/tool/config_text.php
index 54b45f6f6d..5fe9a25b70 100644
--- a/phpBB/phpbb/db/migration/tool/config_text.php
+++ b/phpBB/phpbb/db/migration/tool/config_text.php
@@ -110,7 +110,7 @@ class config_text implements \phpbb\db\migration\tool\tool_interface
case 'remove':
$call = 'add';
- if (sizeof($arguments) == 1)
+ if (count($arguments) == 1)
{
$arguments[] = '';
}
diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php
index 238e063a87..7d2720c861 100644
--- a/phpBB/phpbb/db/migration/tool/module.php
+++ b/phpBB/phpbb/db/migration/tool/module.php
@@ -515,7 +515,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
$parent_id = $parent_id ?: 0;
// If automatic adding is in action, convert array back to string to simplify things
- if (is_array($data) && sizeof($data) == 1)
+ if (is_array($data) && count($data) == 1)
{
$data = $data['module_langname'];
}
@@ -528,7 +528,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
// Search for the parent module_langname
$ids = array_keys($this->module_categories, $parent_id);
- switch (sizeof($ids))
+ switch (count($ids))
{
// No parent with the given module_langname exist
case 0:
diff --git a/phpBB/phpbb/db/migration/tool/permission.php b/phpBB/phpbb/db/migration/tool/permission.php
index 9688420025..4b53aa32a7 100644
--- a/phpBB/phpbb/db/migration/tool/permission.php
+++ b/phpBB/phpbb/db/migration/tool/permission.php
@@ -442,7 +442,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface
}
);
- if (sizeof($auth_option))
+ if (count($auth_option))
{
return $this->permission_set($role_name, $auth_option, 'role', $has_permission);
}
diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php
index 6c026c3ae1..a425df56e8 100644
--- a/phpBB/phpbb/db/migrator.php
+++ b/phpBB/phpbb/db/migrator.php
@@ -632,7 +632,7 @@ class migrator
*/
protected function process_data_step($steps, $state, $revert = false)
{
- if (sizeof($steps) === 0)
+ if (count($steps) === 0)
{
return true;
}
@@ -659,7 +659,7 @@ class migrator
// Result will be null or true if everything completed correctly
// Stop after each update step, to let the updater control the script runtime
$result = $this->run_step($steps[$step], $last_result, $revert);
- if (($result !== null && $result !== true) || $step + 1 < sizeof($steps))
+ if (($result !== null && $result !== true) || $step + 1 < count($steps))
{
return array(
'result' => $result,
diff --git a/phpBB/phpbb/db/sql_insert_buffer.php b/phpBB/phpbb/db/sql_insert_buffer.php
index 18e4814a77..30e807b154 100644
--- a/phpBB/phpbb/db/sql_insert_buffer.php
+++ b/phpBB/phpbb/db/sql_insert_buffer.php
@@ -92,7 +92,7 @@ class sql_insert_buffer
// Flush buffer if it is full or when DB does not support multi inserts.
// In the later case, the buffer will always only contain one row.
- if (!$this->db->get_multi_insert() || sizeof($this->buffer) >= $this->max_buffered_rows)
+ if (!$this->db->get_multi_insert() || count($this->buffer) >= $this->max_buffered_rows)
{
return $this->flush();
}
@@ -104,7 +104,7 @@ class sql_insert_buffer
* Inserts a row set, i.e. an array of rows, by calling insert().
*
* Please note that it is in most cases better to use insert() instead of
- * first building a huge rowset. Or at least sizeof($rows) should be kept
+ * first building a huge rowset. Or at least count($rows) should be kept
* small.
*
* @param array $rows
diff --git a/phpBB/phpbb/db/tools/mssql.php b/phpBB/phpbb/db/tools/mssql.php
index 23b49aab44..cbedf9a5c4 100644
--- a/phpBB/phpbb/db/tools/mssql.php
+++ b/phpBB/phpbb/db/tools/mssql.php
@@ -49,18 +49,18 @@ class mssql extends tools
'STEXT' => '[varchar] (3000)',
'TEXT' => '[varchar] (8000)',
'MTEXT' => '[text]',
- 'XSTEXT_UNI'=> '[varchar] (100)',
- 'STEXT_UNI' => '[varchar] (255)',
- 'TEXT_UNI' => '[varchar] (4000)',
- 'MTEXT_UNI' => '[text]',
+ 'XSTEXT_UNI'=> '[nvarchar] (100)',
+ 'STEXT_UNI' => '[nvarchar] (255)',
+ 'TEXT_UNI' => '[nvarchar] (4000)',
+ 'MTEXT_UNI' => '[ntext]',
'TIMESTAMP' => '[int]',
'DECIMAL' => '[float]',
'DECIMAL:' => '[float]',
'PDECIMAL' => '[float]',
'PDECIMAL:' => '[float]',
- 'VCHAR_UNI' => '[varchar] (255)',
- 'VCHAR_UNI:'=> '[varchar] (%d)',
- 'VCHAR_CI' => '[varchar] (255)',
+ 'VCHAR_UNI' => '[nvarchar] (255)',
+ 'VCHAR_UNI:'=> '[nvarchar] (%d)',
+ 'VCHAR_CI' => '[nvarchar] (255)',
'VARBINARY' => '[varchar] (255)',
),
@@ -80,18 +80,18 @@ class mssql extends tools
'STEXT' => '[varchar] (3000)',
'TEXT' => '[varchar] (8000)',
'MTEXT' => '[text]',
- 'XSTEXT_UNI'=> '[varchar] (100)',
- 'STEXT_UNI' => '[varchar] (255)',
- 'TEXT_UNI' => '[varchar] (4000)',
- 'MTEXT_UNI' => '[text]',
+ 'XSTEXT_UNI'=> '[nvarchar] (100)',
+ 'STEXT_UNI' => '[nvarchar] (255)',
+ 'TEXT_UNI' => '[nvarchar] (4000)',
+ 'MTEXT_UNI' => '[ntext]',
'TIMESTAMP' => '[int]',
'DECIMAL' => '[float]',
'DECIMAL:' => '[float]',
'PDECIMAL' => '[float]',
'PDECIMAL:' => '[float]',
- 'VCHAR_UNI' => '[varchar] (255)',
- 'VCHAR_UNI:'=> '[varchar] (%d)',
- 'VCHAR_CI' => '[varchar] (255)',
+ 'VCHAR_UNI' => '[nvarchar] (255)',
+ 'VCHAR_UNI:'=> '[nvarchar] (%d)',
+ 'VCHAR_CI' => '[nvarchar] (255)',
'VARBINARY' => '[varchar] (255)',
),
);
@@ -440,7 +440,7 @@ class mssql extends tools
{
$result = $this->sql_index_drop($table_name, $index_name);
$statements = array_merge($statements, $result);
- if (sizeof($index_data) > 1)
+ if (count($index_data) > 1)
{
// Remove this column from the index and recreate it
$recreate_indexes[$index_name] = array_diff($index_data, array($column_name));
@@ -448,6 +448,10 @@ class mssql extends tools
}
}
+ // Drop primary keys depending on this column
+ $result = $this->mssql_get_drop_default_primary_key_queries($table_name, $column_name);
+ $statements = array_merge($statements, $result);
+
// Drop default value constraint
$result = $this->mssql_get_drop_default_constraints_queries($table_name, $column_name);
$statements = array_merge($statements, $result);
@@ -541,10 +545,7 @@ class mssql extends tools
{
$statements = array();
- if ($this->mssql_is_sql_server_2000())
- {
- $this->check_index_name_length($table_name, $index_name);
- }
+ $this->check_index_name_length($table_name, $index_name);
// remove index length
$column = preg_replace('#:.*$#', '', $column);
@@ -555,6 +556,21 @@ class mssql extends tools
}
/**
+ * {@inheritdoc}
+ */
+ protected function get_max_index_name_length()
+ {
+ if ($this->mssql_is_sql_server_2000())
+ {
+ return parent::get_max_index_name_length();
+ }
+ else
+ {
+ return 128;
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
function sql_list_index($table_name)
@@ -685,6 +701,38 @@ class mssql extends tools
}
/**
+ * Get queries to drop the primary keys depending on the specified column
+ *
+ * We need to drop primary keys depending on this column before being able
+ * to delete them.
+ *
+ * @param string $table_name
+ * @param string $column_name
+ * @return array Array with SQL statements
+ */
+ protected function mssql_get_drop_default_primary_key_queries($table_name, $column_name)
+ {
+ $statements = array();
+
+ $sql = "SELECT ccu.CONSTRAINT_NAME, ccu.COLUMN_NAME
+ FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
+ JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON tc.CONSTRAINT_NAME = ccu.Constraint_name
+ WHERE tc.TABLE_NAME = '{$table_name}'
+ AND tc.CONSTRAINT_TYPE = 'Primary Key'
+ AND ccu.COLUMN_NAME = '{$column_name}'";
+
+ $result = $this->db->sql_query($sql);
+
+ while ($primary_key = $this->db->sql_fetchrow($result))
+ {
+ $statements[] = 'ALTER TABLE [' . $table_name . '] DROP CONSTRAINT [' . $primary_key['CONSTRAINT_NAME'] . ']';
+ }
+ $this->db->sql_freeresult($result);
+
+ return $statements;
+ }
+
+ /**
* Checks to see if column is an identity column
*
* Identity columns cannot have defaults set for them.
diff --git a/phpBB/phpbb/db/tools/tools.php b/phpBB/phpbb/db/tools/tools.php
index 2f891e43d5..d21d34b8a9 100644
--- a/phpBB/phpbb/db/tools/tools.php
+++ b/phpBB/phpbb/db/tools/tools.php
@@ -1561,7 +1561,8 @@ class tools implements tools_interface
*/
protected function check_index_name_length($table_name, $index_name, $throw_error = true)
{
- if (strlen($index_name) > 30)
+ $max_index_name_length = $this->get_max_index_name_length();
+ if (strlen($index_name) > $max_index_name_length)
{
// Try removing the table prefix if it's at the beginning
$table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
@@ -1582,7 +1583,7 @@ class tools implements tools_interface
if ($throw_error)
{
- trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR);
+ trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is $max_index_name_length characters.", E_USER_ERROR);
}
}
@@ -1590,6 +1591,16 @@ class tools implements tools_interface
}
/**
+ * Get maximum index name length. Might vary depending on db type
+ *
+ * @return int Maximum index name length
+ */
+ protected function get_max_index_name_length()
+ {
+ return 30;
+ }
+
+ /**
* {@inheritDoc}
*/
function sql_list_index($table_name)