From 13fb22385b44095ee59f1f66073f1d981341f67d Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Tue, 22 Mar 2022 20:17:30 +0900 Subject: [PATCH] Fix DB\IO return for unset pk name to be always string Add Test for SELECT typ query and num rows type with dbReturn --- 4dev/tests/CoreLibsDBIOTest.php | 17 +++++++++++++++++ www/lib/CoreLibs/DB/IO.php | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/4dev/tests/CoreLibsDBIOTest.php b/4dev/tests/CoreLibsDBIOTest.php index 0994c5bf..50cd0c46 100644 --- a/4dev/tests/CoreLibsDBIOTest.php +++ b/4dev/tests/CoreLibsDBIOTest.php @@ -3384,6 +3384,23 @@ final class CoreLibsDBIOTest extends TestCase ); } + // if this is a select query, db dbReturn, dbReturnRow, dbReturnArray too + if (preg_match("/^(select|show|with) /i", $query)) { + $res = $db->dbReturn($query); + $this->assertEquals( + $expected_rows, + $db->dbGetNumRows() + ); + $this->assertEquals( + $expected_cols, + $db->dbGetNumFields() + ); + $this->assertEquals( + $expected_col_names, + $db->dbGetFieldNames() + ); + } + // reset all data $db->dbExec("TRUNCATE table_with_primary_key"); $db->dbExec("TRUNCATE table_without_primary_key"); diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index c4254575..974b8ded 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -2874,7 +2874,7 @@ class IO */ public function dbGetInsertPKName(): string { - return $this->insert_id_pk_name; + return (string)$this->insert_id_pk_name; } /**