Permalink
Browse files

Fixing support for nchar and nvarchar fields in SQL server.

These fields report their length as double of what its defined.
  • Loading branch information...
1 parent 1df0801 commit 1a155c80c0aea26a57a490e457cbfe3f0e75e631 @markstory markstory committed Jun 22, 2011
@@ -439,6 +439,9 @@ public function length($length) {
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);
@@ -415,6 +415,15 @@ public function testDescribe() {
'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 @@ public function testDescribe() {
'null' => true,
'default' => '',
'length' => null
+ ),
+ 'id' => array(
+ 'type' => 'string',
+ 'null' => false,
+ 'default' => '',
+ 'length' => 36,
+ 'key' => 'primary'
)
);
$this->assertEqual($expected, $result);

0 comments on commit 1a155c8

Please sign in to comment.