OracleConnection.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\DB;
  8. class OracleConnection extends Connection {
  9. /**
  10. * Quote the keys of the array
  11. * @param array<string, string> $data
  12. * @return array<string, string>
  13. */
  14. private function quoteKeys(array $data) {
  15. $return = [];
  16. $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter();
  17. foreach ($data as $key => $value) {
  18. if ($key[0] !== $c) {
  19. $return[$this->quoteIdentifier($key)] = $value;
  20. } else {
  21. $return[$key] = $value;
  22. }
  23. }
  24. return $return;
  25. }
  26. /**
  27. * {@inheritDoc}
  28. */
  29. public function insert($table, array $data, array $types = []) {
  30. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  31. $table = $this->quoteIdentifier($table);
  32. }
  33. $data = $this->quoteKeys($data);
  34. return parent::insert($table, $data, $types);
  35. }
  36. /**
  37. * {@inheritDoc}
  38. */
  39. public function update($table, array $data, array $criteria, array $types = []) {
  40. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  41. $table = $this->quoteIdentifier($table);
  42. }
  43. $data = $this->quoteKeys($data);
  44. $criteria = $this->quoteKeys($criteria);
  45. return parent::update($table, $data, $criteria, $types);
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. public function delete($table, array $criteria, array $types = []) {
  51. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  52. $table = $this->quoteIdentifier($table);
  53. }
  54. $criteria = $this->quoteKeys($criteria);
  55. return parent::delete($table, $criteria);
  56. }
  57. /**
  58. * Drop a table from the database if it exists
  59. *
  60. * @param string $table table name without the prefix
  61. */
  62. public function dropTable($table) {
  63. $table = $this->tablePrefix . trim($table);
  64. $table = $this->quoteIdentifier($table);
  65. $schema = $this->getSchemaManager();
  66. if ($schema->tablesExist([$table])) {
  67. $schema->dropTable($table);
  68. }
  69. }
  70. /**
  71. * Check if a table exists
  72. *
  73. * @param string $table table name without the prefix
  74. * @return bool
  75. */
  76. public function tableExists($table) {
  77. $table = $this->tablePrefix . trim($table);
  78. $table = $this->quoteIdentifier($table);
  79. $schema = $this->getSchemaManager();
  80. return $schema->tablesExist([$table]);
  81. }
  82. }