Skip to content

Rename getLastInsertID() method in ConnectionInterface to getLastInsertId() #965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
- Enh #822: Refactor data readers (@Tigrov)
- Enh #963: Make `Query::andHaving()` similar to `Query::andWhere()` (@Tigrov)
- New #964: Add `QueryBuilderInterface::replacePlaceholders()` method (@Tigrov)
- Enh #879: Rename `getLastInsertID()` method in `ConnectionInterface` to `getLastInsertId()` (@vjik)

## 1.3.0 March 21, 2024

Expand Down
2 changes: 1 addition & 1 deletion src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getDriverName(): string;
*
* @return string The row ID of the last row inserted, or the last value retrieved from the sequence object.
*/
public function getLastInsertID(?string $sequenceName = null): string;
public function getLastInsertId(?string $sequenceName = null): string;

/**
* Returns the query builder for the current DB connection.
Expand Down
4 changes: 2 additions & 2 deletions src/Debug/ConnectionInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public function getColumnFactory(): ColumnFactoryInterface
return $this->connection->getColumnFactory();
}

public function getLastInsertID(?string $sequenceName = null): string
public function getLastInsertId(?string $sequenceName = null): string
{
return $this->connection->getLastInsertID($sequenceName);
return $this->connection->getLastInsertId($sequenceName);
}

public function getQueryBuilder(): QueryBuilderInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Pdo/AbstractPdoConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function getPdo(): PDO|null
return $this->pdo;
}

public function getLastInsertID(?string $sequenceName = null): string
public function getLastInsertId(?string $sequenceName = null): string
{
if ($this->pdo !== null) {
return $this->pdo->lastInsertID($sequenceName ?? null);
Expand Down
8 changes: 4 additions & 4 deletions tests/Common/CommonCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,9 @@ public function testsInsertQueryAsColumnValue(): void
$command->insert('{{order}}', ['customer_id' => 1, 'created_at' => $time, 'total' => 42])->execute();

if ($db->getDriverName() === 'pgsql') {
$orderId = $db->getLastInsertID('public.order_id_seq');
$orderId = $db->getLastInsertId('public.order_id_seq');
} else {
$orderId = $db->getLastInsertID();
$orderId = $db->getLastInsertId();
}

$columnValueQuery = (new Query($db))->select('{{created_at}}')->from('{{order}}')->where(['id' => $orderId]);
Expand Down Expand Up @@ -1630,9 +1630,9 @@ public function testNoTablenameReplacement(): void
)->execute();

if ($db->getDriverName() === 'pgsql') {
$customerId = $db->getLastInsertID('public.customer_id_seq');
$customerId = $db->getLastInsertId('public.customer_id_seq');
} else {
$customerId = $db->getLastInsertID();
$customerId = $db->getLastInsertId();
}

$customer = $command->setSql(
Expand Down
2 changes: 1 addition & 1 deletion tests/Common/CommonPdoConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function testTransactionRollbackTransactionOnLevel(): void
'createCommand',
'close',
'getDriverName',
'getLastInsertID',
'getLastInsertId',
'getQueryBuilder',
'getQuoter',
'getSchema',
Expand Down
2 changes: 1 addition & 1 deletion tests/Db/Driver/PDO/PdoConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testGetLastInsertID(): void
$this->expectException(InvalidCallException::class);
$this->expectExceptionMessage('DB Connection is not active.');

$db->getLastInsertID();
$db->getLastInsertId();
}

public function testQuoteValueString(): void
Expand Down
8 changes: 0 additions & 8 deletions tests/Support/Stub/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ public function findUniqueIndexes(TableSchemaInterface $table): array
throw new NotSupportedException(__METHOD__ . ' is not supported by this DBMS.');
}

/**
* @throws NotSupportedException
*/
public function getLastInsertID(?string $sequenceName = null): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by this DBMS.');
}

protected function getCacheKey(string $name): array
{
return [];
Expand Down
Loading