diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index b1a5e71f83..bece4b3ae1 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -8,6 +8,7 @@ Yii Framework 2 Change Log - Bug #7707: client-side `trim` validator now passes the trimmed value to subsequent validators (nkovacs) - Bug #8322: `yii\behaviors\TimestampBehavior::touch()` now throws an exception if owner is new record (klimov-paul) - Bug #8451: `yii\i18n\Formatter` did not allow negative unix timestamps as input for date formatting (cebe) +- Bug #8483: sequence name in `Schema::getLastInsertId()` was not properly quoted (nineinchnick) - Bug #8506: Cleaning of output buffer in `Widget::run()` conflicts with `Pjax` widget which did the cleanup itself (cebe, joester89) - Bug: Fixed string comparison in `BaseActiveRecord::unlink()` which may result in wrong comparison result for hash valued primary keys starting with `0e` (cebe) - Enh #7169: `yii\widgets\ActiveField` now uses corresponding methods for default parts rendering (klimov-paul) diff --git a/framework/db/Schema.php b/framework/db/Schema.php index 2da3f98999..c45a13b9c9 100644 --- a/framework/db/Schema.php +++ b/framework/db/Schema.php @@ -348,7 +348,7 @@ abstract class Schema extends Object public function getLastInsertID($sequenceName = '') { if ($this->db->isActive) { - return $this->db->pdo->lastInsertId($sequenceName === '' ? null : $this->quoteSimpleTableName($sequenceName)); + return $this->db->pdo->lastInsertId($sequenceName === '' ? null : $this->quoteTableName($sequenceName)); } else { throw new InvalidCallException('DB Connection is not active.'); } diff --git a/tests/data/postgres.sql b/tests/data/postgres.sql index 3973ed3c52..e5b201f51c 100644 --- a/tests/data/postgres.sql +++ b/tests/data/postgres.sql @@ -37,6 +37,11 @@ CREATE TABLE "profile" ( description varchar(128) NOT NULL ); +CREATE TABLE "schema1"."profile" ( + id serial not null primary key, + description varchar(128) NOT NULL +); + CREATE TABLE "customer" ( id serial not null primary key, email varchar(128) NOT NULL, @@ -151,6 +156,9 @@ INSERT INTO "animal" (type) VALUES ('yiiunit\data\ar\Dog'); INSERT INTO "profile" (description) VALUES ('profile customer 1'); INSERT INTO "profile" (description) VALUES ('profile customer 3'); +INSERT INTO "schema1"."profile" (description) VALUES ('profile customer 1'); +INSERT INTO "schema1"."profile" (description) VALUES ('profile customer 3'); + INSERT INTO "customer" (email, name, address, status, bool_status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, true, 1); INSERT INTO "customer" (email, name, address, status, bool_status) VALUES ('user2@example.com', 'user2', 'address2', 1, true); INSERT INTO "customer" (email, name, address, status, bool_status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, false, 2); diff --git a/tests/framework/db/pgsql/PostgreSQLCommandTest.php b/tests/framework/db/pgsql/PostgreSQLCommandTest.php index 22e0beb487..5a15185393 100644 --- a/tests/framework/db/pgsql/PostgreSQLCommandTest.php +++ b/tests/framework/db/pgsql/PostgreSQLCommandTest.php @@ -62,6 +62,11 @@ class PostgreSQLCommandTest extends CommandTest $sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')'; $command = $db->createCommand($sql); $command->execute(); - $this->assertEquals(3, $db->getSchema()->getLastInsertID('profile_id_seq')); + $this->assertEquals(3, $db->getSchema()->getLastInsertID('public.profile_id_seq')); + + $sql = 'INSERT INTO {{schema1.profile}}([[description]]) VALUES (\'non duplicate\')'; + $command = $db->createCommand($sql); + $command->execute(); + $this->assertEquals(3, $db->getSchema()->getLastInsertID('schema1.profile_id_seq')); } } \ No newline at end of file