Skip to content

Commit 6f70eca

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 b7deefa commit 6f70eca

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
@@ -355,11 +355,11 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
355355
// autoincrement identity field must use DEFAULT and not NULL
356356
// this could be removed in favour of leaving to developer but does make things easier and function like other DBMS
357357
foreach ($constraints as $constraint) {
358-
$key = array_search(trim($constraint, '"'), $fieldNames, true);
358+
$key = array_search(trim((string) $constraint, '"'), $fieldNames, true);
359359

360360
if ($key !== false) {
361361
foreach ($values as $arrayKey => $value) {
362-
if (strtoupper($value[$key]) === 'NULL') {
362+
if (strtoupper((string) $value[$key]) === 'NULL') {
363363
$values[$arrayKey][$key] = 'DEFAULT';
364364
}
365365
}

0 commit comments

Comments
 (0)