Skip to content

Commit

Permalink
Add support for biginteger on SQLserver.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 30, 2012
1 parent 8d8f4b5 commit d4ee62b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -86,16 +86,17 @@ class Sqlserver extends DboSource {
*/
public $columns = array(
'primary_key' => array('name' => 'IDENTITY (1, 1) NOT NULL'),
'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'),
'string' => array('name' => 'nvarchar', 'limit' => '255'),
'text' => array('name' => 'nvarchar', 'limit' => 'MAX'),
'integer' => array('name' => 'int', 'formatter' => 'intval'),
'biginteger' => array('name' => 'bigint'),
'float' => array('name' => 'numeric', 'formatter' => 'floatval'),
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
'time' => array('name' => 'datetime', 'format' => 'H:i:s', 'formatter' => 'date'),
'date' => array('name' => 'datetime', 'format' => 'Y-m-d', 'formatter' => 'date'),
'binary' => array('name' => 'varbinary'),
'boolean' => array('name' => 'bit')
'time' => array('name' => 'datetime', 'format' => 'H:i:s', 'formatter' => 'date'),
'date' => array('name' => 'datetime', 'format' => 'Y-m-d', 'formatter' => 'date'),
'binary' => array('name' => 'varbinary'),
'boolean' => array('name' => 'bit')
);

/**
Expand Down Expand Up @@ -399,6 +400,9 @@ public function column($real) {
if ($col == 'bit') {
return 'boolean';
}
if (strpos($col, 'bigint') !== false) {
return 'biginteger';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
Expand Down Expand Up @@ -643,7 +647,7 @@ public function insertMulti($table, $fields, $values) {
*/
public function buildColumn($column) {
$result = parent::buildColumn($column);
$result = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', $result);
$result = preg_replace('/(bigint|int|integer)\([0-9]+\)/i', '$1', $result);
$result = preg_replace('/(bit)\([0-9]+\)/i', '$1', $result);
if (strpos($result, 'DEFAULT NULL') !== false) {
if (isset($column['default']) && $column['default'] === '') {
Expand Down
Expand Up @@ -553,6 +553,14 @@ public function testBuildColumn() {
$result = $this->db->buildColumn($column);
$expected = "[checked] bit DEFAULT '1'";
$this->assertEquals($expected, $result);

$column = array(
'name' => 'huge',
'type' => 'biginteger',
);
$result = $this->db->buildColumn($column);
$expected = "[huge] bigint";
$this->assertEquals($expected, $result);
}

/**
Expand Down

0 comments on commit d4ee62b

Please sign in to comment.