OracleConnection.php 2.6 KB

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