Fixing support for nchar and nvarchar fields in SQL server.

These fields report their length as double of what its defined.
This commit is contained in:
Mark Story 2011-06-22 11:35:02 -07:00
parent 1df0801c33
commit 1a155c80c0
2 changed files with 19 additions and 0 deletions

View file

@ -439,6 +439,9 @@ class Sqlserver extends DboSource {
if ($length->Length == -1 && strpos($length->Type, 'char') !== false) {
return null;
}
if (in_array($length->Type, array('nchar', 'nvarchar'))) {
return floor($length->Length / 2);
}
return $length->Length;
}
return parent::length($length);

View file

@ -415,6 +415,15 @@ class SqlserverTest extends CakeTestCase {
'Null' => 'YES',
'Size' => ''
),
(object) array(
'Default' => '',
'Field' => 'id',
'Key' => 1,
'Type' => 'nchar',
'Length' => 72,
'Null' => 'NO',
'Size' => ''
)
));
$this->db->executeResultsStack = array($SqlserverTableDescription);
$dummyModel = $this->model;
@ -437,6 +446,13 @@ class SqlserverTest extends CakeTestCase {
'null' => true,
'default' => '',
'length' => null
),
'id' => array(
'type' => 'string',
'null' => false,
'default' => '',
'length' => 36,
'key' => 'primary'
)
);
$this->assertEqual($expected, $result);