phpBB

Code Changes

File: phpbb/db/tools/mssql.php

  Unmodified   Added   Modified   Removed
Line 49Line 49
				'STEXT'		=> '[varchar] (3000)',
'TEXT' => '[varchar] (8000)',
'MTEXT' => '[text]',

				'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]',

				'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)',
),


				'VARBINARY'	=> '[varchar] (255)',
),


Line 80Line 80
				'STEXT'		=> '[varchar] (3000)',
'TEXT' => '[varchar] (8000)',
'MTEXT' => '[text]',

				'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]',

				'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)',
),
);

				'VARBINARY'	=> '[varchar] (255)',
),
);

Line 440Line 440
			{
$result = $this->sql_index_drop($table_name, $index_name);
$statements = array_merge($statements, $result);

			{
$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));
}
}
}

				{
// Remove this column from the index and recreate it
$recreate_indexes[$index_name] = array_diff($index_data, array($column_name));
}
}
}

 

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


// Drop default value constraint
$result = $this->mssql_get_drop_default_constraints_queries($table_name, $column_name);

Line 477Line 481
	{
$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 528
	{
$statements = array();


	{
$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);

 
		}


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



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


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

return $this->_sql_run_sql($statements);

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

return $this->_sql_run_sql($statements);

 
	}

/**
* {@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;
}

	}

/**

	}

/**

Line 601Line 623
		// 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 698
		$this->db->sql_freeresult($result);

return $statements;

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

return $statements;

 
	}

/**
* 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.
*
* @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 802
						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');
}