2013-09-01 06:35:20 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2013-09-01 06:35:20 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-09-01 06:35:20 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\DB;
|
|
|
|
|
|
|
|
|
|
class OracleConnection extends Connection {
|
|
|
|
|
/**
|
|
|
|
|
* Quote the keys of the array
|
2022-12-01 07:28:11 -05:00
|
|
|
* @param array<string, string> $data
|
|
|
|
|
* @return array<string, string>
|
2013-09-01 06:35:20 -04:00
|
|
|
*/
|
|
|
|
|
private function quoteKeys(array $data) {
|
2017-06-01 10:56:34 -04:00
|
|
|
$return = [];
|
|
|
|
|
$c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter();
|
2020-04-10 08:19:56 -04:00
|
|
|
foreach ($data as $key => $value) {
|
2017-06-01 10:56:34 -04:00
|
|
|
if ($key[0] !== $c) {
|
|
|
|
|
$return[$this->quoteIdentifier($key)] = $value;
|
|
|
|
|
} else {
|
|
|
|
|
$return[$key] = $value;
|
|
|
|
|
}
|
2013-09-01 06:35:20 -04:00
|
|
|
}
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-17 12:30:17 -05:00
|
|
|
/**
|
2013-09-18 10:38:59 -04:00
|
|
|
* {@inheritDoc}
|
2013-09-01 06:35:20 -04:00
|
|
|
*/
|
2020-10-29 04:31:37 -04:00
|
|
|
public function insert($table, array $data, array $types = []) {
|
|
|
|
|
if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
|
|
|
|
|
$table = $this->quoteIdentifier($table);
|
2017-06-01 10:56:34 -04:00
|
|
|
}
|
2013-09-01 06:35:20 -04:00
|
|
|
$data = $this->quoteKeys($data);
|
2020-10-29 04:31:37 -04:00
|
|
|
return parent::insert($table, $data, $types);
|
2013-09-01 06:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-17 12:30:17 -05:00
|
|
|
/**
|
2013-09-18 10:38:59 -04:00
|
|
|
* {@inheritDoc}
|
2013-09-01 06:35:20 -04:00
|
|
|
*/
|
2020-10-29 04:31:37 -04:00
|
|
|
public function update($table, array $data, array $criteria, array $types = []) {
|
|
|
|
|
if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
|
|
|
|
|
$table = $this->quoteIdentifier($table);
|
2017-06-01 10:56:34 -04:00
|
|
|
}
|
2013-09-01 06:35:20 -04:00
|
|
|
$data = $this->quoteKeys($data);
|
2020-10-29 04:31:37 -04:00
|
|
|
$criteria = $this->quoteKeys($criteria);
|
|
|
|
|
return parent::update($table, $data, $criteria, $types);
|
2013-09-01 06:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-17 12:30:17 -05:00
|
|
|
/**
|
2013-09-18 10:38:59 -04:00
|
|
|
* {@inheritDoc}
|
2013-09-01 06:35:20 -04:00
|
|
|
*/
|
2020-10-29 04:31:37 -04:00
|
|
|
public function delete($table, array $criteria, array $types = []) {
|
|
|
|
|
if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
|
|
|
|
|
$table = $this->quoteIdentifier($table);
|
2017-06-01 10:56:34 -04:00
|
|
|
}
|
2020-10-29 04:31:37 -04:00
|
|
|
$criteria = $this->quoteKeys($criteria);
|
|
|
|
|
return parent::delete($table, $criteria);
|
2013-09-01 06:35:20 -04:00
|
|
|
}
|
2014-12-09 11:26:39 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Drop a table from the database if it exists
|
|
|
|
|
*
|
|
|
|
|
* @param string $table table name without the prefix
|
|
|
|
|
*/
|
|
|
|
|
public function dropTable($table) {
|
|
|
|
|
$table = $this->tablePrefix . trim($table);
|
|
|
|
|
$table = $this->quoteIdentifier($table);
|
2024-06-28 09:55:02 -04:00
|
|
|
$schema = $this->createSchemaManager();
|
2020-04-10 08:19:56 -04:00
|
|
|
if ($schema->tablesExist([$table])) {
|
2014-12-09 11:26:39 -05:00
|
|
|
$schema->dropTable($table);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if a table exists
|
|
|
|
|
*
|
|
|
|
|
* @param string $table table name without the prefix
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2020-04-09 07:53:40 -04:00
|
|
|
public function tableExists($table) {
|
2014-12-09 11:26:39 -05:00
|
|
|
$table = $this->tablePrefix . trim($table);
|
|
|
|
|
$table = $this->quoteIdentifier($table);
|
2024-06-28 09:55:02 -04:00
|
|
|
$schema = $this->createSchemaManager();
|
2020-03-26 04:30:18 -04:00
|
|
|
return $schema->tablesExist([$table]);
|
2014-12-09 11:26:39 -05:00
|
|
|
}
|
2013-09-01 06:35:20 -04:00
|
|
|
}
|