Problem/Motivation
From #3137883-91: Deprecate passing a StatementInterface object to Connection::query
\Drupal\Core\Database\Driver\pgsql\Upsert::execute() should return the last insert ID but atm it returns TRUE!
From the Upsert constructor...
public function __construct(Connection $connection, $table, array $options = []) {
$options['return'] = Database::RETURN_AFFECTED;
parent::__construct($connection, $options);
$this->table = $table;
}
So all implementations should return the affected rows. This kinda makes sense because the last insert ID is useless - in order to an upsert you need to have all the IDs yourself anyway.
One thing that is tricky if we determine that we should fix it is that MySQL does something nonsensical - see https://dev.mysql.com/doc/c-api/8.0/en/mysql-affected-rows.html ... an updated row counts double???
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3185400
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3185400-test-upsert-return
changes, plain diff MR !676
Comments
Comment #2
mondrakeComment #3
alexpottComment #4
alexpottComment #5
alexpottLet's try that again with an updated codebase...
Comment #6
alexpottComment #7
daffie commentedThe patch looks good to me. Just 2 minor nitpicks:
We are not using the variable $return_value anywhere else. Can we do it on a single line. like:
The same for these 2 lines.
Comment #8
alexpottI'm not sure about #7. I like having the bit where the upsert is executed separate from the assertion on the return value for two reasons...
$this->assertSame($this->connection->driver() === 'mysql' ? 3 : 2, $upsert->execute());Also this is a test so there's no benefit in not assigning a variable.
Comment #9
daffie commentedThe explanation of @alexpott in comment #8 is good enough for me.
The testbot is failing for MariaDB 10.2.7.
Comment #11
mondrakeI think this was superceded by #3211866: Upsert::execute() return values are inconsistent, but not sure if there are some tests that would be worth having from the patch here
Comment #13
mondrakeThis now just adds a new test for Upsert, after #3211866: Upsert::execute() return values are inconsistent.
Comment #14
mondrakeComment #15
daffie commentedThis issue is no longer a bugfix, lets change it to a task.
A small improvement in testing.
It all looks good to me.
Comment #16
catchNeeds a rebase.
Comment #17
mondrakeDone, just pressed Rebase in Gitlab and there were no conflicts requiring manual rebase.
Comment #20
catchCommitted/pushed to 9.3.x and cherry-picked to 9.2.x, thanks!