OracleConnection.php 3.1 KB

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