diff options
author | Joas Schilling <coding@schilljs.com> | 2025-05-08 09:26:59 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2025-05-08 09:26:59 +0200 |
commit | 092794a9d4421249fdd6e3ded29fb538db848b6a (patch) | |
tree | fcf680a281ba44e2b252467ccd2dce8abc3fe829 | |
parent | f8cb51da8aa66d7107a924e54ba349946aa08914 (diff) | |
download | nextcloud-server-bugfix/noid/last-insert-id-when-reconnecting.tar.gz nextcloud-server-bugfix/noid/last-insert-id-when-reconnecting.zip |
fixup! fix(db): Store last insert id before reconnectbugfix/noid/last-insert-id-when-reconnecting
-rw-r--r-- | lib/private/DB/AdapterOCI8.php | 2 | ||||
-rw-r--r-- | lib/private/DB/AdapterPgSql.php | 2 | ||||
-rw-r--r-- | lib/private/DB/Connection.php | 18 |
3 files changed, 12 insertions, 10 deletions
diff --git a/lib/private/DB/AdapterOCI8.php b/lib/private/DB/AdapterOCI8.php index 0a509090bca..4d7eb6d08db 100644 --- a/lib/private/DB/AdapterOCI8.php +++ b/lib/private/DB/AdapterOCI8.php @@ -8,7 +8,7 @@ namespace OC\DB; class AdapterOCI8 extends Adapter { - public function lastInsertId($table) { + public function lastInsertId($table, bool $allowRetry = true) { if (is_null($table)) { throw new \InvalidArgumentException('Oracle requires a table name to be passed into lastInsertId()'); } diff --git a/lib/private/DB/AdapterPgSql.php b/lib/private/DB/AdapterPgSql.php index db48c81c2c5..8662d73b93f 100644 --- a/lib/private/DB/AdapterPgSql.php +++ b/lib/private/DB/AdapterPgSql.php @@ -9,7 +9,7 @@ namespace OC\DB; class AdapterPgSql extends Adapter { - public function lastInsertId($table) { + public function lastInsertId($table, bool $allowRetry = true) { $result = $this->conn->executeQuery('SELECT lastval()'); $val = $result->fetchOne(); $result->free(); diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 0e7463d61e7..2a9e71f9cb4 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -909,14 +909,16 @@ class Connection extends PrimaryReadReplicaConnection { return; } - /** - * Before reconnecting we save the lastInsertId, so that if the reconnect - * happens between the INSERT executeStatement() and the getLastInsertId call - * we are able to return the correct result after all. - */ - $this->disableReconnect = true; - $this->lastInsertId = parent::lastInsertId(); - $this->disableReconnect = false; + if ($this->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) { + /** + * Before reconnecting we save the lastInsertId, so that if the reconnect + * happens between the INSERT executeStatement() and the getLastInsertId call + * we are able to return the correct result after all. + */ + $this->disableReconnect = true; + $this->lastInsertId = parent::lastInsertId(); + $this->disableReconnect = false; + } try { $this->_conn->query($this->getDriver()->getDatabasePlatform()->getDummySelectSQL()); |