Skip to content
This repository
Browse code

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 authored August 30, 2012
16  lib/Cake/Model/Datasource/Database/Sqlite.php
@@ -70,6 +70,7 @@ class Sqlite extends DboSource {
70 70
 		'string' => array('name' => 'varchar', 'limit' => '255'),
71 71
 		'text' => array('name' => 'text'),
72 72
 		'integer' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'),
  73
+		'biginteger' => array('name' => 'bigint', 'limit' => 20),
73 74
 		'float' => array('name' => 'float', 'formatter' => 'floatval'),
74 75
 		'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
75 76
 		'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
@@ -248,9 +249,22 @@ public function column($real) {
248 249
 		$limit = null;
249 250
 		@list($col, $limit) = explode('(', $col);
250 251
 
251  
-		if (in_array($col, array('text', 'integer', 'float', 'boolean', 'timestamp', 'date', 'datetime', 'time'))) {
  252
+		$standard = array(
  253
+			'text',
  254
+			'integer',
  255
+			'float',
  256
+			'boolean',
  257
+			'timestamp',
  258
+			'date',
  259
+			'datetime',
  260
+			'time'
  261
+		);
  262
+		if (in_array($col, $standard)) {
252 263
 			return $col;
253 264
 		}
  265
+		if ($col === 'bigint') {
  266
+			return 'biginteger';
  267
+		}
254 268
 		if (strpos($col, 'char') !== false) {
255 269
 			return 'string';
256 270
 		}
1  lib/Cake/Test/Case/Model/CakeSchemaTest.php
@@ -198,6 +198,7 @@ class TestAppSchema extends CakeSchema {
198 198
 	public $datatypes = array(
199 199
 		'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
200 200
 		'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''),
  201
+		'huge_int' => array('type' => 'biginteger'),
201 202
 		'bool' => array('type' => 'boolean', 'null' => false, 'default' => false),
202 203
 		'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
203 204
 		'tableParameters' => array()
58  lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php
@@ -77,7 +77,7 @@ class SqliteTest extends CakeTestCase {
77 77
  *
78 78
  * @var object
79 79
  */
80  
-	public $fixtures = array('core.user', 'core.uuid');
  80
+	public $fixtures = array('core.user', 'core.uuid', 'core.datatype');
81 81
 
82 82
 /**
83 83
  * Actual DB connection used in testing
@@ -253,6 +253,16 @@ public function testBuildColumn() {
253 253
 		$result = $this->Dbo->buildColumn($data);
254 254
 		$expected = '"testName" integer(10) DEFAULT 10 NOT NULL';
255 255
 		$this->assertEquals($expected, $result);
  256
+
  257
+		$data = array(
  258
+			'name' => 'huge',
  259
+			'type' => 'biginteger',
  260
+			'length' => 20,
  261
+			'null' => false,
  262
+		);
  263
+		$result = $this->Dbo->buildColumn($data);
  264
+		$expected = '"huge" bigint(20) NOT NULL';
  265
+		$this->assertEquals($expected, $result);
256 266
 	}
257 267
 
258 268
 /**
@@ -262,7 +272,11 @@ public function testBuildColumn() {
262 272
  */
263 273
 	public function testDescribe() {
264 274
 		$this->loadFixtures('User');
265  
-		$Model = new Model(array('name' => 'User', 'ds' => 'test', 'table' => 'users'));
  275
+		$Model = new Model(array(
  276
+			'name' => 'User',
  277
+			'ds' => 'test',
  278
+			'table' => 'users'
  279
+		));
266 280
 
267 281
 		$this->Dbo->cacheSources = true;
268 282
 		Configure::write('Cache.disable', false);
@@ -311,6 +325,46 @@ public function testDescribe() {
311 325
 	}
312 326
 
313 327
 /**
  328
+ * Test that datatypes are reflected
  329
+ *
  330
+ * @return void
  331
+ */
  332
+	public function testDatatypes() {
  333
+		$this->loadFixtures('Datatype');
  334
+		$Model = new Model(array(
  335
+			'name' => 'Datatype',
  336
+			'ds' => 'test',
  337
+			'table' => 'datatypes'
  338
+		));
  339
+		$result = $this->Dbo->describe($Model);
  340
+		$expected = array(
  341
+			'id' => array(
  342
+				'type' => 'integer',
  343
+				'null' => false,
  344
+				'default' => 0,
  345
+				'key' => 'primary'
  346
+			),
  347
+			'float_field' => array(
  348
+				'type' => 'float',
  349
+				'length' => '5,2',
  350
+				'null' => false,
  351
+				'default' => null
  352
+			),
  353
+			'huge_int' => array(
  354
+				'type' => 'bigint',
  355
+				'length' => '20',
  356
+				'null' => true,
  357
+				'default' => null
  358
+			),
  359
+			'bool' => array(
  360
+				'type' => 'boolean',
  361
+				'null' => false,
  362
+				'default' => false
  363
+			),
  364
+		);
  365
+	}
  366
+
  367
+/**
314 368
  * test that describe does not corrupt UUID primary keys
315 369
  *
316 370
  * @return void
3  lib/Cake/Test/Fixture/DatatypeFixture.php
@@ -39,6 +39,7 @@ class DatatypeFixture extends CakeTestFixture {
39 39
 	public $fields = array(
40 40
 		'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
41 41
 		'float_field' => array('type' => 'float', 'length' => '5,2', 'null' => false, 'default' => null),
  42
+		'huge_int' => array('type' => 'biginteger'),
42 43
 		'bool' => array('type' => 'boolean', 'null' => false, 'default' => false),
43 44
 	);
44 45
 
@@ -48,6 +49,6 @@ class DatatypeFixture extends CakeTestFixture {
48 49
  * @var array
49 50
  */
50 51
 	public $records = array(
51  
-		array('id' => 1, 'float_field' => 42.23, 'bool' => 0),
  52
+		array('id' => 1, 'float_field' => 42.23, 'huge_int' => '123456789123456789123456789', 'bool' => 0),
52 53
 	);
53 54
 }

0 notes on commit 8d8f4b5

Please sign in to comment.
Something went wrong with that request. Please try again.