diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index d53605fc7..f1efb9258 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -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); diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php index 02ce1e617..12c14e3af 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php @@ -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);