Skip to content

Commit

Permalink
Updating varchar, text columns to use nvarchar.
Browse files Browse the repository at this point in the history
This storage type stores unicode properly, and is the
saner default datatype for most applications.
Fixes #1321
  • Loading branch information
markstory committed Jun 24, 2011
1 parent 6bcfd19 commit 08f1afe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
21 changes: 16 additions & 5 deletions lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -20,9 +20,10 @@
App::uses('DboSource', 'Model/Datasource');

/**
* MS SQL layer for DBO
* Dbo driver for SQLServer
*
* Long description for class
* A Dbo driver for SQLServer 2008 and higher. Requires the `sqlsrv`
* and `pdo_sqlsrv` extensions to be enabled.
*
* @package cake.libs.model.datasources.dbo
*/
Expand Down Expand Up @@ -71,7 +72,7 @@ class Sqlserver extends DboSource {
*/
protected $_baseConfig = array(
'persistent' => true,
'host' => '(local)\sqlexpress',
'host' => 'localhost\SQLEXPRESS',
'login' => '',
'password' => '',
'database' => 'cake'
Expand All @@ -84,8 +85,8 @@ class Sqlserver extends DboSource {
*/
public $columns = array(
'primary_key' => array('name' => 'IDENTITY (1, 1) NOT NULL'),
'string' => array('name' => 'varchar', 'limit' => '255'),
'text' => array('name' => 'text'),
'string' => array('name' => 'nvarchar', 'limit' => '255'),
'text' => array('name' => 'nvarchar', 'limit' => 'MAX'),
'integer' => array('name' => 'int', 'formatter' => 'intval'),
'float' => array('name' => 'numeric', 'formatter' => 'floatval'),
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
Expand Down Expand Up @@ -114,8 +115,18 @@ class Sqlserver extends DboSource {
*/
private $__lastQueryHadError = false;

/**
* Magic column name used to provide pagination support for SQLServer 2008
* which lacks proper limit/offset support.
*/
const ROW_COUNTER = '_cake_page_rownum_';

/**
* The version of SQLServer being used. If greater than 11
* Normal limit offset statements will be used
*
* @var string
*/
protected $_version;

/**
Expand Down
17 changes: 11 additions & 6 deletions lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php
Expand Up @@ -486,32 +486,37 @@ public function testBuildColumn() {

$column = array('type' => 'string', 'name' => 'name');
$result = $this->db->buildColumn($column);
$expected = '[name] varchar(255) NULL';
$expected = '[name] nvarchar(255) NULL';
$this->assertEqual($expected, $result);

$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => '', 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] varchar(255) DEFAULT \'\' NOT NULL';
$expected = '[name] nvarchar(255) DEFAULT \'\' NOT NULL';
$this->assertEqual($expected, $result);

$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] varchar(255) NOT NULL';
$expected = '[name] nvarchar(255) NOT NULL';
$this->assertEqual($expected, $result);

$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => null, 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] varchar(255) NOT NULL';
$expected = '[name] nvarchar(255) NOT NULL';
$this->assertEqual($expected, $result);

$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => null, 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] varchar(255) NULL';
$expected = '[name] nvarchar(255) NULL';
$this->assertEqual($expected, $result);

$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => '', 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] varchar(255) DEFAULT \'\'';
$expected = '[name] nvarchar(255) DEFAULT \'\'';
$this->assertEqual($expected, $result);

$column = array('name' => 'body', 'type' => 'text');
$result = $this->db->buildColumn($column);
$expected = '[body] nvarchar(MAX)';
$this->assertEqual($expected, $result);
}
/**
Expand Down

0 comments on commit 08f1afe

Please sign in to comment.