Skip to content
Permalink
Browse files

Adding tests to DboSqlite::buildColumn

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 2a8858e928b9c447921a2860d8f4f904dc55126d
@@ -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.
*
@@ -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);
}
/**
@@ -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.
*

0 comments on commit 2a8858e

Please sign in to comment.
You can’t perform that action at this time.