Uh oh!
There was an error while loading. Please reload this page.
feat: Add incrementMany() and decrementMany() methods to BaseBuilder and other driver specific builders - #10140
Conversation
paulbalandan
left a comment
There was a problem hiding this comment.
Have you considered adding a separate incrementAll (or other wording) that will take care of the array, so to minimize the BC break?
PS. The random test failure seems legitimate. I'll deal with that later.
michalsn
commented
Apr 25, 2026
I also think that |
Yeah, that would avoid BC. I guess Maybe the current increment method calls incrementAll internally? So, there's no duplication of any logic. |
michalsn
commented
Apr 25, 2026
I see why not. |
incrementAll() and decrementAll() methods to BaseBuilder and other driver specific builderspatel-vansh
commented
Apr 25, 2026
Not sure why PHPStan analysis have failed. |
paulbalandan
commented
Apr 25, 2026
You apparently fixed (or renamed) the affected code. Just run |
michalsn
left a comment
There was a problem hiding this comment.
Supporting a more convenient API would be nice:
incrementAll(['one', 'two'], 2)
incrementAll(['one' => 2, 'two' => 3])What do you think?
Something like:
publicfunctionincrementAll(array$columns, int$value = 1): bool
{
$fields = [];
if (array_is_list($columns)) {
foreach ($columnsas$column) {
$column = $this->db->protectIdentifiers($column);
$fields[$column] = "{$column} + {$value}";
}
} else {
foreach ($columnsas$column => $value) {
if (! is_int($value)) {
thrownewTypeError(...);
}
$column = $this->db->protectIdentifiers($column);
$fields[$column] = "{$column} + {$value}";
}
}
// ...
}Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
patel-vansh
commented
Apr 27, 2026
|
patel-vansh
commented
Apr 27, 2026
I chose
|
incrementAll() and decrementAll() methods to BaseBuilder and other driver specific buildersincrementMany() and decrementMany() methods to BaseBuilder and other driver specific buildersUh oh!
There was an error while loading. Please reload this page.
| Query Builder | ||
| ------------- | ||
| - Added new ``incrementMany()`` and ``decrementMany()`` methods to ``CodeIgniter\Database\BaseBuilder`` for performing bulk increment/decrement operations. |
There was a problem hiding this comment.
You have removed the public methods for SQLSRV and Postgre. I think it needs to be displayed in the BC section. I can't write a suggestion well, let them correct me.The Postgre::increment() method ... has been removed. Added new incrementMany() instead.
There was a problem hiding this comment.
increment() and decrement() are still public through inheritance from BaseBuilder. People overriding those methods in their own subclass can still do so. People calling parent::increment() from a subclass still get working behavior.
Uh oh!
There was an error while loading. Please reload this page.
| $fields = []; | ||
| foreach ($columns as $col => $val) { | ||
| if (! is_int($val)) { |
There was a problem hiding this comment.
You forgot to test negative values. The is_int() check will work correctly and the data will be changed incorrectly: field + -1. It is necessary to prohibit these values.
The comment applies to all new methods
There was a problem hiding this comment.
Actually, negative values were allowed in earlier behaviour. increment() method allowed negative values which would actually subtract from the field instead of adding. So, I tried to retain that behaviour. If everyone agrees to change that, I would happily change this to disallow negative values in both incrementMany() and decrementMany() method
There was a problem hiding this comment.
I see no problem with allowing negative values. This may be an actively used feature.
patel-vansh
commented
May 5, 2026
I was looking at the PostgreSQL Builder's failing test cases and found that the current implementation ( So, here's my suggestion. Instead of |
michalsn
commented
May 5, 2026
sounds reasonable to me. I do not see BC break here. |
d1c5747 to
3127b88Compare
neznaika0
left a comment
There was a problem hiding this comment.
Okay, but I still haven't seen any negative value tests:
1. (-10) ± (-5)
2. 10 ± (-5)
Uh oh!
There was an error while loading. Please reload this page.
👋 Hi, @patel-vansh! |
…ns as input Co-authored-by: Copilot <copilot@github.com>
# Conflicts: # user_guide_src/source/changelogs/v4.8.0.rst
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: neznaika0 <ozornick.ks@gmail.com>
57ddc07 to
155e206CompareCo-authored-by: John Paul E. Balandan, CPA <paulbalandan@gmail.com> Co-authored-by: Michal Sniatala <michal@sniatala.pl>
Uh oh!
There was an error while loading. Please reload this page.
michalsn
commented
May 7, 2026
Thank you @patel-vansh |
Description
This PR adds two new functions in
BaseBuilder.php—incrementMany()anddecrementMany(). These two functions enable devs to increment/decrement multiple rows at once atomically.Also, the
increment()anddecrement()methods now internally callincrementMany()anddecrementMany()respectively to prevent duplicating the logic.Checklist: