connectionwrapper.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Thomas Müller <deepdiver@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\DB;
  9. class ConnectionWrapper implements \OCP\IDBConnection {
  10. private $connection;
  11. public function __construct(Connection $conn) {
  12. $this->connection = $conn;
  13. }
  14. /**
  15. * Used to the owncloud database access away
  16. * @param string $sql the sql query with ? placeholder for params
  17. * @param int $limit the maximum number of rows
  18. * @param int $offset from which row we want to start
  19. * @return \Doctrine\DBAL\Driver\Statement The prepared statement.
  20. */
  21. public function prepare($sql, $limit = null, $offset = null)
  22. {
  23. return $this->connection->prepare($sql, $limit, $offset);
  24. }
  25. /**
  26. * Used to get the id of the just inserted element
  27. * @param string $tableName the name of the table where we inserted the item
  28. * @return int the id of the inserted element
  29. */
  30. public function lastInsertId($table = null)
  31. {
  32. return $this->connection->lastInsertId($table);
  33. }
  34. /**
  35. * Insert a row if a matching row doesn't exists.
  36. * @param string The table name (will replace *PREFIX*) to perform the replace on.
  37. * @param array
  38. *
  39. * The input array if in the form:
  40. *
  41. * array ( 'id' => array ( 'value' => 6,
  42. * 'key' => true
  43. * ),
  44. * 'name' => array ('value' => 'Stoyan'),
  45. * 'family' => array ('value' => 'Stefanov'),
  46. * 'birth_date' => array ('value' => '1975-06-20')
  47. * );
  48. * @return bool
  49. *
  50. */
  51. public function insertIfNotExist($table, $input)
  52. {
  53. return $this->connection->insertIfNotExist($table, $input);
  54. }
  55. /**
  56. * Start a transaction
  57. * @return bool TRUE on success or FALSE on failure
  58. */
  59. public function beginTransaction()
  60. {
  61. return $this->connection->beginTransaction();
  62. }
  63. /**
  64. * Commit the database changes done during a transaction that is in progress
  65. * @return bool TRUE on success or FALSE on failure
  66. */
  67. public function commit()
  68. {
  69. return $this->connection->commit();
  70. }
  71. /**
  72. * Rollback the database changes done during a transaction that is in progress
  73. * @return bool TRUE on success or FALSE on failure
  74. */
  75. public function rollBack()
  76. {
  77. return $this->connection->rollBack();
  78. }
  79. /**
  80. * Gets the error code and message as a string for logging
  81. * @return string
  82. */
  83. public function getError()
  84. {
  85. return $this->connection->getError();
  86. }
  87. }