Skip to content

Commit

Permalink
Unit test bugs fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
msyk committed May 23, 2024
1 parent bfc435e commit 090edfa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions spec/INTER-Mediator-UnitTest/DB-PDO/DB_PDO_Test_Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion src/php/DB/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
1 change: 1 addition & 0 deletions src/php/DB/Support/DB_PDO_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace INTERMediator\DB\Support;

use Exception;
use INTERMediator\DB\Logger;
use INTERMediator\DB\PDO;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/php/DB/Support/DB_PDO_SQLite_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function dateResetForNotNull(): string
*/
protected function checkNullableField(string $info): bool
{
return $info === 0;
return intval($info) === 0;
}

/**
Expand Down

0 comments on commit 090edfa

Please sign in to comment.