Browse Source

Add bigint support for Sqlite.

* Update SQLite for biginteger.
* Update CakeSchema tests for integration purposes.
mark_story 13 years ago
parent
commit
8d8f4b5c5d

+ 15 - 1
lib/Cake/Model/Datasource/Database/Sqlite.php

@@ -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';
 		}

+ 1 - 0
lib/Cake/Test/Case/Model/CakeSchemaTest.php

@@ -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()

+ 56 - 2
lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php

@@ -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);
@@ -311,6 +325,46 @@ class SqliteTest extends CakeTestCase {
 	}
 
 /**
+ * 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

+ 2 - 1
lib/Cake/Test/Fixture/DatatypeFixture.php

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