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.

OracleConnection.php 3.1KB

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