mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 09:42:09 -04:00
Try to workaround oracles primary key
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
a20d9c85c9
commit
2257ecb36b
2 changed files with 45 additions and 0 deletions
|
|
@ -26,6 +26,13 @@ class AdapterOCI8 extends Adapter {
|
|||
$statement = str_replace('`', '"', $statement);
|
||||
$statement = str_ireplace('NOW()', 'CURRENT_TIMESTAMP', $statement);
|
||||
$statement = str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement);
|
||||
|
||||
$statement = preg_replace(
|
||||
'/^INSERT INTO (.*) VALUES (.*) INTO (.*)$/',
|
||||
'INSERT INTO ${1} VALUES ${2} RETURNING pk_id INTO ${3}',
|
||||
$statement
|
||||
);
|
||||
|
||||
return $statement;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
namespace OC\DB;
|
||||
|
||||
class OracleConnection extends Connection {
|
||||
/** @var array<string, int> */
|
||||
protected array $lastInsertId = [];
|
||||
|
||||
/**
|
||||
* Quote the keys of the array
|
||||
* @param array<string, string> $data
|
||||
|
|
@ -75,4 +78,39 @@ class OracleConnection extends Connection {
|
|||
$schema = $this->createSchemaManager();
|
||||
return $schema->tablesExist([$table]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
|
||||
* and returns the number of affected rows.
|
||||
*
|
||||
* This method supports PDO binding types as well as DBAL mapping types.
|
||||
*
|
||||
* @param string $sql The SQL query.
|
||||
* @param array $params The query parameters.
|
||||
* @param array $types The parameter types.
|
||||
*
|
||||
* @return int The number of affected rows, if the result is bigger than PHP_INT_MAX, PHP_INT_MAX is returned
|
||||
*
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
*/
|
||||
public function executeStatement($sql, array $params = [], array $types = []): int {
|
||||
$returned = parent::executeStatement($sql, $params, $types);
|
||||
|
||||
var_dump($sql);
|
||||
if (preg_match('/^INSERT INTO (.*) VALUES (.*) INTO (.*)$/', $sql, $matches)) {
|
||||
var_dump($returned);
|
||||
$this->lastInsertId[$matches[1]] = $returned;
|
||||
var_dump($this->lastInsertId);
|
||||
$returned = 1;
|
||||
}
|
||||
|
||||
return $returned;
|
||||
}
|
||||
|
||||
public function lastInsertId($name = null): int {
|
||||
if ($name) {
|
||||
$name = $this->replaceTablePrefix($name);
|
||||
}
|
||||
return $this->lastInsertId[$name];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue