aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorDavid M <davidmj@users.sourceforge.net>2007-07-09 22:39:50 +0000
committerDavid M <davidmj@users.sourceforge.net>2007-07-09 22:39:50 +0000
commit84a16e2ac6e1490260e8501146fcf940b123a61a (patch)
tree199191acafee416681f44dc0d93cd5593c6ecbc8 /phpBB
parentc0ea9006c5baf32b5acab6ad7c0fb3cd03c2be41 (diff)
downloadforums-84a16e2ac6e1490260e8501146fcf940b123a61a.tar
forums-84a16e2ac6e1490260e8501146fcf940b123a61a.tar.gz
forums-84a16e2ac6e1490260e8501146fcf940b123a61a.tar.bz2
forums-84a16e2ac6e1490260e8501146fcf940b123a61a.tar.xz
forums-84a16e2ac6e1490260e8501146fcf940b123a61a.zip
- better PostgreSQL support for ALTER TABLE
- stress tested sql_list_index(), found some bugs in it :/ git-svn-id: file:///svn/phpbb/trunk@7855 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/install/database_update.php55
1 files changed, 46 insertions, 9 deletions
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index 64a9f369fc..33e4d406e8 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -937,6 +937,8 @@ function prepare_column_data($dbms, $column_data)
$sql = '';
+ $return_array = array();
+
switch ($dbms)
{
case 'firebird':
@@ -1011,14 +1013,23 @@ function prepare_column_data($dbms, $column_data)
break;
case 'postgres':
+ $return_array['column_type'] = $column_type;
+ $return_array['null'] = 'NOT NULL';
+
+ if (!is_null($column_data[1]))
+ {
+ $return_array['default'] = $column_data[1];
+ }
+
$sql .= " {$column_type} ";
- $sql .= 'NOT NULL';
+ $sql .= 'NOT NULL ';
$sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : '';
// Unsigned? Then add a CHECK contraint
if (in_array($orig_column_type, $unsigned_types))
{
+ $return_array['constraint'] = "CHECK ({$column_name} >= 0)";
$sql .= " CHECK ({$column_name} >= 0)";
}
break;
@@ -1040,9 +1051,9 @@ function prepare_column_data($dbms, $column_data)
break;
}
- return array(
- 'column_type_sql' => $sql,
- );
+ $return_array['column_type_sql'] = $sql;
+
+ return $return_array;
}
/**
@@ -1263,7 +1274,7 @@ function sql_index_drop($dbms, $index_name, $table_name)
case 'oracle':
case 'postgres':
case 'sqlite':
- $sql = 'DROP INDEX ' . $table_name . '_' . $index_name;
+ $sql = 'DROP INDEX ' . $table_name . '_' . $index_name;
_sql($sql, $errored, $error_ary);
break;
}
@@ -1476,6 +1487,16 @@ function sql_list_index($dbms, $table_name)
continue;
}
+ switch ($dbms)
+ {
+ case 'firebird':
+ case 'oracle':
+ case 'postgres':
+ case 'sqlite':
+ $row[$col] = substr($row[$col], strlen($table_name) + 1);
+ break;
+ }
+
$index_array[] = $row[$col];
}
$db->sql_freeresult($result);
@@ -1519,16 +1540,32 @@ function sql_column_change($dbms, $table_name, $column_name, $column_data)
break;
case 'postgres':
- $default_pos = strpos($column_data['column_type_sql'], ' DEFAULT');
+ $sql = 'ALTER TABLE ' . $table_name . ' ';
+
+ $sql_array = array();
+ $sql_array[] = 'ALTER COLUMN ' . $column_name . ' TYPE ' . $column_data['column_type'];
- if ($default_pos === false)
+ if ($column_data['null'] == 'NOT NULL')
{
- $sql = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN ' . $column_name . ' TYPE ' . $column_data['column_type_sql'];
+ $sql_array[] = 'ALTER COLUMN ' . $column_name . ' SET NOT NULL';
}
else
{
- $sql = 'ALTER TABLE ' . $table_name . ' ALTER COLUMN ' . $column_name . ' TYPE ' . substr($column_data['column_type_sql'], 0, $default_pos) . ', ALTER COLUMN ' . $column_name . ' SET ' . substr($column_data['column_type_sql'], $default_pos + 1);
+ $sql_array[] = 'ALTER COLUMN ' . $column_name . ' DROP NOT NULL';
+ }
+
+ if (isset($column_data['default']))
+ {
+ $sql_array[] = 'ALTER COLUMN ' . $column_name . " SET DEFAULT '" . $column_data['default'] . "'";
}
+
+ if (isset($column_data['constraint']))
+ {
+ $sql_array[] = 'ALTER COLUMN ' . $column_name . " ADD '" . $column_data['constraint'] . "'";
+ }
+
+ $sql .= implode(', ', $sql_array);
+
_sql($sql, $errored, $error_ary);
break;