From d01f3e8aedf036efd31e699ab1884841360b9b68 Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Fri, 3 Mar 2017 21:42:58 -0500 Subject: [PATCH 01/11] allow data sources to provide smaller integers based on storage requirements --- lib/Cake/Model/Datasource/Database/Mysql.php | 38 +++++++++++ lib/Cake/Model/Datasource/DboSource.php | 24 +++++-- .../Model/Datasource/Database/MysqlTest.php | 65 +++++++++++++++++++ 3 files changed, 122 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index bb6e1d18e..4a01dc29e 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -117,6 +117,10 @@ class Mysql extends DboSource { 'text' => array('name' => 'text'), 'biginteger' => array('name' => 'bigint', 'limit' => '20'), 'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), + 'integer/4' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), + 'integer/3' => array('name' => 'mediumint', 'limit' => '9', 'formatter' => 'intval'), + 'integer/2' => array('name' => 'smallint', 'limit' => '6', 'formatter' => 'intval'), + 'integer/1' => array('name' => 'tinyint', 'limit' => '4', 'formatter' => 'intval'), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), 'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), @@ -369,6 +373,10 @@ class Mysql extends DboSource { $fields[$column->Field]['charset'] = $charset; } } + $storage = $this->storageRequirement($column->Type); + if (is_numeric($storage)) { + $fields[$column->Field]['storage'] = $storage; + } } $this->_cacheDescription($key, $fields); $cols->closeCursor(); @@ -810,6 +818,36 @@ class Mysql extends DboSource { return 'text'; } +/** + * Gets the storage requirement of a database-native column description, or null if unknown or N/A + * + * @param string $real Real database-layer column type (i.e. "varchar(255)") + * @return mixed An integer representing the storage requirement of the column in bytes, or null if unknown or N/A. + */ + public function storageRequirement($real) { + if (is_array($real)) { + $col = $real['name']; + } else { + $col = $real; + if (strpos($col, '(') !== false) { + list($col, $vals) = explode('(', $col); + } + } + + // Base on Storage Requirements for Numeric Types + // https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html + if ($col === 'tinyint') { + return 1; + } + if ($col === 'smallint') { + return 2; + } + if ($col === 'mediumint') { + return 3; + } + return null; + } + /** * {@inheritDoc} */ diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index f69144746..2491bb953 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3246,6 +3246,16 @@ class DboSource extends DataSource { return (int)$length; } +/** + * Gets the storage requirement of a database-native column description, or null if unknown or N/A + * + * @param string $real Real database-layer column type (i.e. "varchar(255)") + * @return mixed An integer representing the storage requirement of the column in bytes, or null if unknown or N/A. + */ + public function storageRequirement($real) { + return null; + } + /** * Translates between PHP boolean values and Database (faked) boolean values * @@ -3459,12 +3469,16 @@ class DboSource extends DataSource { return null; } - if (!isset($this->columns[$type])) { - trigger_error(__d('cake_dev', 'Column type %s does not exist', $type), E_USER_WARNING); - return null; + // if a storage requirement in bytes was set, try it first (i.e. 'integer/4' before 'integer') + if (isset($storage) && isset($this->columns[$type . '/' . $storage])) { + $real = $this->columns[$type . '/' . $storage]; + } else { + if (!isset($this->columns[$type])) { + trigger_error(__d('cake_dev', 'Column type %s does not exist', $type), E_USER_WARNING); + return null; + } + $real = $this->columns[$type]; } - - $real = $this->columns[$type]; $out = $this->name($name) . ' ' . $real['name']; if (isset($column['length'])) { diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 8e7dc7b3c..7ec9218b7 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -389,6 +389,36 @@ class MysqlTest extends CakeTestCase { $expected = '`testName` CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL'; $this->assertEquals($expected, $result); $this->Dbo->columns = $restore; + + $data = array( + 'name' => 'testName', + 'type' => 'integer', + 'storage' => 1 + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`testName` tinyint(4)'; + $this->assertEquals($expected, $result); + $this->Dbo->columns = $restore; + + $data = array( + 'name' => 'testName', + 'type' => 'integer', + 'storage' => 2 + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`testName` smallint(6)'; + $this->assertEquals($expected, $result); + $this->Dbo->columns = $restore; + + $data = array( + 'name' => 'testName', + 'type' => 'integer', + 'storage' => 3 + ); + $result = $this->Dbo->buildColumn($data); + $expected = '`testName` mediumint(9)'; + $this->assertEquals($expected, $result); + $this->Dbo->columns = $restore; } /** @@ -526,6 +556,18 @@ class MysqlTest extends CakeTestCase { $expected = 'boolean'; $this->assertEquals($expected, $result); + $result = $this->Dbo->column('tinyint(4)'); + $expected = 'integer'; + $this->assertEquals($expected, $result); + + $result = $this->Dbo->column('smallint'); + $expected = 'integer'; + $this->assertEquals($expected, $result); + + $result = $this->Dbo->column('mediumint'); + $expected = 'integer'; + $this->assertEquals($expected, $result); + $result = $this->Dbo->column('boolean'); $expected = 'boolean'; $this->assertEquals($expected, $result); @@ -3092,6 +3134,29 @@ SQL; $this->assertSame($expected, $result); } +/** + * test storageRequirement method + * + * @return void + */ + public function testStorageRequirement () { + $result = $this->Dbo->storageRequirement('varchar(255)'); + $expected = null; + $this->assertSame($expected, $result); + + $result = $this->Dbo->storageRequirement('mediumint'); + $expected = 3; + $this->assertSame($expected, $result); + + $result = $this->Dbo->storageRequirement('smallint'); + $expected = 2; + $this->assertSame($expected, $result); + + $result = $this->Dbo->storageRequirement('tinyint'); + $expected = 1; + $this->assertSame($expected, $result); + } + /** * testBuildIndex method * From 216ae0ec0c359ac49831ac609d0d29b61d7634da Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Sat, 4 Mar 2017 00:56:57 -0500 Subject: [PATCH 02/11] fix coding standard --- lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 7ec9218b7..cd0beaef5 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -3139,7 +3139,7 @@ SQL; * * @return void */ - public function testStorageRequirement () { + public function testStorageRequirement() { $result = $this->Dbo->storageRequirement('varchar(255)'); $expected = null; $this->assertSame($expected, $result); From 38101995b4404317a068e3278c756e70ea89b668 Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Sun, 5 Mar 2017 12:25:14 -0500 Subject: [PATCH 03/11] introduce new tinyint, smallint types for smaller storage requirements --- lib/Cake/Model/Datasource/Database/Mysql.php | 46 ++--------- .../Model/Datasource/Database/Postgres.php | 6 ++ lib/Cake/Model/Datasource/Database/Sqlite.php | 4 + .../Model/Datasource/Database/Sqlserver.php | 10 +++ lib/Cake/Model/Datasource/DboSource.php | 24 ++---- .../Model/Datasource/Database/MysqlTest.php | 79 +++---------------- .../Datasource/Database/PostgresTest.php | 6 +- .../Model/Datasource/Database/SqliteTest.php | 22 ++++++ .../Datasource/Database/SqlserverTest.php | 10 +++ 9 files changed, 79 insertions(+), 128 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 4a01dc29e..de517a42f 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -117,10 +117,8 @@ class Mysql extends DboSource { 'text' => array('name' => 'text'), 'biginteger' => array('name' => 'bigint', 'limit' => '20'), 'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), - 'integer/4' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), - 'integer/3' => array('name' => 'mediumint', 'limit' => '9', 'formatter' => 'intval'), - 'integer/2' => array('name' => 'smallint', 'limit' => '6', 'formatter' => 'intval'), - 'integer/1' => array('name' => 'tinyint', 'limit' => '4', 'formatter' => 'intval'), + 'smallint' => array('name' => 'smallint', 'limit' => '6', 'formatter' => 'intval'), + 'tinyint' => array('name' => 'tinyint', 'limit' => '4', 'formatter' => 'intval'), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), 'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), @@ -373,10 +371,6 @@ class Mysql extends DboSource { $fields[$column->Field]['charset'] = $charset; } } - $storage = $this->storageRequirement($column->Type); - if (is_numeric($storage)) { - $fields[$column->Field]['storage'] = $storage; - } } $this->_cacheDescription($key, $fields); $cols->closeCursor(); @@ -791,6 +785,12 @@ class Mysql extends DboSource { if (strpos($col, 'bigint') !== false || $col === 'bigint') { return 'biginteger'; } + if (strpos($col, 'tinyint') !== false) { + return 'tinyint'; + } + if (strpos($col, 'smallint') !== false) { + return 'smallint'; + } if (strpos($col, 'int') !== false) { return 'integer'; } @@ -818,36 +818,6 @@ class Mysql extends DboSource { return 'text'; } -/** - * Gets the storage requirement of a database-native column description, or null if unknown or N/A - * - * @param string $real Real database-layer column type (i.e. "varchar(255)") - * @return mixed An integer representing the storage requirement of the column in bytes, or null if unknown or N/A. - */ - public function storageRequirement($real) { - if (is_array($real)) { - $col = $real['name']; - } else { - $col = $real; - if (strpos($col, '(') !== false) { - list($col, $vals) = explode('(', $col); - } - } - - // Base on Storage Requirements for Numeric Types - // https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html - if ($col === 'tinyint') { - return 1; - } - if ($col === 'smallint') { - return 2; - } - if ($col === 'mediumint') { - return 3; - } - return null; - } - /** * {@inheritDoc} */ diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 8673fbc5c..b8dbf462a 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -51,6 +51,8 @@ class Postgres extends DboSource { /** * Columns * + * @link https://www.postgresql.org/docs/9.6/static/datatype.html PostgreSQL Data Types + * * @var array */ public $columns = array( @@ -58,6 +60,8 @@ class Postgres extends DboSource { 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), 'integer' => array('name' => 'integer', 'formatter' => 'intval'), + 'smallint' => array('name' => 'smallint', 'formatter' => 'intval'), + 'tinyint' => array('name' => 'smallint', 'formatter' => 'intval'), 'biginteger' => array('name' => 'bigint', 'limit' => '20'), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), @@ -701,6 +705,8 @@ class Postgres extends DboSource { return 'time'; case ($col === 'bigint'): return 'biginteger'; + case ($col === 'smallint'): + return 'smallint'; case (strpos($col, 'int') !== false && $col !== 'interval'): return 'integer'; case (strpos($col, 'char') !== false): diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index bfda2c8dd..6ad7b54bc 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -63,6 +63,8 @@ class Sqlite extends DboSource { /** * SQLite3 column definition * + * @link https://www.sqlite.org/datatype3.html Datatypes In SQLite Version 3 + * * @var array */ public $columns = array( @@ -70,6 +72,8 @@ class Sqlite extends DboSource { 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), 'integer' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'), + 'smallint' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'), + 'tinyint' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'), 'biginteger' => array('name' => 'bigint', 'limit' => 20), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index 90590e6ad..a25ecc04a 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -84,6 +84,8 @@ class Sqlserver extends DboSource { /** * MS SQL column definition * + * @link https://msdn.microsoft.com/en-us/library/ms187752.aspx SQL Server Data Types + * * @var array */ public $columns = array( @@ -91,6 +93,8 @@ class Sqlserver extends DboSource { 'string' => array('name' => 'nvarchar', 'limit' => '255'), 'text' => array('name' => 'nvarchar', 'limit' => 'MAX'), 'integer' => array('name' => 'int', 'formatter' => 'intval'), + 'smallint' => array('name' => 'smallint', 'formatter' => 'intval'), + 'tinyint' => array('name' => 'tinyint', 'formatter' => 'intval'), 'biginteger' => array('name' => 'bigint'), 'numeric' => array('name' => 'decimal', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), @@ -435,6 +439,12 @@ class Sqlserver extends DboSource { if (strpos($col, 'bigint') !== false) { return 'biginteger'; } + if (strpos($col, 'smallint') !== false) { + return 'smallint'; + } + if (strpos($col, 'tinyint') !== false) { + return 'tinyint'; + } if (strpos($col, 'int') !== false) { return 'integer'; } diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 2491bb953..f69144746 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3246,16 +3246,6 @@ class DboSource extends DataSource { return (int)$length; } -/** - * Gets the storage requirement of a database-native column description, or null if unknown or N/A - * - * @param string $real Real database-layer column type (i.e. "varchar(255)") - * @return mixed An integer representing the storage requirement of the column in bytes, or null if unknown or N/A. - */ - public function storageRequirement($real) { - return null; - } - /** * Translates between PHP boolean values and Database (faked) boolean values * @@ -3469,16 +3459,12 @@ class DboSource extends DataSource { return null; } - // if a storage requirement in bytes was set, try it first (i.e. 'integer/4' before 'integer') - if (isset($storage) && isset($this->columns[$type . '/' . $storage])) { - $real = $this->columns[$type . '/' . $storage]; - } else { - if (!isset($this->columns[$type])) { - trigger_error(__d('cake_dev', 'Column type %s does not exist', $type), E_USER_WARNING); - return null; - } - $real = $this->columns[$type]; + if (!isset($this->columns[$type])) { + trigger_error(__d('cake_dev', 'Column type %s does not exist', $type), E_USER_WARNING); + return null; } + + $real = $this->columns[$type]; $out = $this->name($name) . ' ' . $real['name']; if (isset($column['length'])) { diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index cd0beaef5..9bd6faf91 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -201,7 +201,7 @@ class MysqlTest extends CakeTestCase { public function testTinyintCasting() { $this->Dbo->cacheSources = false; $tableName = 'tinyint_' . uniqid(); - $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));'); + $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), tiny_int tinyint(2), primary key(id));'); $this->model = new CakeTestModel(array( 'name' => 'Tinyint', 'table' => $tableName, 'ds' => 'test' @@ -209,24 +209,24 @@ class MysqlTest extends CakeTestCase { $result = $this->model->schema(); $this->assertEquals('boolean', $result['bool']['type']); - $this->assertEquals('integer', $result['small_int']['type']); + $this->assertEquals('tinyint', $result['tiny_int']['type']); - $this->assertTrue((bool)$this->model->save(array('bool' => 5, 'small_int' => 5))); + $this->assertTrue((bool)$this->model->save(array('bool' => 5, 'tiny_int' => 5))); $result = $this->model->find('first'); $this->assertTrue($result['Tinyint']['bool']); - $this->assertSame($result['Tinyint']['small_int'], '5'); + $this->assertSame($result['Tinyint']['tiny_int'], '5'); $this->model->deleteAll(true); - $this->assertTrue((bool)$this->model->save(array('bool' => 0, 'small_int' => 100))); + $this->assertTrue((bool)$this->model->save(array('bool' => 0, 'tiny_int' => 100))); $result = $this->model->find('first'); $this->assertFalse($result['Tinyint']['bool']); - $this->assertSame($result['Tinyint']['small_int'], '100'); + $this->assertSame($result['Tinyint']['tiny_int'], '100'); $this->model->deleteAll(true); - $this->assertTrue((bool)$this->model->save(array('bool' => true, 'small_int' => 0))); + $this->assertTrue((bool)$this->model->save(array('bool' => true, 'tiny_int' => 0))); $result = $this->model->find('first'); $this->assertTrue($result['Tinyint']['bool']); - $this->assertSame($result['Tinyint']['small_int'], '0'); + $this->assertSame($result['Tinyint']['tiny_int'], '0'); $this->model->deleteAll(true); $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); @@ -389,36 +389,6 @@ class MysqlTest extends CakeTestCase { $expected = '`testName` CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL'; $this->assertEquals($expected, $result); $this->Dbo->columns = $restore; - - $data = array( - 'name' => 'testName', - 'type' => 'integer', - 'storage' => 1 - ); - $result = $this->Dbo->buildColumn($data); - $expected = '`testName` tinyint(4)'; - $this->assertEquals($expected, $result); - $this->Dbo->columns = $restore; - - $data = array( - 'name' => 'testName', - 'type' => 'integer', - 'storage' => 2 - ); - $result = $this->Dbo->buildColumn($data); - $expected = '`testName` smallint(6)'; - $this->assertEquals($expected, $result); - $this->Dbo->columns = $restore; - - $data = array( - 'name' => 'testName', - 'type' => 'integer', - 'storage' => 3 - ); - $result = $this->Dbo->buildColumn($data); - $expected = '`testName` mediumint(9)'; - $this->assertEquals($expected, $result); - $this->Dbo->columns = $restore; } /** @@ -556,16 +526,12 @@ class MysqlTest extends CakeTestCase { $expected = 'boolean'; $this->assertEquals($expected, $result); - $result = $this->Dbo->column('tinyint(4)'); - $expected = 'integer'; + $result = $this->Dbo->column('tinyint'); + $expected = 'tinyint'; $this->assertEquals($expected, $result); $result = $this->Dbo->column('smallint'); - $expected = 'integer'; - $this->assertEquals($expected, $result); - - $result = $this->Dbo->column('mediumint'); - $expected = 'integer'; + $expected = 'smallint'; $this->assertEquals($expected, $result); $result = $this->Dbo->column('boolean'); @@ -3134,29 +3100,6 @@ SQL; $this->assertSame($expected, $result); } -/** - * test storageRequirement method - * - * @return void - */ - public function testStorageRequirement() { - $result = $this->Dbo->storageRequirement('varchar(255)'); - $expected = null; - $this->assertSame($expected, $result); - - $result = $this->Dbo->storageRequirement('mediumint'); - $expected = 3; - $this->assertSame($expected, $result); - - $result = $this->Dbo->storageRequirement('smallint'); - $expected = 2; - $this->assertSame($expected, $result); - - $result = $this->Dbo->storageRequirement('tinyint'); - $expected = 1; - $this->assertSame($expected, $result); - } - /** * testBuildIndex method * diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 9158efcd2..68db54f33 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -304,9 +304,9 @@ class PostgresTest extends CakeTestCase { $this->assertEquals('float', $this->Dbo2->column('double precision')); $this->assertEquals('uuid', $this->Dbo2->column('uuid')); - $result = $this->Dbo2->column('bigint'); - $expected = 'biginteger'; - $this->assertEquals($expected, $result); + $this->assertEquals('biginteger', $this->Dbo2->column('bigint')); + $this->assertEquals('integer', $this->Dbo2->column('integer')); + $this->assertEquals('smallint', $this->Dbo2->column('smallint')); } /** diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php index 8f831a671..bc32275f8 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php @@ -263,6 +263,28 @@ class SqliteTest extends CakeTestCase { $expected = '"testName" integer(10) DEFAULT 10 NOT NULL'; $this->assertEquals($expected, $result); + $data = array( + 'name' => 'testName', + 'type' => 'smallint', + 'length' => 6, + 'default' => 6, + 'null' => false, + ); + $result = $this->Dbo->buildColumn($data); + $expected = '"testName" integer(6) DEFAULT 6 NOT NULL'; + $this->assertEquals($expected, $result); + + $data = array( + 'name' => 'testName', + 'type' => 'tinyint', + 'length' => 4, + 'default' => 4, + 'null' => false, + ); + $result = $this->Dbo->buildColumn($data); + $expected = '"testName" integer(4) DEFAULT 4 NOT NULL'; + $this->assertEquals($expected, $result); + $data = array( 'name' => 'huge', 'type' => 'biginteger', diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php index 81fa8e7b2..5d7df51ad 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php @@ -532,6 +532,16 @@ class SqlserverTest extends CakeTestCase { $expected = '[client_id] int NULL'; $this->assertEquals($expected, $result); + $column = array('type' => 'smallint', 'name' => 'client_id'); + $result = $this->db->buildColumn($column); + $expected = '[client_id] smallint NULL'; + $this->assertEquals($expected, $result); + + $column = array('type' => 'tinyint', 'name' => 'client_id'); + $result = $this->db->buildColumn($column); + $expected = '[client_id] tinyint NULL'; + $this->assertEquals($expected, $result); + $column = array('type' => 'string', 'name' => 'name'); $result = $this->db->buildColumn($column); $expected = '[name] nvarchar(255) NULL'; From 7c0bcb16c8f128117ac32bdc19d2bf4127dc832a Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Sun, 5 Mar 2017 12:28:41 -0500 Subject: [PATCH 04/11] add missing MySQL data type link --- lib/Cake/Model/Datasource/Database/Mysql.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index de517a42f..3a1146d63 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -109,6 +109,8 @@ class Mysql extends DboSource { /** * MySQL column definition * + * @link https://dev.mysql.com/doc/refman/5.7/en/data-types.html MySQL Data Types + * * @var array */ public $columns = array( From c0ea3d08e6aff91ef8de0785b2168015e840797e Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Sun, 5 Mar 2017 22:17:28 -0500 Subject: [PATCH 05/11] update ModelTask and FormHelper for tinyint,smallint --- lib/Cake/Console/Command/Task/ModelTask.php | 4 ++++ lib/Cake/View/Helper/FormHelper.php | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index 2dc03a5c3..c8a6ef381 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -450,6 +450,10 @@ class ModelTask extends BakeTask { $guess = $methods['notBlank']; } elseif ($metaData['type'] === 'integer') { $guess = $methods['numeric']; + } elseif ($metaData['type'] === 'smallint') { + $guess = $methods['numeric']; + } elseif ($metaData['type'] === 'tinyint') { + $guess = $methods['numeric']; } elseif ($metaData['type'] === 'float') { $guess = $methods['numeric']; } elseif ($metaData['type'] === 'boolean') { diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 49083962f..d1463372a 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1236,11 +1236,18 @@ class FormHelper extends AppHelper { $type = $fieldDef['type']; $primaryKey = $this->fieldset[$modelKey]['key']; $map = array( - 'string' => 'text', 'datetime' => 'datetime', - 'boolean' => 'checkbox', 'timestamp' => 'datetime', - 'text' => 'textarea', 'time' => 'time', - 'date' => 'date', 'float' => 'number', - 'integer' => 'number', 'decimal' => 'number', + 'string' => 'text', + 'datetime' => 'datetime', + 'boolean' => 'checkbox', + 'timestamp' => 'datetime', + 'text' => 'textarea', + 'time' => 'time', + 'date' => 'date', + 'float' => 'number', + 'integer' => 'number', + 'smallint' => 'number', + 'tinyint' => 'number', + 'decimal' => 'number', 'binary' => 'file' ); From 15a33eee06cf2eb022ca95a3126c532f0aad10ee Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Sun, 5 Mar 2017 22:38:08 -0500 Subject: [PATCH 06/11] update more tests, DatatypeFixture --- lib/Cake/Test/Case/Model/CakeSchemaTest.php | 3 +++ .../Model/Datasource/Database/SqliteTest.php | 18 ++++++++++++++++++ lib/Cake/Test/Fixture/DatatypeFixture.php | 13 ++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/CakeSchemaTest.php b/lib/Cake/Test/Case/Model/CakeSchemaTest.php index aedb6ef3d..b5f389d8e 100644 --- a/lib/Cake/Test/Case/Model/CakeSchemaTest.php +++ b/lib/Cake/Test/Case/Model/CakeSchemaTest.php @@ -173,6 +173,9 @@ class TestAppSchema extends CakeSchema { 'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''), 'decimal_field' => array('type' => 'decimal', 'length' => '6,3', 'default' => '0.000'), 'huge_int' => array('type' => 'biginteger'), + 'normal_int' => array('type' => 'integer'), + 'small_int' => array('type' => 'smallint'), + 'tiny_int' => array('type' => 'tinyint'), 'bool' => array('type' => 'boolean', 'null' => false, 'default' => false), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)), 'tableParameters' => array() diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php index bc32275f8..ef206901a 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php @@ -405,6 +405,24 @@ class SqliteTest extends CakeTestCase { 'default' => null, 'length' => 20, ), + 'normal_int' => array( + 'type' => 'integer', + 'null' => true, + 'default' => null, + 'length' => null + ), + 'small_int' => array( + 'type' => 'integer', + 'null' => true, + 'default' => null, + 'length' => null + ), + 'tiny_int' => array( + 'type' => 'integer', + 'null' => true, + 'default' => null, + 'length' => null + ), 'bool' => array( 'type' => 'boolean', 'null' => false, diff --git a/lib/Cake/Test/Fixture/DatatypeFixture.php b/lib/Cake/Test/Fixture/DatatypeFixture.php index 14b1162e5..cf789b67e 100644 --- a/lib/Cake/Test/Fixture/DatatypeFixture.php +++ b/lib/Cake/Test/Fixture/DatatypeFixture.php @@ -33,6 +33,9 @@ class DatatypeFixture extends CakeTestFixture { 'float_field' => array('type' => 'float', 'length' => '5,2', 'null' => false, 'default' => null), 'decimal_field' => array('type' => 'decimal', 'length' => '6,3', 'default' => '0.000'), 'huge_int' => array('type' => 'biginteger'), + 'normal_int' => array('type' => 'integer'), + 'small_int' => array('type' => 'smallint'), + 'tiny_int' => array('type' => 'tinyint'), 'bool' => array('type' => 'boolean', 'null' => false, 'default' => false), ); @@ -42,6 +45,14 @@ class DatatypeFixture extends CakeTestFixture { * @var array */ public $records = array( - array('id' => 1, 'float_field' => 42.23, 'huge_int' => '1234567891234567891', 'bool' => 0), + array( + 'id' => 1, + 'float_field' => 42.23, + 'huge_int' => '9223372036854775807', + 'normal_int' => 2147483647, + 'small_int' => 32767, + 'tiny_int' => 127, + 'bool' => 0 + ), ); } From 4fc8f7d919d9b08ee08833ee6c53640364ccb7cc Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Mon, 6 Mar 2017 00:21:11 -0500 Subject: [PATCH 07/11] fix test for UnsignedFixture --- lib/Cake/Model/Datasource/Database/Mysql.php | 8 ++++++-- lib/Cake/Test/Fixture/UnsignedFixture.php | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 3a1146d63..1ac70fdca 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -87,10 +87,14 @@ class Mysql extends DboSource { 'collate' => array('value' => 'COLLATE', 'quote' => false, 'join' => ' ', 'column' => 'Collation', 'position' => 'beforeDefault'), 'comment' => array('value' => 'COMMENT', 'quote' => true, 'join' => ' ', 'column' => 'Comment', 'position' => 'afterDefault'), 'unsigned' => array( - 'value' => 'UNSIGNED', 'quote' => false, 'join' => ' ', 'column' => false, 'position' => 'beforeDefault', + 'value' => 'UNSIGNED', + 'quote' => false, + 'join' => ' ', + 'column' => false, + 'position' => 'beforeDefault', 'noVal' => true, 'options' => array(true), - 'types' => array('integer', 'float', 'decimal', 'biginteger') + 'types' => array('integer', 'smallint', 'tinyint', 'float', 'decimal', 'biginteger') ) ); diff --git a/lib/Cake/Test/Fixture/UnsignedFixture.php b/lib/Cake/Test/Fixture/UnsignedFixture.php index 1c8eb2f28..a0eb97161 100644 --- a/lib/Cake/Test/Fixture/UnsignedFixture.php +++ b/lib/Cake/Test/Fixture/UnsignedFixture.php @@ -40,6 +40,10 @@ class UnsignedFixture extends CakeTestFixture { public $fields = array( 'uinteger' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary', 'unsigned' => true), 'integer' => array('type' => 'integer', 'length' => '8', 'unsigned' => false), + 'usmallint' => array('type' => 'smallint', 'unsigned' => true), + 'smallint' => array('type' => 'smallint', 'unsigned' => false), + 'utinyint' => array('type' => 'tinyint', 'unsigned' => true), + 'tinyint' => array('type' => 'tinyint', 'unsigned' => false), 'udecimal' => array('type' => 'decimal', 'length' => '4', 'unsigned' => true), 'decimal' => array('type' => 'decimal', 'length' => '4'), 'biginteger' => array('type' => 'biginteger', 'length' => '20', 'default' => 3), From 58078e77e1e7a2fa63d222cbeb686ee4e1aeda2d Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Mon, 6 Mar 2017 10:42:23 -0500 Subject: [PATCH 08/11] more tinyint smallint tests in MySQL --- .../Model/Datasource/Database/MysqlTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 9bd6faf91..6f4eca8b6 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -3376,6 +3376,26 @@ SQL; 'default' => 1 ), '`testName` decimal UNSIGNED DEFAULT 1' + ), + //set #9 + array( + array( + 'name' => 'testName', + 'type' => 'smallint', + 'length' => 6, + 'unsigned' => true + ), + '`testName` smallint(6) UNSIGNED' + ), + //set #10 + array( + array( + 'name' => 'testName', + 'type' => 'tinyint', + 'length' => 4, + 'unsigned' => true + ), + '`testName` tinyint(4) UNSIGNED' ) ); } From d78829bd93a1369f40de8b3aec764da2a8b3e16f Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Thu, 9 Mar 2017 10:45:35 -0500 Subject: [PATCH 09/11] coding/doc standard, move @link after @var, per req --- lib/Cake/Model/Datasource/Database/Mysql.php | 3 +-- lib/Cake/Model/Datasource/Database/Postgres.php | 3 +-- lib/Cake/Model/Datasource/Database/Sqlite.php | 3 +-- lib/Cake/Model/Datasource/Database/Sqlserver.php | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 1ac70fdca..fa6deab76 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -113,9 +113,8 @@ class Mysql extends DboSource { /** * MySQL column definition * - * @link https://dev.mysql.com/doc/refman/5.7/en/data-types.html MySQL Data Types - * * @var array + * @link https://dev.mysql.com/doc/refman/5.7/en/data-types.html MySQL Data Types */ public $columns = array( 'primary_key' => array('name' => 'NOT NULL AUTO_INCREMENT'), diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index b8dbf462a..9a827fc5f 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -51,9 +51,8 @@ class Postgres extends DboSource { /** * Columns * - * @link https://www.postgresql.org/docs/9.6/static/datatype.html PostgreSQL Data Types - * * @var array + * @link https://www.postgresql.org/docs/9.6/static/datatype.html PostgreSQL Data Types */ public $columns = array( 'primary_key' => array('name' => 'serial NOT NULL'), diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index 6ad7b54bc..51a0dc375 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -63,9 +63,8 @@ class Sqlite extends DboSource { /** * SQLite3 column definition * - * @link https://www.sqlite.org/datatype3.html Datatypes In SQLite Version 3 - * * @var array + * @link https://www.sqlite.org/datatype3.html Datatypes In SQLite Version 3 */ public $columns = array( 'primary_key' => array('name' => 'integer primary key autoincrement'), diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index a25ecc04a..5bbf0a102 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -84,9 +84,8 @@ class Sqlserver extends DboSource { /** * MS SQL column definition * - * @link https://msdn.microsoft.com/en-us/library/ms187752.aspx SQL Server Data Types - * * @var array + * @link https://msdn.microsoft.com/en-us/library/ms187752.aspx SQL Server Data Types */ public $columns = array( 'primary_key' => array('name' => 'IDENTITY (1, 1) NOT NULL'), From b6372d63d95dd42c5cb984a5dd568aa062134303 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 11 Mar 2017 21:41:22 -0500 Subject: [PATCH 10/11] Rename (small|tiny)int to (small|tiny)integer Make the new types consistent with the biginteger. --- lib/Cake/Console/Command/Task/ModelTask.php | 4 +-- lib/Cake/Model/Datasource/Database/Mysql.php | 10 +++--- .../Model/Datasource/Database/Postgres.php | 6 ++-- lib/Cake/Model/Datasource/Database/Sqlite.php | 10 ++++-- .../Model/Datasource/Database/Sqlserver.php | 8 ++--- lib/Cake/Test/Case/Model/CakeSchemaTest.php | 4 +-- .../Model/Datasource/Database/MysqlTest.php | 32 +++++++++---------- .../Datasource/Database/PostgresTest.php | 2 +- .../Model/Datasource/Database/SqliteTest.php | 12 +++---- .../Datasource/Database/SqlserverTest.php | 4 +-- lib/Cake/Test/Fixture/DatatypeFixture.php | 4 +-- lib/Cake/Test/Fixture/UnsignedFixture.php | 8 ++--- lib/Cake/View/Helper/FormHelper.php | 4 +-- 13 files changed, 57 insertions(+), 51 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index c8a6ef381..eaba7b0ee 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -450,9 +450,9 @@ class ModelTask extends BakeTask { $guess = $methods['notBlank']; } elseif ($metaData['type'] === 'integer') { $guess = $methods['numeric']; - } elseif ($metaData['type'] === 'smallint') { + } elseif ($metaData['type'] === 'smallinteger') { $guess = $methods['numeric']; - } elseif ($metaData['type'] === 'tinyint') { + } elseif ($metaData['type'] === 'tinyinteger') { $guess = $methods['numeric']; } elseif ($metaData['type'] === 'float') { $guess = $methods['numeric']; diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index fa6deab76..52310492c 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -94,7 +94,7 @@ class Mysql extends DboSource { 'position' => 'beforeDefault', 'noVal' => true, 'options' => array(true), - 'types' => array('integer', 'smallint', 'tinyint', 'float', 'decimal', 'biginteger') + 'types' => array('integer', 'smallinteger', 'tinyinteger', 'float', 'decimal', 'biginteger') ) ); @@ -122,8 +122,8 @@ class Mysql extends DboSource { 'text' => array('name' => 'text'), 'biginteger' => array('name' => 'bigint', 'limit' => '20'), 'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'), - 'smallint' => array('name' => 'smallint', 'limit' => '6', 'formatter' => 'intval'), - 'tinyint' => array('name' => 'tinyint', 'limit' => '4', 'formatter' => 'intval'), + 'smallinteger' => array('name' => 'smallint', 'limit' => '6', 'formatter' => 'intval'), + 'tinyinteger' => array('name' => 'tinyint', 'limit' => '4', 'formatter' => 'intval'), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), 'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'), @@ -791,10 +791,10 @@ class Mysql extends DboSource { return 'biginteger'; } if (strpos($col, 'tinyint') !== false) { - return 'tinyint'; + return 'tinyinteger'; } if (strpos($col, 'smallint') !== false) { - return 'smallint'; + return 'smallinteger'; } if (strpos($col, 'int') !== false) { return 'integer'; diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 9a827fc5f..341531320 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -59,8 +59,8 @@ class Postgres extends DboSource { 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), 'integer' => array('name' => 'integer', 'formatter' => 'intval'), - 'smallint' => array('name' => 'smallint', 'formatter' => 'intval'), - 'tinyint' => array('name' => 'smallint', 'formatter' => 'intval'), + 'smallinteger' => array('name' => 'smallint', 'formatter' => 'intval'), + 'tinyinteger' => array('name' => 'smallint', 'formatter' => 'intval'), 'biginteger' => array('name' => 'bigint', 'limit' => '20'), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), @@ -705,7 +705,7 @@ class Postgres extends DboSource { case ($col === 'bigint'): return 'biginteger'; case ($col === 'smallint'): - return 'smallint'; + return 'smallinteger'; case (strpos($col, 'int') !== false && $col !== 'interval'): return 'integer'; case (strpos($col, 'char') !== false): diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index 51a0dc375..6d34e7e4d 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -71,8 +71,8 @@ class Sqlite extends DboSource { 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), 'integer' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'), - 'smallint' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'), - 'tinyint' => array('name' => 'integer', 'limit' => null, 'formatter' => 'intval'), + 'smallinteger' => array('name' => 'smallint', 'limit' => null, 'formatter' => 'intval'), + 'tinyinteger' => array('name' => 'tinyint', 'limit' => null, 'formatter' => 'intval'), 'biginteger' => array('name' => 'bigint', 'limit' => 20), 'float' => array('name' => 'float', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), @@ -275,6 +275,12 @@ class Sqlite extends DboSource { if (in_array($col, $standard)) { return $col; } + if ($col === 'tinyint') { + return 'tinyinteger'; + } + if ($col === 'smallint') { + return 'smallinteger'; + } if ($col === 'bigint') { return 'biginteger'; } diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index 5bbf0a102..ee2fd3d85 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -92,8 +92,8 @@ class Sqlserver extends DboSource { 'string' => array('name' => 'nvarchar', 'limit' => '255'), 'text' => array('name' => 'nvarchar', 'limit' => 'MAX'), 'integer' => array('name' => 'int', 'formatter' => 'intval'), - 'smallint' => array('name' => 'smallint', 'formatter' => 'intval'), - 'tinyint' => array('name' => 'tinyint', 'formatter' => 'intval'), + 'smallinteger' => array('name' => 'smallint', 'formatter' => 'intval'), + 'tinyinteger' => array('name' => 'tinyint', 'formatter' => 'intval'), 'biginteger' => array('name' => 'bigint'), 'numeric' => array('name' => 'decimal', 'formatter' => 'floatval'), 'decimal' => array('name' => 'decimal', 'formatter' => 'floatval'), @@ -439,10 +439,10 @@ class Sqlserver extends DboSource { return 'biginteger'; } if (strpos($col, 'smallint') !== false) { - return 'smallint'; + return 'smallinteger'; } if (strpos($col, 'tinyint') !== false) { - return 'tinyint'; + return 'tinyinteger'; } if (strpos($col, 'int') !== false) { return 'integer'; diff --git a/lib/Cake/Test/Case/Model/CakeSchemaTest.php b/lib/Cake/Test/Case/Model/CakeSchemaTest.php index b5f389d8e..be096484b 100644 --- a/lib/Cake/Test/Case/Model/CakeSchemaTest.php +++ b/lib/Cake/Test/Case/Model/CakeSchemaTest.php @@ -174,8 +174,8 @@ class TestAppSchema extends CakeSchema { 'decimal_field' => array('type' => 'decimal', 'length' => '6,3', 'default' => '0.000'), 'huge_int' => array('type' => 'biginteger'), 'normal_int' => array('type' => 'integer'), - 'small_int' => array('type' => 'smallint'), - 'tiny_int' => array('type' => 'tinyint'), + 'small_int' => array('type' => 'smallinteger'), + 'tiny_int' => array('type' => 'tinyinteger'), 'bool' => array('type' => 'boolean', 'null' => false, 'default' => false), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)), 'tableParameters' => array() diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 6f4eca8b6..bfbdb5b6f 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -209,7 +209,7 @@ class MysqlTest extends CakeTestCase { $result = $this->model->schema(); $this->assertEquals('boolean', $result['bool']['type']); - $this->assertEquals('tinyint', $result['tiny_int']['type']); + $this->assertEquals('tinyinteger', $result['tiny_int']['type']); $this->assertTrue((bool)$this->model->save(array('bool' => 5, 'tiny_int' => 5))); $result = $this->model->find('first'); @@ -527,11 +527,11 @@ class MysqlTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $this->Dbo->column('tinyint'); - $expected = 'tinyint'; + $expected = 'tinyinteger'; $this->assertEquals($expected, $result); $result = $this->Dbo->column('smallint'); - $expected = 'smallint'; + $expected = 'smallinteger'; $this->assertEquals($expected, $result); $result = $this->Dbo->column('boolean'); @@ -3291,7 +3291,7 @@ SQL; */ public function buildColumnUnsignedProvider() { return array( - //set #0 + // unsigned int array( array( 'name' => 'testName', @@ -3301,7 +3301,7 @@ SQL; ), '`testName` int(11) UNSIGNED' ), - //set #1 + // unsigned bigint array( array( 'name' => 'testName', @@ -3311,7 +3311,7 @@ SQL; ), '`testName` bigint(20) UNSIGNED' ), - //set #2 + // unsigned float array( array( 'name' => 'testName', @@ -3320,7 +3320,7 @@ SQL; ), '`testName` float UNSIGNED' ), - //set #3 + // varchar array( array( 'name' => 'testName', @@ -3330,7 +3330,7 @@ SQL; ), '`testName` varchar(255)' ), - //set #4 + // date unsigned array( array( 'name' => 'testName', @@ -3339,7 +3339,7 @@ SQL; ), '`testName` date' ), - //set #5 + // date array( array( 'name' => 'testName', @@ -3348,7 +3348,7 @@ SQL; ), '`testName` date' ), - //set #6 + // integer with length array( array( 'name' => 'testName', @@ -3358,7 +3358,7 @@ SQL; ), '`testName` int(11)' ), - //set #7 + // unsigned decimal array( array( 'name' => 'testName', @@ -3367,7 +3367,7 @@ SQL; ), '`testName` decimal UNSIGNED' ), - //set #8 + // decimal with default array( array( 'name' => 'testName', @@ -3377,21 +3377,21 @@ SQL; ), '`testName` decimal UNSIGNED DEFAULT 1' ), - //set #9 + // smallinteger array( array( 'name' => 'testName', - 'type' => 'smallint', + 'type' => 'smallinteger', 'length' => 6, 'unsigned' => true ), '`testName` smallint(6) UNSIGNED' ), - //set #10 + // tinyinteger array( array( 'name' => 'testName', - 'type' => 'tinyint', + 'type' => 'tinyinteger', 'length' => 4, 'unsigned' => true ), diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 68db54f33..bc423d8ac 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -306,7 +306,7 @@ class PostgresTest extends CakeTestCase { $this->assertEquals('biginteger', $this->Dbo2->column('bigint')); $this->assertEquals('integer', $this->Dbo2->column('integer')); - $this->assertEquals('smallint', $this->Dbo2->column('smallint')); + $this->assertEquals('smallinteger', $this->Dbo2->column('smallint')); } /** diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php index ef206901a..b13bbb0ce 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php @@ -265,24 +265,24 @@ class SqliteTest extends CakeTestCase { $data = array( 'name' => 'testName', - 'type' => 'smallint', + 'type' => 'smallinteger', 'length' => 6, 'default' => 6, 'null' => false, ); $result = $this->Dbo->buildColumn($data); - $expected = '"testName" integer(6) DEFAULT 6 NOT NULL'; + $expected = '"testName" smallint(6) DEFAULT 6 NOT NULL'; $this->assertEquals($expected, $result); $data = array( 'name' => 'testName', - 'type' => 'tinyint', + 'type' => 'tinyinteger', 'length' => 4, 'default' => 4, 'null' => false, ); $result = $this->Dbo->buildColumn($data); - $expected = '"testName" integer(4) DEFAULT 4 NOT NULL'; + $expected = '"testName" tinyint(4) DEFAULT 4 NOT NULL'; $this->assertEquals($expected, $result); $data = array( @@ -412,13 +412,13 @@ class SqliteTest extends CakeTestCase { 'length' => null ), 'small_int' => array( - 'type' => 'integer', + 'type' => 'smallinteger', 'null' => true, 'default' => null, 'length' => null ), 'tiny_int' => array( - 'type' => 'integer', + 'type' => 'tinyinteger', 'null' => true, 'default' => null, 'length' => null diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php index 5d7df51ad..f37f0a140 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php @@ -532,12 +532,12 @@ class SqlserverTest extends CakeTestCase { $expected = '[client_id] int NULL'; $this->assertEquals($expected, $result); - $column = array('type' => 'smallint', 'name' => 'client_id'); + $column = array('type' => 'smallinteger', 'name' => 'client_id'); $result = $this->db->buildColumn($column); $expected = '[client_id] smallint NULL'; $this->assertEquals($expected, $result); - $column = array('type' => 'tinyint', 'name' => 'client_id'); + $column = array('type' => 'tinyinteger', 'name' => 'client_id'); $result = $this->db->buildColumn($column); $expected = '[client_id] tinyint NULL'; $this->assertEquals($expected, $result); diff --git a/lib/Cake/Test/Fixture/DatatypeFixture.php b/lib/Cake/Test/Fixture/DatatypeFixture.php index cf789b67e..68a3a9dbd 100644 --- a/lib/Cake/Test/Fixture/DatatypeFixture.php +++ b/lib/Cake/Test/Fixture/DatatypeFixture.php @@ -34,8 +34,8 @@ class DatatypeFixture extends CakeTestFixture { 'decimal_field' => array('type' => 'decimal', 'length' => '6,3', 'default' => '0.000'), 'huge_int' => array('type' => 'biginteger'), 'normal_int' => array('type' => 'integer'), - 'small_int' => array('type' => 'smallint'), - 'tiny_int' => array('type' => 'tinyint'), + 'small_int' => array('type' => 'smallinteger'), + 'tiny_int' => array('type' => 'tinyinteger'), 'bool' => array('type' => 'boolean', 'null' => false, 'default' => false), ); diff --git a/lib/Cake/Test/Fixture/UnsignedFixture.php b/lib/Cake/Test/Fixture/UnsignedFixture.php index a0eb97161..f6237d7e3 100644 --- a/lib/Cake/Test/Fixture/UnsignedFixture.php +++ b/lib/Cake/Test/Fixture/UnsignedFixture.php @@ -40,10 +40,10 @@ class UnsignedFixture extends CakeTestFixture { public $fields = array( 'uinteger' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary', 'unsigned' => true), 'integer' => array('type' => 'integer', 'length' => '8', 'unsigned' => false), - 'usmallint' => array('type' => 'smallint', 'unsigned' => true), - 'smallint' => array('type' => 'smallint', 'unsigned' => false), - 'utinyint' => array('type' => 'tinyint', 'unsigned' => true), - 'tinyint' => array('type' => 'tinyint', 'unsigned' => false), + 'usmallinteger' => array('type' => 'smallinteger', 'unsigned' => true), + 'smallinteger' => array('type' => 'smallinteger', 'unsigned' => false), + 'utinyinteger' => array('type' => 'tinyinteger', 'unsigned' => true), + 'tinyinteger' => array('type' => 'tinyinteger', 'unsigned' => false), 'udecimal' => array('type' => 'decimal', 'length' => '4', 'unsigned' => true), 'decimal' => array('type' => 'decimal', 'length' => '4'), 'biginteger' => array('type' => 'biginteger', 'length' => '20', 'default' => 3), diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index d1463372a..c828d141c 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1245,8 +1245,8 @@ class FormHelper extends AppHelper { 'date' => 'date', 'float' => 'number', 'integer' => 'number', - 'smallint' => 'number', - 'tinyint' => 'number', + 'smallinteger' => 'number', + 'tinyinteger' => 'number', 'decimal' => 'number', 'binary' => 'file' ); From c3f88c350e400134b0f551149f31b8d315dfd560 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 11 Mar 2017 21:46:14 -0500 Subject: [PATCH 11/11] Add default value generation for all integer types. This resolves the bigint issue raised by @chinpei in 10347 and adds default values for the new small & tiny integer types. --- lib/Cake/Console/Command/Task/FixtureTask.php | 3 +++ .../Test/Case/Console/Command/Task/FixtureTaskTest.php | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/Task/FixtureTask.php b/lib/Cake/Console/Command/Task/FixtureTask.php index d0329e944..ffad45bfc 100644 --- a/lib/Cake/Console/Command/Task/FixtureTask.php +++ b/lib/Cake/Console/Command/Task/FixtureTask.php @@ -335,6 +335,9 @@ class FixtureTask extends BakeTask { } $insert = ''; switch ($fieldInfo['type']) { + case 'tinyinteger': + case 'smallinteger': + case 'biginteger': case 'integer': case 'float': $insert = $i + 1; diff --git a/lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php index 01a7b2b27..de48fb2de 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php @@ -470,17 +470,20 @@ class FixtureTaskTest extends CakeTestCase { } /** - * test record generation with float and binary types + * test record generation with various integer, float and binary types * * @return void */ - public function testRecordGenerationForBinaryAndFloat() { + public function testRecordGenerationForBinaryFloatAndIntegerTypes() { $this->Task->connection = 'test'; $this->Task->path = '/my/path/'; $result = $this->Task->bake('Article', 'datatypes'); $this->assertContains("'float_field' => 1", $result); $this->assertContains("'bool' => 1", $result); + $this->assertContains("'tiny_int' => 1", $result); + $this->assertContains("'small_int' => 1", $result); + $this->assertContains("'huge_int' => 1", $result); $result = $this->Task->bake('Article', 'binary_tests'); $this->assertContains("'data' => 'Lorem ipsum dolor sit amet'", $result);