Skip to content

Commit 9a4da43

Browse files
committed
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
1 parent 5d52f33 commit 9a4da43

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

system/Database/Postgre/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
357357
// autoincrement identity field must use DEFAULT and not NULL
358358
// this could be removed in favour of leaving to developer but does make things easier and function like other DBMS
359359
foreach ($constraints as $constraint) {
360-
$key = array_search(trim($constraint, '"'), $fieldNames, true);
360+
$key = array_search(trim((string) $constraint, '"'), $fieldNames, true);
361361

362362
if ($key !== false) {
363363
foreach ($values as $arrayKey => $value) {
364-
if (strtoupper($value[$key]) === 'NULL') {
364+
if (strtoupper((string) $value[$key]) === 'NULL') {
365365
$values[$arrayKey][$key] = 'DEFAULT';
366366
}
367367
}

0 commit comments

Comments
 (0)