1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-03 20:57:36 +02:00

getInsertId() is be able to return negative ID's [Closes #336]

This commit is contained in:
David Grudl
2019-09-18 10:33:06 +02:00
parent a2afac80f2
commit c1640c5e7b
3 changed files with 3 additions and 3 deletions

View File

@@ -315,7 +315,7 @@ class Connection implements IConnection
$this->connect();
}
$id = $this->driver->getInsertId($sequence);
if ($id < 1) {
if ($id === null) {
throw new Exception('Cannot retrieve last generated ID.');
}
return $id;

View File

@@ -199,7 +199,7 @@ class MySqliDriver implements Dibi\Driver
*/
public function getInsertId(?string $sequence): ?int
{
return $this->connection->insert_id;
return $this->connection->insert_id ?: null;
}

View File

@@ -139,7 +139,7 @@ class SqliteDriver implements Dibi\Driver
*/
public function getInsertId(?string $sequence): ?int
{
return $this->connection->lastInsertRowID();
return $this->connection->lastInsertRowID() ?: null;
}