phpBB

Code Changes

File: phpbb/db/tools/mssql.php

  Unmodified   Added   Modified   Removed
Line 477Line 477
	{
$statements = array();


	{
$statements = array();


		$statements[] = 'DROP INDEX ' . $table_name . '.' . $index_name;

		$statements[] = 'DROP INDEX [' . $table_name . '].[' . $index_name . ']';


return $this->_sql_run_sql($statements);
}


return $this->_sql_run_sql($statements);
}

Line 524Line 524
	{
$statements = array();


	{
$statements = array();


 
		if ($this->is_sql_server_2000())
{

		$this->check_index_name_length($table_name, $index_name);

		$this->check_index_name_length($table_name, $index_name);

 
		}


$statements[] = 'CREATE UNIQUE INDEX [' . $index_name . '] ON [' . $table_name . ']([' . implode('], [', $column) . '])';



$statements[] = 'CREATE UNIQUE INDEX [' . $index_name . '] ON [' . $table_name . ']([' . implode('], [', $column) . '])';


Line 538Line 541
	{
$statements = array();


	{
$statements = array();


 
		if ($this->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);


// remove index length
$column = preg_replace('#:.*$#', '', $column);

Line 601Line 607
		// Change the column
$statements[] = 'ALTER TABLE [' . $table_name . '] ALTER COLUMN [' . $column_name . '] ' . $column_data['column_type_sql'];


		// 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 . ']';

		{
// Add new default value constraint
$statements[] = 'ALTER TABLE [' . $table_name . '] ADD CONSTRAINT [DF_' . $table_name . '_' . $column_name . '_1] ' . $column_data['default'] . ' FOR [' . $column_name . ']';

Line 676Line 682
		$this->db->sql_freeresult($result);

return $statements;

		$this->db->sql_freeresult($result);

return $statements;

 
	}

/**
* 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;

	}

/**

	}

/**

Line 717Line 754
						AND cols.object_id = ix.object_id
WHERE ix.object_id = object_id('{$table_name}')
AND cols.name = '{$column_name}'

						AND cols.object_id = ix.object_id
WHERE ix.object_id = object_id('{$table_name}')
AND cols.name = '{$column_name}'

 
					AND ix.is_primary_key = 0

					AND ix.is_unique = " . ($unique ? '1' : '0');
}


					AND ix.is_unique = " . ($unique ? '1' : '0');
}