You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.2 KiB

3 years ago
  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 Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.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. */
  32. private function quoteKeys(array $data) {
  33. $return = [];
  34. $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter();
  35. foreach ($data as $key => $value) {
  36. if ($key[0] !== $c) {
  37. $return[$this->quoteIdentifier($key)] = $value;
  38. } else {
  39. $return[$key] = $value;
  40. }
  41. }
  42. return $return;
  43. }
  44. /**
  45. * {@inheritDoc}
  46. */
  47. public function insert($tableExpression, array $data, array $types = []) {
  48. if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  49. $tableExpression = $this->quoteIdentifier($tableExpression);
  50. }
  51. $data = $this->quoteKeys($data);
  52. return parent::insert($tableExpression, $data, $types);
  53. }
  54. /**
  55. * {@inheritDoc}
  56. */
  57. public function update($tableExpression, array $data, array $identifier, array $types = []) {
  58. if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  59. $tableExpression = $this->quoteIdentifier($tableExpression);
  60. }
  61. $data = $this->quoteKeys($data);
  62. $identifier = $this->quoteKeys($identifier);
  63. return parent::update($tableExpression, $data, $identifier, $types);
  64. }
  65. /**
  66. * {@inheritDoc}
  67. */
  68. public function delete($tableExpression, array $identifier, array $types = []) {
  69. if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  70. $tableExpression = $this->quoteIdentifier($tableExpression);
  71. }
  72. $identifier = $this->quoteKeys($identifier);
  73. return parent::delete($tableExpression, $identifier);
  74. }
  75. /**
  76. * Drop a table from the database if it exists
  77. *
  78. * @param string $table table name without the prefix
  79. */
  80. public function dropTable($table) {
  81. $table = $this->tablePrefix . trim($table);
  82. $table = $this->quoteIdentifier($table);
  83. $schema = $this->getSchemaManager();
  84. if ($schema->tablesExist([$table])) {
  85. $schema->dropTable($table);
  86. }
  87. }
  88. /**
  89. * Check if a table exists
  90. *
  91. * @param string $table table name without the prefix
  92. * @return bool
  93. */
  94. public function tableExists($table) {
  95. $table = $this->tablePrefix . trim($table);
  96. $table = $this->quoteIdentifier($table);
  97. $schema = $this->getSchemaManager();
  98. return $schema->tablesExist([$table]);
  99. }
  100. }