diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index aa6311be3..d106dac34 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -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); } /** diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php index 75acb73e6..34648b420 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php @@ -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. *