Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions system/Database/Postgre/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function increment(string $column, int $value = 1)
{
$column = $this->db->protectIdentifiers($column);

$sql = $this->_update($this->QBFrom[0], [$column => "to_number({$column}, '9999999') + {$value}"]);
$sql = $this->_update($this->QBFrom[0], [$column => "CAST({$column} AS numeric) + {$value}"]);

if (! $this->testMode) {
$this->resetWrite();
Expand All @@ -119,7 +119,7 @@ public function decrement(string $column, int $value = 1)
{
$column = $this->db->protectIdentifiers($column);

$sql = $this->_update($this->QBFrom[0], [$column => "to_number({$column}, '9999999') - {$value}"]);
$sql = $this->_update($this->QBFrom[0], [$column => "CAST({$column} AS numeric) - {$value}"]);

if (! $this->testMode) {
$this->resetWrite();
Expand Down
44 changes: 44 additions & 0 deletions tests/system/Database/Live/IncrementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ public function testIncrementWithValue(): void
$this->seeInDatabase('job', ['name' => 'incremental', 'description' => '8']);
}

public function testIncrementWithNumericColumns(): void
{
$this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]);

$this->db->table('job')
->where('name', 'incremental')
->increment('created_at');

$this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 7]);
}

public function testIncrementWithNumericColumnsAndValue(): void
{
$this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]);

$this->db->table('job')
->where('name', 'incremental')
->increment('created_at', 2);

$this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 8]);
}

public function testResetStateAfterIncrement(): void
{
$this->hasInDatabase('job', ['name' => 'account1', 'description' => '10']);
Expand Down Expand Up @@ -87,6 +109,28 @@ public function testDecrementWithValue(): void
$this->seeInDatabase('job', ['name' => 'incremental', 'description' => '4']);
}

public function testDecrementWithNumericColumns(): void
{
$this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]);

$this->db->table('job')
->where('name', 'incremental')
->decrement('created_at');

$this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 5]);
}

public function testDecrementWithNumericColumnsAndValue(): void
{
$this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]);

$this->db->table('job')
->where('name', 'incremental')
->decrement('created_at', 2);

$this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 4]);
}

public function testResetStateAfterDecrement(): void
{
$this->hasInDatabase('job', ['name' => 'account1', 'description' => '10']);
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Bugs Fixed
- **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.
- **Database:** Fixed a bug where the PostgreSQL driver's ``increment()`` and ``decrement()`` methods were not working for numeric columns.
- **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``.
Expand Down
Loading