Skip to content

Commit

Permalink
Adding tests to DboSqlite::buildColumn
Browse files Browse the repository at this point in the history
Adding collate field parameter to DboSqlite.
Removing duplicated code from DboSource, adding parent call instead.
  • Loading branch information
markstory committed Oct 29, 2009
1 parent 4bf807b commit 2a8858e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 26 deletions.
37 changes: 11 additions & 26 deletions cake/libs/model/datasources/dbo/dbo_sqlite.php
Expand Up @@ -107,6 +107,16 @@ class DboSqlite extends DboSource {
'boolean' => array('name' => 'boolean')
);

/**
* List of engine specific additional field parameters used on table creating
*
* @var array
* @access public
*/
var $fieldParameters = array(
'collate' => array('value' => 'COLLATE', 'quote' => false, 'join' => ' ', 'column' => 'Collate', 'position' => 'afterDefault'),
);

/**
* Connects to the database using config['database'] as a filename.
*
Expand Down Expand Up @@ -481,32 +491,7 @@ function buildColumn($column) {
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
return $this->name($name) . ' ' . $this->columns['primary_key']['name'];
}
if (isset($real['limit']) || isset($real['length']) || isset($column['limit']) || isset($column['length'])) {
if (isset($column['length'])) {
$length = $column['length'];
} elseif (isset($column['limit'])) {
$length = $column['limit'];
} elseif (isset($real['length'])) {
$length = $real['length'];
} else {
$length = $real['limit'];
}
$out .= '(' . $length . ')';
}
if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
$out .= ' ' . $this->columns['primary_key']['name'];
} elseif (isset($column['key']) && $column['key'] == 'primary') {
$out .= ' NOT NULL';
} elseif (isset($column['default']) && isset($column['null']) && $column['null'] == false) {
$out .= ' DEFAULT ' . $this->value($column['default'], $type) . ' NOT NULL';
} elseif (isset($column['default'])) {
$out .= ' DEFAULT ' . $this->value($column['default'], $type);
} elseif (isset($column['null']) && $column['null'] == true) {
$out .= ' DEFAULT NULL';
} elseif (isset($column['null']) && $column['null'] == false) {
$out .= ' NOT NULL';
}
return $out;
return parent::buildColumn($column);
}

/**
Expand Down
60 changes: 60 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php
Expand Up @@ -222,6 +222,66 @@ function testCacheKeyName() {
Configure::write('Cache.disable', true);
}

/**
* test building columns with SQLite
*
* @return void
**/
function testBuildColumn() {
$data = array(
'name' => 'int_field',
'type' => 'integer',
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '"int_field" integer(11) NOT NULL';
$this->assertEqual($result, $expected);

$data = array(
'name' => 'name',
'type' => 'string',
'length' => 20,
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '"name" varchar(20) NOT NULL';
$this->assertEqual($result, $expected);

$data = array(
'name' => 'testName',
'type' => 'string',
'length' => 20,
'default' => null,
'null' => true,
'collate' => 'NOCASE'
);
$result = $this->db->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE';
$this->assertEqual($result, $expected);

$data = array(
'name' => 'testName',
'type' => 'string',
'length' => 20,
'default' => 'test-value',
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT \'test-value\' NOT NULL';
$this->assertEqual($result, $expected);

$data = array(
'name' => 'testName',
'type' => 'integer',
'length' => 10,
'default' => 10,
'null' => false,
);
$result = $this->db->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL';
$this->assertEqual($result, $expected);
}

/**
* test describe() and normal results.
*
Expand Down

0 comments on commit 2a8858e

Please sign in to comment.