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/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index 2dc03a5c3..eaba7b0ee 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'] === 'smallinteger') { + $guess = $methods['numeric']; + } elseif ($metaData['type'] === 'tinyinteger') { + $guess = $methods['numeric']; } elseif ($metaData['type'] === 'float') { $guess = $methods['numeric']; } elseif ($metaData['type'] === 'boolean') { diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index bb6e1d18e..52310492c 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', 'smallinteger', 'tinyinteger', 'float', 'decimal', 'biginteger') ) ); @@ -110,6 +114,7 @@ class Mysql extends DboSource { * MySQL column definition * * @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'), @@ -117,6 +122,8 @@ class Mysql extends DboSource { 'text' => array('name' => 'text'), 'biginteger' => array('name' => 'bigint', 'limit' => '20'), 'integer' => array('name' => 'int', 'limit' => '11', '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'), @@ -783,6 +790,12 @@ class Mysql extends DboSource { if (strpos($col, 'bigint') !== false || $col === 'bigint') { return 'biginteger'; } + if (strpos($col, 'tinyint') !== false) { + return 'tinyinteger'; + } + if (strpos($col, 'smallint') !== false) { + 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 8673fbc5c..341531320 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -52,12 +52,15 @@ class Postgres extends DboSource { * Columns * * @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'), 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), 'integer' => array('name' => 'integer', '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'), @@ -701,6 +704,8 @@ class Postgres extends DboSource { return 'time'; case ($col === 'bigint'): return 'biginteger'; + case ($col === '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 bfda2c8dd..6d34e7e4d 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -64,12 +64,15 @@ class Sqlite extends DboSource { * SQLite3 column definition * * @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'), 'string' => array('name' => 'varchar', 'limit' => '255'), 'text' => array('name' => 'text'), 'integer' => 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'), @@ -272,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 90590e6ad..ee2fd3d85 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -85,12 +85,15 @@ class Sqlserver extends DboSource { * MS SQL column definition * * @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'), 'string' => array('name' => 'nvarchar', 'limit' => '255'), 'text' => array('name' => 'nvarchar', 'limit' => 'MAX'), 'integer' => array('name' => 'int', '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'), @@ -435,6 +438,12 @@ class Sqlserver extends DboSource { if (strpos($col, 'bigint') !== false) { return 'biginteger'; } + if (strpos($col, 'smallint') !== false) { + return 'smallinteger'; + } + if (strpos($col, 'tinyint') !== false) { + return 'tinyinteger'; + } if (strpos($col, 'int') !== false) { return 'integer'; } 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); diff --git a/lib/Cake/Test/Case/Model/CakeSchemaTest.php b/lib/Cake/Test/Case/Model/CakeSchemaTest.php index aedb6ef3d..be096484b 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' => '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 8e7dc7b3c..bfbdb5b6f 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('tinyinteger', $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)); @@ -526,6 +526,14 @@ class MysqlTest extends CakeTestCase { $expected = 'boolean'; $this->assertEquals($expected, $result); + $result = $this->Dbo->column('tinyint'); + $expected = 'tinyinteger'; + $this->assertEquals($expected, $result); + + $result = $this->Dbo->column('smallint'); + $expected = 'smallinteger'; + $this->assertEquals($expected, $result); + $result = $this->Dbo->column('boolean'); $expected = 'boolean'; $this->assertEquals($expected, $result); @@ -3283,7 +3291,7 @@ SQL; */ public function buildColumnUnsignedProvider() { return array( - //set #0 + // unsigned int array( array( 'name' => 'testName', @@ -3293,7 +3301,7 @@ SQL; ), '`testName` int(11) UNSIGNED' ), - //set #1 + // unsigned bigint array( array( 'name' => 'testName', @@ -3303,7 +3311,7 @@ SQL; ), '`testName` bigint(20) UNSIGNED' ), - //set #2 + // unsigned float array( array( 'name' => 'testName', @@ -3312,7 +3320,7 @@ SQL; ), '`testName` float UNSIGNED' ), - //set #3 + // varchar array( array( 'name' => 'testName', @@ -3322,7 +3330,7 @@ SQL; ), '`testName` varchar(255)' ), - //set #4 + // date unsigned array( array( 'name' => 'testName', @@ -3331,7 +3339,7 @@ SQL; ), '`testName` date' ), - //set #5 + // date array( array( 'name' => 'testName', @@ -3340,7 +3348,7 @@ SQL; ), '`testName` date' ), - //set #6 + // integer with length array( array( 'name' => 'testName', @@ -3350,7 +3358,7 @@ SQL; ), '`testName` int(11)' ), - //set #7 + // unsigned decimal array( array( 'name' => 'testName', @@ -3359,7 +3367,7 @@ SQL; ), '`testName` decimal UNSIGNED' ), - //set #8 + // decimal with default array( array( 'name' => 'testName', @@ -3368,6 +3376,26 @@ SQL; 'default' => 1 ), '`testName` decimal UNSIGNED DEFAULT 1' + ), + // smallinteger + array( + array( + 'name' => 'testName', + 'type' => 'smallinteger', + 'length' => 6, + 'unsigned' => true + ), + '`testName` smallint(6) UNSIGNED' + ), + // tinyinteger + array( + array( + 'name' => 'testName', + 'type' => 'tinyinteger', + 'length' => 4, + 'unsigned' => true + ), + '`testName` tinyint(4) UNSIGNED' ) ); } diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 9158efcd2..bc423d8ac 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('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 8f831a671..b13bbb0ce 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' => 'smallinteger', + 'length' => 6, + 'default' => 6, + 'null' => false, + ); + $result = $this->Dbo->buildColumn($data); + $expected = '"testName" smallint(6) DEFAULT 6 NOT NULL'; + $this->assertEquals($expected, $result); + + $data = array( + 'name' => 'testName', + 'type' => 'tinyinteger', + 'length' => 4, + 'default' => 4, + 'null' => false, + ); + $result = $this->Dbo->buildColumn($data); + $expected = '"testName" tinyint(4) DEFAULT 4 NOT NULL'; + $this->assertEquals($expected, $result); + $data = array( 'name' => 'huge', 'type' => 'biginteger', @@ -383,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' => 'smallinteger', + 'null' => true, + 'default' => null, + 'length' => null + ), + 'tiny_int' => array( + 'type' => 'tinyinteger', + 'null' => true, + 'default' => null, + 'length' => null + ), 'bool' => array( 'type' => 'boolean', 'null' => false, diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php index 81fa8e7b2..f37f0a140 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' => 'smallinteger', 'name' => 'client_id'); + $result = $this->db->buildColumn($column); + $expected = '[client_id] smallint NULL'; + $this->assertEquals($expected, $result); + + $column = array('type' => 'tinyinteger', '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'; diff --git a/lib/Cake/Test/Fixture/DatatypeFixture.php b/lib/Cake/Test/Fixture/DatatypeFixture.php index 14b1162e5..68a3a9dbd 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' => 'smallinteger'), + 'tiny_int' => array('type' => 'tinyinteger'), '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 + ), ); } diff --git a/lib/Cake/Test/Fixture/UnsignedFixture.php b/lib/Cake/Test/Fixture/UnsignedFixture.php index 1c8eb2f28..f6237d7e3 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), + '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 49083962f..c828d141c 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', + 'smallinteger' => 'number', + 'tinyinteger' => 'number', + 'decimal' => 'number', 'binary' => 'file' );