diff options
author | David Colón <david@davidiq.com> | 2017-01-25 16:45:04 -0500 |
---|---|---|
committer | David Colón <david@davidiq.com> | 2017-01-26 08:43:39 -0500 |
commit | fae78b4c011de598e4e05e26ff3129610ae087a0 (patch) | |
tree | d45c2dad2d536208ac50b2d8f94f259d0b2ad5f2 /phpBB/phpbb/db/tools/mssql.php | |
parent | c53054f2b7bb83a5b3ec39f310c8ea37bffa95ab (diff) | |
download | forums-fae78b4c011de598e4e05e26ff3129610ae087a0.tar forums-fae78b4c011de598e4e05e26ff3129610ae087a0.tar.gz forums-fae78b4c011de598e4e05e26ff3129610ae087a0.tar.bz2 forums-fae78b4c011de598e4e05e26ff3129610ae087a0.tar.xz forums-fae78b4c011de598e4e05e26ff3129610ae087a0.zip |
[ticket/15047] Do not set default for identity cols
Diffstat (limited to 'phpBB/phpbb/db/tools/mssql.php')
-rw-r--r-- | phpBB/phpbb/db/tools/mssql.php | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/phpBB/phpbb/db/tools/mssql.php b/phpBB/phpbb/db/tools/mssql.php index 3518fb416b..81e7424136 100644 --- a/phpBB/phpbb/db/tools/mssql.php +++ b/phpBB/phpbb/db/tools/mssql.php @@ -597,7 +597,7 @@ class mssql extends tools // Change the column $statements[] = 'ALTER TABLE [' . $table_name . '] ALTER COLUMN [' . $column_name . '] ' . $column_data['column_type_sql']; - if (!empty($column_data['default'])) + if (!empty($column_data['default']) && !$this->mssql_is_column_identity($table_name, $column_name)) { // Add new default value constraint $statements[] = 'ALTER TABLE [' . $table_name . '] ADD CONSTRAINT [DF_' . $table_name . '_' . $column_name . '_1] ' . $column_data['default'] . ' FOR [' . $column_name . ']'; @@ -675,6 +675,37 @@ class mssql extends tools } /** + * Checks to see if column is an identity column + * + * Identity columns cannot have defaults set for them. + * + * @param string $table_name + * @param string $column_name + * @return bool true if identity, false if not + */ + protected function mssql_is_column_identity($table_name, $column_name) + { + if ($this->mssql_is_sql_server_2000()) + { + // http://msdn.microsoft.com/en-us/library/aa175912%28v=sql.80%29.aspx + // Deprecated in SQL Server 2005 + $sql = "SELECT COLUMNPROPERTY(object_id('{$table_name}'), '{$column_name}', 'IsIdentity') AS is_identity"; + } + else + { + $sql = "SELECT is_identity FROM sys.columns + WHERE object_id = object_id('{$table_name}') + AND name = '{$column_name}'"; + } + + $result = $this->db->sql_query($sql); + $is_identity = $this->db->sql_fetchfield('is_identity'); + $this->db->sql_freeresult($result); + + return (bool)$is_identity; + } + + /** * Get a list with existing indexes for the column * * @param string $table_name |