Skip to content

Commit

Permalink
refactor: fix TypeError in Postgre/Builder.php
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kenjis committed Nov 29, 2023
1 parent 5d52f33 commit 9a4da43
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions system/Database/Postgre/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand Down

0 comments on commit 9a4da43

Please sign in to comment.