OracleConnection.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. */
  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($table, array $data, array $types = []) {
  48. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  49. $table = $this->quoteIdentifier($table);
  50. }
  51. $data = $this->quoteKeys($data);
  52. return parent::insert($table, $data, $types);
  53. }
  54. /**
  55. * {@inheritDoc}
  56. */
  57. public function update($table, array $data, array $criteria, array $types = []) {
  58. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  59. $table = $this->quoteIdentifier($table);
  60. }
  61. $data = $this->quoteKeys($data);
  62. $criteria = $this->quoteKeys($criteria);
  63. return parent::update($table, $data, $criteria, $types);
  64. }
  65. /**
  66. * {@inheritDoc}
  67. */
  68. public function delete($table, array $criteria, array $types = []) {
  69. if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) {
  70. $table = $this->quoteIdentifier($table);
  71. }
  72. $criteria = $this->quoteKeys($criteria);
  73. return parent::delete($table, $criteria);
  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. }