Skip to content

fix: SQLSRV driver's decrement() method#10155

Open
patel-vansh wants to merge 7 commits intocodeigniter4:developfrom
patel-vansh:fix/sqlsrv-decrement-bug
Open

fix: SQLSRV driver's decrement() method#10155
patel-vansh wants to merge 7 commits intocodeigniter4:developfrom
patel-vansh:fix/sqlsrv-decrement-bug

Conversation

@patel-vansh
Copy link
Copy Markdown
Contributor

Description
As discovered by @paulbalandan in this comment, SQLSRV Database Driver was incorrectly adding instead of subtracting the decrement value when $castTextToInt was false.

This PR fixes that bug by flipping the sign in decrement() function.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@patel-vansh
Copy link
Copy Markdown
Contributor Author

patel-vansh commented May 3, 2026

I am quite unsure about the tests in this case. Do I need to add a new file in tests/system/Database/Live/SQLSRV directory? Or add a particular test inside the normal IncrementTest.php file?

@michalsn
Copy link
Copy Markdown
Member

michalsn commented May 4, 2026

The new class under the SQLSRV directory would be better. Please add tests for both increment() and decrement() with castTextToInt = false. You can use the existing job table and its integer created_at field for this.

@patel-vansh
Copy link
Copy Markdown
Contributor Author

The new class under the SQLSRV directory would be better. Please add tests for both increment() and decrement() with castTextToInt = false. You can use the existing job table and its integer created_at field for this.

Idk if I've added the tests as expected, as I didn't found any direct option to modify castTextToInt. Also, the assertInstanceOf assertion is to prevent PHPStan from complaining.

Comment thread tests/system/Database/Live/SQLSRV/IncrementTest.php Outdated
@patel-vansh patel-vansh marked this pull request as ready for review May 5, 2026 14:11
@paulbalandan paulbalandan added bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer labels May 5, 2026
Comment thread user_guide_src/source/changelogs/v4.7.3.rst Outdated
Comment thread tests/system/Database/Live/SQLSRV/IncrementTest.php Outdated
Comment thread tests/system/Database/Live/SQLSRV/IncrementTest.php Outdated
patel-vansh and others added 7 commits May 6, 2026 09:42
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
Co-authored-by: John Paul E. Balandan, CPA <paulbalandan@gmail.com>
@patel-vansh patel-vansh force-pushed the fix/sqlsrv-decrement-bug branch from 95e4622 to f1e4243 Compare May 6, 2026 04:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants