Skip to content

Commit e3571ae

Browse files
committed
fix: remove escaping code for negative integer
It is inconsistent, with negative numbers we get a string. For positive, we get numbers.
1 parent 4e5f571 commit e3571ae

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

system/Database/BaseConnection.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,10 +1202,6 @@ public function escape($str)
12021202
return ($str === false) ? 0 : 1;
12031203
}
12041204

1205-
if (is_numeric($str) && $str < 0) {
1206-
return "{$str}";
1207-
}
1208-
12091205
return $str ?? 'NULL';
12101206
}
12111207

tests/system/Database/BaseQueryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,20 @@ public function testSetQueryBindsWithSetEscapeNegativeIntegers()
363363
$this->assertSame($expected, $query->getQuery());
364364
}
365365

366+
public function testSetQueryNamedBindsWithNegativeIntegers()
367+
{dd
368+
$query = new Query($this->db);
369+
370+
$query->setQuery(
371+
'SELECT * FROM product WHERE date_pickup < DateAdd(month, :num:, Convert(date, GetDate())',
372+
['num' => -6]
373+
);
374+
375+
$expected = 'SELECT * FROM product WHERE date_pickup < DateAdd(month, -6, Convert(date, GetDate())';
376+
377+
$this->assertSame($expected, $query->getQuery());
378+
}
379+
366380
/**
367381
* @see https://github.com/codeigniter4/CodeIgniter4/issues/2762
368382
*/

tests/system/Database/Live/EscapeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function setUp(): void
4040
*/
4141
public function testEscapeProtectsNegativeNumbers()
4242
{
43-
$this->assertSame('-100', $this->db->escape(-100));
43+
$this->assertSame(-100, $this->db->escape(-100));
4444
}
4545

4646
public function testEscape()

0 commit comments

Comments
 (0)