Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add bigint support for Sqlite.

* Update SQLite for biginteger.
* Update CakeSchema tests for integration purposes.
  • Loading branch information...
commit 8d8f4b5c5da3470058ea1848565e87f3c7cae4fc 1 parent 7bad865
Mark Story markstory authored
16 lib/Cake/Model/Datasource/Database/Sqlite.php
View
@@ -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 @@ 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';
}
1  lib/Cake/Test/Case/Model/CakeSchemaTest.php
View
@@ -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()
58 lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php
View
@@ -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 @@ 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);
}
/**
@@ -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);
@@ -311,6 +325,46 @@ public function testDescribe() {
}
/**
+ * 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
*
* @return void
3  lib/Cake/Test/Fixture/DatatypeFixture.php
View
@@ -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),
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.