aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db/db_tools.php
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2011-04-29 00:39:36 -0400
committerOleg Pudeyev <oleg@bsdpower.com>2011-04-29 02:10:42 -0400
commit9f34aa0b79456f5d2d60f62361f483c76a3f89dd (patch)
tree7149b65e6e90521398887e69c7d94275cbb9b20d /phpBB/includes/db/db_tools.php
parent3cb1b90ca6afcf0533f8f398f2a3f4066b697ed3 (diff)
downloadforums-9f34aa0b79456f5d2d60f62361f483c76a3f89dd.tar
forums-9f34aa0b79456f5d2d60f62361f483c76a3f89dd.tar.gz
forums-9f34aa0b79456f5d2d60f62361f483c76a3f89dd.tar.bz2
forums-9f34aa0b79456f5d2d60f62361f483c76a3f89dd.tar.xz
forums-9f34aa0b79456f5d2d60f62361f483c76a3f89dd.zip
[ticket/10003] Ported 54c22ae52a0e18232cac8fed342ea52f2e2a793d to db_tools.
This diff applied cleanly. PHPBB3-10003
Diffstat (limited to 'phpBB/includes/db/db_tools.php')
-rw-r--r--phpBB/includes/db/db_tools.php110
1 files changed, 109 insertions, 1 deletions
diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php
index d9ff811e34..a793a2f313 100644
--- a/phpBB/includes/db/db_tools.php
+++ b/phpBB/includes/db/db_tools.php
@@ -697,7 +697,8 @@ class phpbb_db_tools
{
if ($column_exists)
{
- $sqlite_data[$table]['change_columns'][] = $result;
+ continue;
+// $sqlite_data[$table]['change_columns'][] = $result;
}
else
{
@@ -719,6 +720,11 @@ class phpbb_db_tools
{
foreach ($indexes as $index_name)
{
+ if (!$this->sql_index_exists($table, $index_name))
+ {
+ continue;
+ }
+
$result = $this->sql_index_drop($table, $index_name);
if ($this->return_statements)
@@ -779,6 +785,11 @@ class phpbb_db_tools
{
foreach ($index_array as $index_name => $column)
{
+ if ($this->sql_index_exists($table, $index_name))
+ {
+ continue;
+ }
+
$result = $this->sql_create_unique_index($table, $index_name, $column);
if ($this->return_statements)
@@ -796,6 +807,11 @@ class phpbb_db_tools
{
foreach ($index_array as $index_name => $column)
{
+ if ($this->sql_index_exists($table, $index_name))
+ {
+ continue;
+ }
+
$result = $this->sql_create_index($table, $index_name, $column);
if ($this->return_statements)
@@ -1105,6 +1121,98 @@ class phpbb_db_tools
}
/**
+ * Check if a specified index exists in table
+ *
+ * @param string $table_name Table to check the index at
+ * @param string $index_name The index name to check
+ *
+ * @return bool True if index exists, else false
+ */
+ function sql_index_exists($table_name, $index_name)
+ {
+ if ($this->sql_layer == 'mssql')
+ {
+ $sql = "EXEC sp_statistics '$table_name'";
+ $result = $this->db->sql_query($sql);
+
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if ($row['TYPE'] == 3)
+ {
+ if (strtolower($row['INDEX_NAME']) == strtolower($index_name))
+ {
+ $this->db->sql_freeresult($result);
+ return true;
+ }
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ return false;
+ }
+
+ switch ($this->sql_layer)
+ {
+ case 'firebird':
+ $sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
+ FROM RDB\$INDICES
+ WHERE RDB\$RELATION_NAME = " . strtoupper($table_name) . "
+ AND RDB\$UNIQUE_FLAG IS NULL
+ AND RDB\$FOREIGN_KEY IS NULL";
+ $col = 'index_name';
+ break;
+
+ case 'postgres':
+ $sql = "SELECT ic.relname as index_name
+ FROM pg_class bc, pg_class ic, pg_index i
+ WHERE (bc.oid = i.indrelid)
+ AND (ic.oid = i.indexrelid)
+ AND (bc.relname = '" . $table_name . "')
+ AND (i.indisunique != 't')
+ AND (i.indisprimary != 't')";
+ $col = 'index_name';
+ break;
+
+ case 'mysql_40':
+ case 'mysql_41':
+ $sql = 'SHOW KEYS
+ FROM ' . $table_name;
+ $col = 'Key_name';
+ break;
+
+ case 'oracle':
+ $sql = "SELECT index_name
+ FROM user_indexes
+ WHERE table_name = '" . $table_name . "'
+ AND generated = 'N'";
+ break;
+
+ case 'sqlite':
+ $sql = "PRAGMA index_info('" . $table_name . "');";
+ $col = 'name';
+ break;
+ }
+
+ $result = $this->db->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ if (($this->sql_layer == 'mysql_40' || $this->sql_layer == 'mysql_41') && !$row['Non_unique'])
+ {
+ continue;
+ }
+
+ if (strtolower($row[$col]) == strtolower($index_name))
+ {
+ $this->db->sql_freeresult($result);
+ return true;
+ }
+ }
+ $this->db->sql_freeresult($result);
+
+ return false;
+ }
+
+ /**
* Private method for performing sql statements (either execute them or return them)
* @access private
*/