From 090edfad43e435282472fc3d34425df28785c5ef Mon Sep 17 00:00:00 2001 From: Masayuki Nii Date: Thu, 23 May 2024 10:15:06 +0900 Subject: [PATCH] Unit test bugs fixed. --- spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_Common.php | 3 +++ src/php/DB/PDO.php | 2 +- src/php/DB/Support/DB_PDO_Handler.php | 1 + src/php/DB/Support/DB_PDO_SQLite_Handler.php | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_Common.php b/spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_Common.php index f1cf16e3b..cd7f8cb36 100755 --- a/spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_Common.php +++ b/spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_Common.php @@ -216,6 +216,9 @@ public function testCreateRecord2() $this->db_proxy->requireUpdatedRecord(true); $newKeyValue = $this->db_proxy->createInDB(); + // echo " Returns {$newKeyValue}\n"; + //var_export($this->db_proxy->logger->getDebugMessages()); + $this->assertTrue($newKeyValue == -999, "Record wasn't created."); $createdRecord = $this->db_proxy->getUpdatedRecord(); $this->assertNull($createdRecord, "Record wasn't created."); diff --git a/src/php/DB/PDO.php b/src/php/DB/PDO.php index 0c49b6bad..19dfac880 100644 --- a/src/php/DB/PDO.php +++ b/src/php/DB/PDO.php @@ -725,7 +725,7 @@ public function createInDB(bool $isReplace = false): ?string } $seqObject = $tableInfo['sequence'] ?? "{$this->dbSettings->getEntityForUpdate()}_{$keyField}_seq"; $lastKeyValue = $this->handler->lastInsertIdAlt($seqObject, $tableNameRow); // $this->link->lastInsertId($seqObject); - if (/* $isReplace && */ $lastKeyValue === 0) { // lastInsertId returns 0 after replace command. + if (/* $isReplace && */ !$lastKeyValue) { // lastInsertId returns 0 after replace command. // Moreover, about MySQL, it returns 0 with the key field without AUTO_INCREMENT. $lastKeyValue = -999; // This means kind of error, so avoid to set non-zero value. } diff --git a/src/php/DB/Support/DB_PDO_Handler.php b/src/php/DB/Support/DB_PDO_Handler.php index f9261666c..54e7d43fe 100644 --- a/src/php/DB/Support/DB_PDO_Handler.php +++ b/src/php/DB/Support/DB_PDO_Handler.php @@ -17,6 +17,7 @@ namespace INTERMediator\DB\Support; use Exception; +use INTERMediator\DB\Logger; use INTERMediator\DB\PDO; /** diff --git a/src/php/DB/Support/DB_PDO_SQLite_Handler.php b/src/php/DB/Support/DB_PDO_SQLite_Handler.php index 5160708d6..2b8605db7 100644 --- a/src/php/DB/Support/DB_PDO_SQLite_Handler.php +++ b/src/php/DB/Support/DB_PDO_SQLite_Handler.php @@ -149,7 +149,7 @@ public function dateResetForNotNull(): string */ protected function checkNullableField(string $info): bool { - return $info === 0; + return intval($info) === 0; } /**