API CHANGE: Added MSSQLDatabase::set_collation() to let you set the collation for the nvarchar fields.

This commit is contained in:
Sam Minnee 2010-06-03 00:58:31 +00:00
parent 07ea9353e1
commit feebe26208

View File

@ -82,6 +82,19 @@ class MSSQLDatabase extends SS_Database {
*/ */
protected $fullTextEnabled = null; protected $fullTextEnabled = null;
/**
* @ignore
*/
protected static $collation = null;
/**
* Set the default collation of the MSSQL nvarchar fields that we create.
* We don't apply this to the database as a whole, so that we can use unicode collations.
*/
public static function set_collation($collation) {
self::$collation = $collation;
}
/** /**
* Connect to a MS SQL database. * Connect to a MS SQL database.
* @param array $parameters An map of parameters, which should include: * @param array $parameters An map of parameters, which should include:
@ -577,7 +590,7 @@ class MSSQLDatabase extends SS_Database {
public function fieldList($table) { public function fieldList($table) {
//This gets us more information than we need, but I've included it all for the moment.... //This gets us more information than we need, but I've included it all for the moment....
$fieldRecords = $this->query("SELECT ordinal_position, column_name, data_type, column_default, $fieldRecords = $this->query("SELECT ordinal_position, column_name, data_type, column_default,
is_nullable, character_maximum_length, numeric_precision, numeric_scale is_nullable, character_maximum_length, numeric_precision, numeric_scale, collation_name
FROM information_schema.columns WHERE table_name = '$table' FROM information_schema.columns WHERE table_name = '$table'
ORDER BY ordinal_position;"); ORDER BY ordinal_position;");
@ -629,6 +642,7 @@ class MSSQLDatabase extends SS_Database {
} }
break; break;
case 'nvarchar':
case 'varchar': case 'varchar':
//Check to see if there's a constraint attached to this column: //Check to see if there's a constraint attached to this column:
$constraint=$this->ColumnConstraints($table, $field['column_name']); $constraint=$this->ColumnConstraints($table, $field['column_name']);
@ -940,7 +954,8 @@ class MSSQLDatabase extends SS_Database {
* @return string * @return string
*/ */
public function text($values) { public function text($values) {
return 'nvarchar(max) null'; $collation = self::$collation ? "COLLATE " . self::$collation : "";
return "nvarchar(max) $collation null";
} }
/** /**
@ -960,7 +975,8 @@ class MSSQLDatabase extends SS_Database {
* @return string * @return string
*/ */
public function varchar($values) { public function varchar($values) {
return 'nvarchar(' . $values['precision'] . ') null'; $collation = self::$collation ? "COLLATE " . self::$collation : "";
return "nvarchar(" . $values['precision'] . ") $collation null";
} }
/** /**