From 8b9bd88926a06d22818d976c5eace4332e0b903b Mon Sep 17 00:00:00 2001 From: patel-vansh Date: Sun, 3 May 2026 16:02:51 +0530 Subject: [PATCH 1/7] Fix the bug --- system/Database/SQLSRV/Builder.php | 2 +- user_guide_src/source/changelogs/v4.7.3.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Database/SQLSRV/Builder.php b/system/Database/SQLSRV/Builder.php index 96890bf45cb2..44af621658a6 100644 --- a/system/Database/SQLSRV/Builder.php +++ b/system/Database/SQLSRV/Builder.php @@ -269,7 +269,7 @@ public function decrement(string $column, int $value = 1) if ($this->castTextToInt) { $values = [$column => "CONVERT(VARCHAR(MAX),CONVERT(INT,CONVERT(VARCHAR(MAX), {$column})) - {$value})"]; } else { - $values = [$column => "{$column} + {$value}"]; + $values = [$column => "{$column} - {$value}"]; } $sql = $this->_update($this->QBFrom[0], $values); diff --git a/user_guide_src/source/changelogs/v4.7.3.rst b/user_guide_src/source/changelogs/v4.7.3.rst index 257d8d91cba9..4d44990887bc 100644 --- a/user_guide_src/source/changelogs/v4.7.3.rst +++ b/user_guide_src/source/changelogs/v4.7.3.rst @@ -43,6 +43,7 @@ Bugs Fixed - **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets. - **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator. - **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``. +- **SQLSRV Database Driver:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false. See the repo's `CHANGELOG.md `_ From ef09e0adb8f4f0f39c24a91496f6036ab274e9ac Mon Sep 17 00:00:00 2001 From: patel-vansh Date: Tue, 5 May 2026 15:13:24 +0530 Subject: [PATCH 2/7] Added tests --- .../Database/Live/SQLSRV/IncrementTest.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/system/Database/Live/SQLSRV/IncrementTest.php diff --git a/tests/system/Database/Live/SQLSRV/IncrementTest.php b/tests/system/Database/Live/SQLSRV/IncrementTest.php new file mode 100644 index 000000000000..b4e563905635 --- /dev/null +++ b/tests/system/Database/Live/SQLSRV/IncrementTest.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Database\Live\SQLSRV; + +use CodeIgniter\Database\SQLSRV\Builder; +use CodeIgniter\Test\CIUnitTestCase; +use CodeIgniter\Test\DatabaseTestTrait; +use PHPUnit\Framework\Attributes\Group; +use Tests\Support\Database\Seeds\CITestSeeder; + +/** + * @internal + */ +#[Group('DatabaseLive')] +final class IncrementTest extends CIUnitTestCase +{ + use DatabaseTestTrait; + + protected $refresh = true; + protected $seed = CITestSeeder::class; + + protected function setUp(): void + { + parent::setUp(); + + if ($this->db->DBDriver !== 'SQLSRV') { + $this->markTestSkipped('This test is only for SQLSRV.'); + } + } + + public function testIncrementWhenCastTextToIntFalse(): void + { + $this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]); + + $this->assertTrue($this->db->table('job') instanceof Builder); + + $this->db->table('job')->castTextToInt = false; + + $this->db->table('job') + ->where('name', 'incremental') + ->increment('created_at'); + + $this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 7]); + } + + public function testDecrementWhenCastTextToIntFalse(): void + { + $this->hasInDatabase('job', ['name' => 'decremental', 'created_at' => 6]); + + $this->assertTrue($this->db->table('job') instanceof Builder); + + $this->db->table('job')->castTextToInt = false; + + $this->db->table('job') + ->where('name', 'decremental') + ->decrement('created_at'); + + $this->seeInDatabase('job', ['name' => 'decremental', 'created_at' => 5]); + } +} From 472a688bc2f5bdd462203530e2fea45b05ca93ab Mon Sep 17 00:00:00 2001 From: patel-vansh Date: Tue, 5 May 2026 15:16:03 +0530 Subject: [PATCH 3/7] change assertTrue to assertInstanceOf --- tests/system/Database/Live/SQLSRV/IncrementTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/Database/Live/SQLSRV/IncrementTest.php b/tests/system/Database/Live/SQLSRV/IncrementTest.php index b4e563905635..0296f7d776f4 100644 --- a/tests/system/Database/Live/SQLSRV/IncrementTest.php +++ b/tests/system/Database/Live/SQLSRV/IncrementTest.php @@ -43,7 +43,7 @@ public function testIncrementWhenCastTextToIntFalse(): void { $this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]); - $this->assertTrue($this->db->table('job') instanceof Builder); + $this->assertInstanceOf(Builder::class, $this->db->table('job')); $this->db->table('job')->castTextToInt = false; @@ -58,7 +58,7 @@ public function testDecrementWhenCastTextToIntFalse(): void { $this->hasInDatabase('job', ['name' => 'decremental', 'created_at' => 6]); - $this->assertTrue($this->db->table('job') instanceof Builder); + $this->assertInstanceOf(Builder::class, $this->db->table('job')); $this->db->table('job')->castTextToInt = false; From ca948a18796647e34ffbbb6c804bb8061f29826e Mon Sep 17 00:00:00 2001 From: patel-vansh Date: Tue, 5 May 2026 19:15:29 +0530 Subject: [PATCH 4/7] apply suggestion Co-authored-by: Michal Sniatala --- .../system/Database/Live/SQLSRV/IncrementTest.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/system/Database/Live/SQLSRV/IncrementTest.php b/tests/system/Database/Live/SQLSRV/IncrementTest.php index 0296f7d776f4..ce6040274ac5 100644 --- a/tests/system/Database/Live/SQLSRV/IncrementTest.php +++ b/tests/system/Database/Live/SQLSRV/IncrementTest.php @@ -45,10 +45,11 @@ public function testIncrementWhenCastTextToIntFalse(): void $this->assertInstanceOf(Builder::class, $this->db->table('job')); - $this->db->table('job')->castTextToInt = false; + $builder = $this->db->table('job'); - $this->db->table('job') - ->where('name', 'incremental') + $builder->castTextToInt = false; + + $builder->where('name', 'incremental') ->increment('created_at'); $this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 7]); @@ -60,10 +61,11 @@ public function testDecrementWhenCastTextToIntFalse(): void $this->assertInstanceOf(Builder::class, $this->db->table('job')); - $this->db->table('job')->castTextToInt = false; + $builder = $this->db->table('job'); + + $builder->castTextToInt = false; - $this->db->table('job') - ->where('name', 'decremental') + $builder->where('name', 'incremental') ->decrement('created_at'); $this->seeInDatabase('job', ['name' => 'decremental', 'created_at' => 5]); From b737a6759e146e44ef61b174699f7dbf3c6c5d7c Mon Sep 17 00:00:00 2001 From: patel-vansh Date: Tue, 5 May 2026 19:27:03 +0530 Subject: [PATCH 5/7] fix typo --- tests/system/Database/Live/SQLSRV/IncrementTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Database/Live/SQLSRV/IncrementTest.php b/tests/system/Database/Live/SQLSRV/IncrementTest.php index ce6040274ac5..0a917c5075f2 100644 --- a/tests/system/Database/Live/SQLSRV/IncrementTest.php +++ b/tests/system/Database/Live/SQLSRV/IncrementTest.php @@ -65,7 +65,7 @@ public function testDecrementWhenCastTextToIntFalse(): void $builder->castTextToInt = false; - $builder->where('name', 'incremental') + $builder->where('name', 'decremental') ->decrement('created_at'); $this->seeInDatabase('job', ['name' => 'decremental', 'created_at' => 5]); From 77f85c22c05ec382fa82fd9c65b4923a44d5cd83 Mon Sep 17 00:00:00 2001 From: patel-vansh Date: Wed, 6 May 2026 09:41:58 +0530 Subject: [PATCH 6/7] apply suggestion Co-authored-by: John Paul E. Balandan, CPA --- tests/system/Database/Live/SQLSRV/IncrementTest.php | 8 ++++---- user_guide_src/source/changelogs/v4.7.3.rst | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/system/Database/Live/SQLSRV/IncrementTest.php b/tests/system/Database/Live/SQLSRV/IncrementTest.php index 0a917c5075f2..c5ea28cd2692 100644 --- a/tests/system/Database/Live/SQLSRV/IncrementTest.php +++ b/tests/system/Database/Live/SQLSRV/IncrementTest.php @@ -43,10 +43,10 @@ public function testIncrementWhenCastTextToIntFalse(): void { $this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]); - $this->assertInstanceOf(Builder::class, $this->db->table('job')); - $builder = $this->db->table('job'); + $this->assertInstanceOf(Builder::class, $builder); + $builder->castTextToInt = false; $builder->where('name', 'incremental') @@ -59,10 +59,10 @@ public function testDecrementWhenCastTextToIntFalse(): void { $this->hasInDatabase('job', ['name' => 'decremental', 'created_at' => 6]); - $this->assertInstanceOf(Builder::class, $this->db->table('job')); - $builder = $this->db->table('job'); + $this->assertInstanceOf(Builder::class, $builder); + $builder->castTextToInt = false; $builder->where('name', 'decremental') diff --git a/user_guide_src/source/changelogs/v4.7.3.rst b/user_guide_src/source/changelogs/v4.7.3.rst index 4d44990887bc..d0b78c88bc29 100644 --- a/user_guide_src/source/changelogs/v4.7.3.rst +++ b/user_guide_src/source/changelogs/v4.7.3.rst @@ -42,8 +42,8 @@ Bugs Fixed - **Common:** Fixed a bug where the ``command()`` helper function did not properly clean up output buffers, which could lead to risky tests when exceptions were thrown. - **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets. - **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator. +- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false. - **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``. -- **SQLSRV Database Driver:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false. See the repo's `CHANGELOG.md `_ From f1e42433058fc16d5e666d98b6b4975b91a1507f Mon Sep 17 00:00:00 2001 From: patel-vansh Date: Wed, 6 May 2026 09:44:39 +0530 Subject: [PATCH 7/7] Reorder after rebase --- user_guide_src/source/changelogs/v4.7.3.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.7.3.rst b/user_guide_src/source/changelogs/v4.7.3.rst index d0b78c88bc29..06418cf9e5e8 100644 --- a/user_guide_src/source/changelogs/v4.7.3.rst +++ b/user_guide_src/source/changelogs/v4.7.3.rst @@ -40,9 +40,9 @@ Bugs Fixed - **CLI:** Fixed a bug where ``CLI::generateDimensions()`` leaked ``stty`` error output (e.g., ``stty: 'standard input': Inappropriate ioctl for device``) to stderr when stdin was not a TTY. - **Commands:** Fixed a bug in the ``env`` command where passing options only would cause the command to throw a ``TypeError`` instead of showing the current environment. - **Common:** Fixed a bug where the ``command()`` helper function did not properly clean up output buffers, which could lead to risky tests when exceptions were thrown. +- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false. - **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets. - **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator. -- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false. - **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``. See the repo's