Add bigint support for Sqlite.

* Update SQLite for biginteger.
* Update CakeSchema tests for integration purposes.
This commit is contained in:
mark_story 2012-08-30 14:26:17 +01:00
parent 7bad865d6e
commit 8d8f4b5c5d
4 changed files with 74 additions and 4 deletions

View file

@ -70,6 +70,7 @@ class Sqlite extends DboSource {
'string' => array('name' => 'varchar', 'limit' => '255'),
'text' => array('name' => 'text'),
'integer' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'),
'biginteger' => array('name' => 'bigint', 'limit' => 20),
'float' => array('name' => 'float', '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'),
@ -248,9 +249,22 @@ class Sqlite extends DboSource {
$limit = null;
@list($col, $limit) = explode('(', $col);
if (in_array($col, array('text', 'integer', 'float', 'boolean', 'timestamp', 'date', 'datetime', 'time'))) {
$standard = array(
'text',
'integer',
'float',
'boolean',
'timestamp',
'date',
'datetime',
'time'
);
if (in_array($col, $standard)) {
return $col;
}
if ($col === 'bigint') {
return 'biginteger';
}
if (strpos($col, 'char') !== false) {
return 'string';
}

View file

@ -198,6 +198,7 @@ class TestAppSchema extends CakeSchema {
public $datatypes = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''),
'huge_int' => array('type' => 'biginteger'),
'bool' => array('type' => 'boolean', 'null' => false, 'default' => false),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
'tableParameters' => array()

View file

@ -77,7 +77,7 @@ class SqliteTest extends CakeTestCase {
*
* @var object
*/
public $fixtures = array('core.user', 'core.uuid');
public $fixtures = array('core.user', 'core.uuid', 'core.datatype');
/**
* Actual DB connection used in testing
@ -253,6 +253,16 @@ class SqliteTest extends CakeTestCase {
$result = $this->Dbo->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT 10 NOT NULL';
$this->assertEquals($expected, $result);
$data = array(
'name' => 'huge',
'type' => 'biginteger',
'length' => 20,
'null' => false,
);
$result = $this->Dbo->buildColumn($data);
$expected = '"huge" bigint(20) NOT NULL';
$this->assertEquals($expected, $result);
}
/**
@ -262,7 +272,11 @@ class SqliteTest extends CakeTestCase {
*/
public function testDescribe() {
$this->loadFixtures('User');
$Model = new Model(array('name' => 'User', 'ds' => 'test', 'table' => 'users'));
$Model = new Model(array(
'name' => 'User',
'ds' => 'test',
'table' => 'users'
));
$this->Dbo->cacheSources = true;
Configure::write('Cache.disable', false);
@ -310,6 +324,46 @@ class SqliteTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test that datatypes are reflected
*
* @return void
*/
public function testDatatypes() {
$this->loadFixtures('Datatype');
$Model = new Model(array(
'name' => 'Datatype',
'ds' => 'test',
'table' => 'datatypes'
));
$result = $this->Dbo->describe($Model);
$expected = array(
'id' => array(
'type' => 'integer',
'null' => false,
'default' => 0,
'key' => 'primary'
),
'float_field' => array(
'type' => 'float',
'length' => '5,2',
'null' => false,
'default' => null
),
'huge_int' => array(
'type' => 'bigint',
'length' => '20',
'null' => true,
'default' => null
),
'bool' => array(
'type' => 'boolean',
'null' => false,
'default' => false
),
);
}
/**
* test that describe does not corrupt UUID primary keys
*

View file

@ -39,6 +39,7 @@ class DatatypeFixture extends CakeTestFixture {
public $fields = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'float_field' => array('type' => 'float', 'length' => '5,2', 'null' => false, 'default' => null),
'huge_int' => array('type' => 'biginteger'),
'bool' => array('type' => 'boolean', 'null' => false, 'default' => false),
);
@ -48,6 +49,6 @@ class DatatypeFixture extends CakeTestFixture {
* @var array
*/
public $records = array(
array('id' => 1, 'float_field' => 42.23, 'bool' => 0),
array('id' => 1, 'float_field' => 42.23, 'huge_int' => '123456789123456789123456789', 'bool' => 0),
);
}