OracleConnection.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OC\DB;
  28. class OracleConnection extends Connection {
  29. /**
  30. * Quote the keys of the array
  31. * @param array<string, string> $data
  32. * @return array<string, string>
  33. */
  34. private function quoteKeys(array $data) {
  35. $return = [];
  36. $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter();
  37. foreach ($data as $key => $value) {
  38. if ($key[0] !== $c) {
  39. $return[$this->quoteIdentifier($key)] = $value;
  40. } else {
  41. $return[$key] = $value;
  42. }
  43. }
  44. return $return;
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. public function insert($table, array $data, array $types = []) {
  50. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  51. $table = $this->quoteIdentifier($table);
  52. }
  53. $data = $this->quoteKeys($data);
  54. return parent::insert($table, $data, $types);
  55. }
  56. /**
  57. * {@inheritDoc}
  58. */
  59. public function update($table, array $data, array $criteria, array $types = []) {
  60. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  61. $table = $this->quoteIdentifier($table);
  62. }
  63. $data = $this->quoteKeys($data);
  64. $criteria = $this->quoteKeys($criteria);
  65. return parent::update($table, $data, $criteria, $types);
  66. }
  67. /**
  68. * {@inheritDoc}
  69. */
  70. public function delete($table, array $criteria, array $types = []) {
  71. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  72. $table = $this->quoteIdentifier($table);
  73. }
  74. $criteria = $this->quoteKeys($criteria);
  75. return parent::delete($table, $criteria);
  76. }
  77. /**
  78. * Drop a table from the database if it exists
  79. *
  80. * @param string $table table name without the prefix
  81. */
  82. public function dropTable($table) {
  83. $table = $this->tablePrefix . trim($table);
  84. $table = $this->quoteIdentifier($table);
  85. $schema = $this->getSchemaManager();
  86. if ($schema->tablesExist([$table])) {
  87. $schema->dropTable($table);
  88. }
  89. }
  90. /**
  91. * Check if a table exists
  92. *
  93. * @param string $table table name without the prefix
  94. * @return bool
  95. */
  96. public function tableExists($table) {
  97. $table = $this->tablePrefix . trim($table);
  98. $table = $this->quoteIdentifier($table);
  99. $schema = $this->getSchemaManager();
  100. return $schema->tablesExist([$table]);
  101. }
  102. }