From 9dbb20118eb8069f96bde43842dc09fc17f2452b Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 6 Aug 2026 13:37:08 -0400 Subject: [PATCH] UtilsSql - Optimize inserts with int values Pure int values do not need to be run through string escaping. --- CRM/Utils/SQL/Insert.php | 2 +- tests/phpunit/CRM/Utils/SQL/InsertTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/SQL/Insert.php b/CRM/Utils/SQL/Insert.php index 34e3245a3512..584c5cfafe81 100644 --- a/CRM/Utils/SQL/Insert.php +++ b/CRM/Utils/SQL/Insert.php @@ -145,7 +145,7 @@ public function row($row) { $escapedRow = []; foreach ($this->columns as $column) { - if (is_bool($row[$column])) { + if (is_bool($row[$column]) || is_int($row[$column])) { $escapedRow[$column] = (int) $row[$column]; } else { diff --git a/tests/phpunit/CRM/Utils/SQL/InsertTest.php b/tests/phpunit/CRM/Utils/SQL/InsertTest.php index ef5471be138d..745a4fb73884 100644 --- a/tests/phpunit/CRM/Utils/SQL/InsertTest.php +++ b/tests/phpunit/CRM/Utils/SQL/InsertTest.php @@ -13,11 +13,11 @@ public function setUp(): void { public function testRow_twice(): void { $insert = CRM_Utils_SQL_Insert::into('foo') - ->row(['first' => '1', 'second' => '2']) + ->row(['first' => '1', 'second' => 2]) ->row(['second' => '2b', 'first' => '1b']); $expected = ' INSERT INTO foo (`first`,`second`) VALUES - ("1","2"), + ("1",2), ("1b","2b") '; $this->assertLike($expected, $insert->toSQL());