You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand that using negative integers for PK's is generally considered bad practice, but that doesn't change the reality that our company's database has dozens of tables that use them. We no longer allow new schemas to have negative ID's, but we still have to support the legacy tables. We love everything about Dibi, but it's been very frustrating not being able to use getInsertId() for most of our queries because the code was written explicitly to throw an exception when encountering a negative ID (e.g. see: src/Dibi/Connection.php:318).
/**
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
* @throws Exception
*/
public function getInsertId(string $sequence = null): int
{
if (!$this->driver) {
$this->connect();
}
$id = $this->driver->getInsertId($sequence);
if ($id < 1) {
throw new Exception('Cannot retrieve last generated ID.');
}
return $id;
}
At the very least, it would be great to have a configurable option allowing negative ID's.
I'd be happy to work on this feature myself if approved.
The text was updated successfully, but these errors were encountered:
I understand that using negative integers for PK's is generally considered bad practice, but that doesn't change the reality that our company's database has dozens of tables that use them. We no longer allow new schemas to have negative ID's, but we still have to support the legacy tables. We love everything about Dibi, but it's been very frustrating not being able to use getInsertId() for most of our queries because the code was written explicitly to throw an exception when encountering a negative ID (e.g. see: src/Dibi/Connection.php:318).
At the very least, it would be great to have a configurable option allowing negative ID's.
I'd be happy to work on this feature myself if approved.
The text was updated successfully, but these errors were encountered: