oracleconnection.php 2.6 KB

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