Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Try to workaround oracles primary key
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and come-nc committed Apr 24, 2025
commit 2fb1b7cd74d16f72ae4147e7602c8bbefaec8614
7 changes: 7 additions & 0 deletions lib/private/DB/AdapterOCI8.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public function fixupStatement($statement) {
$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;
}
}
38 changes: 38 additions & 0 deletions lib/private/DB/OracleConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,4 +89,39 @@ public function tableExists($table) {
$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];
}
}