mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding tests to DboSqlite::buildColumn
Adding collate field parameter to DboSqlite. Removing duplicated code from DboSource, adding parent call instead.
This commit is contained in:
parent
4bf807b4be
commit
2a8858e928
2 changed files with 71 additions and 26 deletions
|
@ -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 @@ class DboSqlite extends DboSource {
|
|||
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 @@ class DboSqliteTest extends CakeTestCase {
|
|||
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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue