Skip to content
Open
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
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
73 changes: 73 additions & 0 deletions tests/system/Database/Live/SQLSRV/IncrementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* 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->assertInstanceOf(Builder::class, $this->db->table('job'));

$builder = $this->db->table('job');
Comment on lines +46 to +48
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.


$builder->castTextToInt = false;

$builder->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->assertInstanceOf(Builder::class, $this->db->table('job'));

$builder = $this->db->table('job');
Comment on lines +62 to +64
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interchange these two, then swap $builder to the 2nd arg of assertInstanceOf.


$builder->castTextToInt = false;

$builder->where('name', 'decremental')
->decrement('created_at');

$this->seeInDatabase('job', ['name' => 'decremental', 'created_at' => 5]);
}
}
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.
- **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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Database, then sort alphabetically:

Suggested change
- **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.
- **Database:** 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 <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down
Loading