From 5d82672764bacddabb9d5b1a3c4663cfaa7b97a5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 29 Nov 2023 11:36:56 +0900 Subject: [PATCH] refactor: fix TypeError in Postgre/Builder.php There were 2 errors: 1) CodeIgniter\Database\Live\UpsertTest::testUpsertWithMatchingDataOnUniqueIndexandPrimaryKey TypeError: strtoupper(): Argument #1 ($string) must be of type string, int given /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/Postgre/Builder.php:364 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseBuilder.php:1790 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseBuilder.php:1927 /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/Live/UpsertTest.php:410 2) CodeIgniter\Database\Live\UpsertTest::testUpsertBatchOnPrimaryKey TypeError: strtoupper(): Argument #1 ($string) must be of type string, int given /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/Postgre/Builder.php:364 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseBuilder.php:1790 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseBuilder.php:1961 /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/Live/UpsertTest.php:457 -- There was 1 failure: 1) CodeIgniter\Database\Live\UpsertTest::testUpsertCauseConstraintError Failed asserting that exception of type "TypeError" matches expected exception "CodeIgniter\Database\Exceptions\DatabaseException". Message was: "trim(): Argument #1 ($string) must be of type string, CodeIgniter\Database\RawSql given" at /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/Postgre/Builder.php:360 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseBuilder.php:1790 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseBuilder.php:1927 /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/Live/UpsertTest.php:303 --- system/Database/Postgre/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index 9cee16e1403a..8b2754a6c28f 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -357,11 +357,11 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri // autoincrement identity field must use DEFAULT and not NULL // this could be removed in favour of leaving to developer but does make things easier and function like other DBMS foreach ($constraints as $constraint) { - $key = array_search(trim($constraint, '"'), $fieldNames, true); + $key = array_search(trim((string) $constraint, '"'), $fieldNames, true); if ($key !== false) { foreach ($values as $arrayKey => $value) { - if (strtoupper($value[$key]) === 'NULL') { + if (strtoupper((string) $value[$key]) === 'NULL') { $values[$arrayKey][$key] = 'DEFAULT'; } }