Skip to content

Commit

Permalink
Add bigint support for Sqlite.
Browse files Browse the repository at this point in the history
* Update SQLite for biginteger.
* Update CakeSchema tests for integration purposes.
  • Loading branch information
markstory committed Aug 30, 2012
1 parent 7bad865 commit 8d8f4b5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
16 changes: 15 additions & 1 deletion lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -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'),
Expand Down Expand Up @@ -248,9 +249,22 @@ public function column($real) {
$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';
}
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Test/Case/Model/CakeSchemaTest.php
Expand Up @@ -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()
Expand Down
58 changes: 56 additions & 2 deletions lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -253,6 +253,16 @@ public function testBuildColumn() {
$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);
}

/**
Expand All @@ -262,7 +272,11 @@ public function testBuildColumn() {
*/
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);
Expand Down Expand Up @@ -310,6 +324,46 @@ public function testDescribe() {
$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
*
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Test/Fixture/DatatypeFixture.php
Expand Up @@ -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),
);

Expand All @@ -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),
);
}

0 comments on commit 8d8f4b5

Please sign in to comment.