From f4772813bc897ab495a5ceb629bf7d28f1d0bb1c Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 24 Oct 2023 20:52:35 -0300 Subject: [PATCH 1/7] Add tests for fail boolean type. --- tests/ColumnSchemaTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ColumnSchemaTest.php b/tests/ColumnSchemaTest.php index f7ef59a6..9642c05a 100644 --- a/tests/ColumnSchemaTest.php +++ b/tests/ColumnSchemaTest.php @@ -56,7 +56,7 @@ public function testPhpTypeCast(): void $this->assertSame(1.234, $floatColPhpType); $this->assertSame("\x10\x11\x12", $blobColPhpType); $this->assertSame('2023-07-11 14:50:00.123', $datetimeColPhpType); - $this->assertEquals(false, $boolColPhpType); + $this->assertFalse($boolColPhpType); $db->close(); } From 0ce3b21d5e1fd731ef74e020597ac487c39caeae Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 24 Oct 2023 20:57:47 -0300 Subject: [PATCH 2/7] Fix correction bit type with boolean. --- src/Schema.php | 14 ++++---------- tests/Support/Fixture/mssql.sql | 4 ++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Schema.php b/src/Schema.php index f1fb7caa..1d9bfcde 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -444,6 +444,10 @@ protected function loadColumnSchema(array $info): ColumnSchemaInterface $column->type($this->typeMap[$type]); } + if ($type === 'bit') { + $column->type(self::TYPE_BOOLEAN); + } + if (!empty($matches[2])) { $values = explode(',', $matches[2]); $column->precision((int) $values[0]); @@ -452,16 +456,6 @@ protected function loadColumnSchema(array $info): ColumnSchemaInterface if (isset($values[1])) { $column->scale((int) $values[1]); } - - if ($column->getSize() === 1 && ($type === 'tinyint' || $type === 'bit')) { - $column->type(self::TYPE_BOOLEAN); - } elseif ($type === 'bit') { - if ($column->getSize() > 32) { - $column->type(self::TYPE_BIGINT); - } elseif ($column->getSize() === 32) { - $column->type(self::TYPE_INTEGER); - } - } } } diff --git a/tests/Support/Fixture/mssql.sql b/tests/Support/Fixture/mssql.sql index b5028353..3fdc5fd5 100644 --- a/tests/Support/Fixture/mssql.sql +++ b/tests/Support/Fixture/mssql.sql @@ -156,8 +156,8 @@ CREATE TABLE [dbo].[type] ( [blob_col] [varbinary](MAX), [numeric_col] [decimal](5,2) DEFAULT '33.22', [datetime_col] [datetime] NOT NULL DEFAULT '2002-01-01 00:00:00', - [bool_col] [tinyint] NOT NULL, - [bool_col2] [tinyint] DEFAULT '1' + [bool_col] [bit] NOT NULL, + [bool_col2] [bit] DEFAULT '1' ); CREATE TABLE [dbo].[animal] ( From 7e6b94e45bc0d9abb5ac4c6fdb9e2e2ad1e676c1 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 24 Oct 2023 21:28:56 -0300 Subject: [PATCH 3/7] Update tests. --- tests/Provider/CommandProvider.php | 10 +++++----- tests/Provider/QueryBuilderProvider.php | 2 +- tests/Provider/SchemaProvider.php | 14 +++++++------- tests/Provider/Type/BitProvider.php | 6 +++--- tests/Type/BitTest.php | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/Provider/CommandProvider.php b/tests/Provider/CommandProvider.php index 70326b2b..8d5035f7 100644 --- a/tests/Provider/CommandProvider.php +++ b/tests/Provider/CommandProvider.php @@ -22,14 +22,14 @@ public static function batchInsert(): array { $batchInsert = parent::batchInsert(); - $batchInsert['multirow']['expectedParams'][':qp3'] = 1; - $batchInsert['multirow']['expectedParams'][':qp7'] = 0; + $batchInsert['multirow']['expectedParams'][':qp3'] = true; + $batchInsert['multirow']['expectedParams'][':qp7'] = false; - $batchInsert['issue11242']['expectedParams'][':qp3'] = 1; + $batchInsert['issue11242']['expectedParams'][':qp3'] = true; - $batchInsert['wrongBehavior']['expectedParams'][':qp3'] = 0; + $batchInsert['wrongBehavior']['expectedParams'][':qp3'] = false; - $batchInsert['batchInsert binds params from expression']['expectedParams'][':qp3'] = 0; + $batchInsert['batchInsert binds params from expression']['expectedParams'][':qp3'] = false; return $batchInsert; } diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index aea94267..21c71be3 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -128,7 +128,7 @@ public static function insertWithReturningPks(): array ['{{%type}}.[[related_id]]' => null, '[[time]]' => new Expression('now()')], [], << null], ], diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index 039aa5c1..fd8b8ac6 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -171,9 +171,9 @@ public static function columns(): array 'defaultValue' => '2002-01-01 00:00:00', ], 'bool_col' => [ - 'type' => 'tinyint', - 'dbType' => 'tinyint', - 'phpType' => 'integer', + 'type' => 'boolean', + 'dbType' => 'bit', + 'phpType' => 'boolean', 'primaryKey' => false, 'allowNull' => false, 'autoIncrement' => false, @@ -184,9 +184,9 @@ public static function columns(): array 'defaultValue' => null, ], 'bool_col2' => [ - 'type' => 'tinyint', - 'dbType' => 'tinyint', - 'phpType' => 'integer', + 'type' => 'boolean', + 'dbType' => 'bit', + 'phpType' => 'boolean', 'primaryKey' => false, 'allowNull' => true, 'autoIncrement' => false, @@ -194,7 +194,7 @@ public static function columns(): array 'size' => null, 'precision' => null, 'scale' => null, - 'defaultValue' => 1, + 'defaultValue' => true, ], ], 'tableName' => 'type', diff --git a/tests/Provider/Type/BitProvider.php b/tests/Provider/Type/BitProvider.php index 4b28ae78..adddfe5d 100644 --- a/tests/Provider/Type/BitProvider.php +++ b/tests/Provider/Type/BitProvider.php @@ -9,9 +9,9 @@ final class BitProvider public static function columns(): array { return [ - ['Mybit1', 'bit', 'integer', 0], - ['Mybit2', 'bit', 'integer', 1], - ['Mybit3', 'bit', 'integer', 2], + ['Mybit1', 'bit', 'boolean', false], + ['Mybit2', 'bit', 'boolean', true], + ['Mybit3', 'bit', 'boolean', true], ]; } } diff --git a/tests/Type/BitTest.php b/tests/Type/BitTest.php index 2b5141ef..36bcdfc7 100644 --- a/tests/Type/BitTest.php +++ b/tests/Type/BitTest.php @@ -37,7 +37,7 @@ public function testCreateTableWithDefaultValue( string $column, string $dbType, string $phpType, - int $defaultValue + bool $defaultValue ): void { $db = $this->buildTable(); @@ -89,7 +89,7 @@ public function testDefaultValue( string $column, string $dbType, string $phpType, - int $defaultValue + bool $defaultValue ): void { $this->setFixture('Type/bit.sql'); @@ -198,7 +198,7 @@ public function testMaxValue(): void $this->assertSame( [ 'id' => '2', - 'Mybit1' => '0', + 'Mybit1' => '1', 'Mybit2' => '1', 'Mybit3' => '1', ], @@ -251,7 +251,7 @@ public function testMinValue(): void [ 'id' => '2', 'Mybit1' => null, - 'Mybit2' => '0', + 'Mybit2' => '1', 'Mybit3' => '1', ], $command->setSql( From 1c0573ac9fd339f8c6a0e4725646b96ae88918a9 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 24 Oct 2023 21:44:16 -0300 Subject: [PATCH 4/7] Update scrutinizer.yml. --- .scrutinizer.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index b57b3b6a..73034ce5 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -56,8 +56,7 @@ build: - /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE yiitest' - pecl channel-update pecl.php.net - pecl install pdo_sqlsrv - - composer config preferred-install.yiisoft/db source - - composer update --no-interaction --no-progress --optimize-autoloader --ansi + - composer require yiisoft/db:"dev-master as 1.0" --ansi tests: override: From 3374fc607b03983a6c2adcdcbc9052914135b9c0 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Tue, 24 Oct 2023 21:50:33 -0300 Subject: [PATCH 5/7] Update scrutinizer.yml. --- .scrutinizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 73034ce5..ab7dc881 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -56,7 +56,7 @@ build: - /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE yiitest' - pecl channel-update pecl.php.net - pecl install pdo_sqlsrv - - composer require yiisoft/db:"dev-master as 1.0" --ansi + - composer require yiisoft/db:dev-master --ansi tests: override: From d08fa3bec9c3a5287e2c4f9a1d225567c83e0c10 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 25 Oct 2023 05:44:50 -0300 Subject: [PATCH 6/7] Apply fix corrections. --- CHANGELOG.md | 1 + tests/CommandTest.php | 16 ---------------- tests/Provider/CommandProvider.php | 16 ---------------- tests/Provider/Type/BitProvider.php | 1 - tests/Support/Fixture/Type/bit.sql | 1 - tests/Type/BitTest.php | 2 -- 6 files changed, 1 insertion(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12140e25..ebcadeba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.0.2 under development +- Bug #280: Fix type boolean (@terabytesoftw) - Bug #278: Remove `RECURSIVE` expression from CTE queries (@Tigrov) ## 1.0.1 July 24, 2023 diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 79768656..2c1896c4 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -51,22 +51,6 @@ public function testAlterColumn(): void $this->assertSame('ntext', $columns['email']->getDbType()); } - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\CommandProvider::batchInsert - * - * @throws Throwable - */ - public function testBatchInsert( - string $table, - array $columns, - array $values, - string $expected, - array $expectedParams = [], - int $insertedRow = 1 - ): void { - parent::testBatchInsert($table, $columns, $values, $expected, $expectedParams, $insertedRow); - } - /** * @throws Exception * @throws InvalidConfigException diff --git a/tests/Provider/CommandProvider.php b/tests/Provider/CommandProvider.php index 8d5035f7..5f429c40 100644 --- a/tests/Provider/CommandProvider.php +++ b/tests/Provider/CommandProvider.php @@ -18,22 +18,6 @@ final class CommandProvider extends \Yiisoft\Db\Tests\Provider\CommandProvider protected static string $driverName = 'sqlsrv'; - public static function batchInsert(): array - { - $batchInsert = parent::batchInsert(); - - $batchInsert['multirow']['expectedParams'][':qp3'] = true; - $batchInsert['multirow']['expectedParams'][':qp7'] = false; - - $batchInsert['issue11242']['expectedParams'][':qp3'] = true; - - $batchInsert['wrongBehavior']['expectedParams'][':qp3'] = false; - - $batchInsert['batchInsert binds params from expression']['expectedParams'][':qp3'] = false; - - return $batchInsert; - } - /** * @throws JsonException */ diff --git a/tests/Provider/Type/BitProvider.php b/tests/Provider/Type/BitProvider.php index adddfe5d..7872310b 100644 --- a/tests/Provider/Type/BitProvider.php +++ b/tests/Provider/Type/BitProvider.php @@ -11,7 +11,6 @@ public static function columns(): array return [ ['Mybit1', 'bit', 'boolean', false], ['Mybit2', 'bit', 'boolean', true], - ['Mybit3', 'bit', 'boolean', true], ]; } } diff --git a/tests/Support/Fixture/Type/bit.sql b/tests/Support/Fixture/Type/bit.sql index ab003f9b..2701be7e 100644 --- a/tests/Support/Fixture/Type/bit.sql +++ b/tests/Support/Fixture/Type/bit.sql @@ -15,7 +15,6 @@ CREATE TABLE [dbo].[bit_default] ( [id] [int] IDENTITY NOT NULL, [Mybit1] [bit] NOT NULL DEFAULT 0, [Mybit2] [bit] NOT NULL DEFAULT 1, - [Mybit3] [bit] NOT NULL DEFAULT 2, CONSTRAINT [PK_bit_default_pk] PRIMARY KEY CLUSTERED ( [id] ASC ) ON [PRIMARY] diff --git a/tests/Type/BitTest.php b/tests/Type/BitTest.php index 36bcdfc7..afde50ce 100644 --- a/tests/Type/BitTest.php +++ b/tests/Type/BitTest.php @@ -280,7 +280,6 @@ private function buildTable(): ConnectionInterface 'id' => 'INT IDENTITY NOT NULL', 'Mybit1' => 'BIT DEFAULT 0', // Min value 'Mybit2' => 'BIT DEFAULT 1', // Max value - 'Mybit3' => 'BIT DEFAULT 2', // Max value ], )->execute(); @@ -293,7 +292,6 @@ private function getColumns(): array 'id' => '1', 'Mybit1' => '0', 'Mybit2' => '1', - 'Mybit3' => '1', ]; } } From 056cf42585047c89513604267efe5913567c6ed8 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 25 Oct 2023 15:04:41 -0300 Subject: [PATCH 7/7] Fix order changelog. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebcadeba..25dcaf9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ ## 1.0.2 under development -- Bug #280: Fix type boolean (@terabytesoftw) - Bug #278: Remove `RECURSIVE` expression from CTE queries (@Tigrov) +- Bug #280: Fix type boolean (@terabytesoftw) ## 1.0.1 July 24, 2023