PageRenderTime 25ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/Db/lib/Horde/Db/Adapter.php

https://github.com/imr/horde
PHP | 314 lines | 31 code | 32 blank | 251 comment | 0 complexity | 17498494170e689a0aa0fc65b04edaa5 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2007 Maintainable Software, LLC
  4. * Copyright 2008-2014 Horde LLC (http://www.horde.org/)
  5. *
  6. * @author Mike Naberezny <mike@maintainable.com>
  7. * @author Derek DeVries <derek@maintainable.com>
  8. * @author Chuck Hagenbuch <chuck@horde.org>
  9. * @license http://www.horde.org/licenses/bsd
  10. * @category Horde
  11. * @package Db
  12. * @subpackage Adapter
  13. */
  14. /**
  15. * @author Mike Naberezny <mike@maintainable.com>
  16. * @author Derek DeVries <derek@maintainable.com>
  17. * @author Chuck Hagenbuch <chuck@horde.org>
  18. * @license http://www.horde.org/licenses/bsd
  19. * @category Horde
  20. * @package Db
  21. * @subpackage Adapter
  22. */
  23. interface Horde_Db_Adapter
  24. {
  25. /**
  26. * Returns the human-readable name of the adapter. Use mixed case - one
  27. * can always use downcase if needed.
  28. *
  29. * @return string
  30. */
  31. public function adapterName();
  32. /**
  33. * Does this adapter support migrations? Backend specific, as the
  34. * abstract adapter always returns +false+.
  35. *
  36. * @return boolean
  37. */
  38. public function supportsMigrations();
  39. /**
  40. * Does this adapter support using DISTINCT within COUNT? This is +true+
  41. * for all adapters except sqlite.
  42. *
  43. * @return boolean
  44. */
  45. public function supportsCountDistinct();
  46. /**
  47. * Should primary key values be selected from their corresponding
  48. * sequence before the insert statement? If true, next_sequence_value
  49. * is called before each insert to set the record's primary key.
  50. * This is false for all adapters but Firebird.
  51. *
  52. * @return boolean
  53. */
  54. public function prefetchPrimaryKey($tableName = null);
  55. /*##########################################################################
  56. # Connection Management
  57. ##########################################################################*/
  58. /**
  59. * Connect to the db.
  60. */
  61. public function connect();
  62. /**
  63. * Is the connection active?
  64. *
  65. * @return boolean
  66. */
  67. public function isActive();
  68. /**
  69. * Reconnect to the db.
  70. */
  71. public function reconnect();
  72. /**
  73. * Disconnect from db.
  74. */
  75. public function disconnect();
  76. /**
  77. * Provides access to the underlying database connection. Useful for when
  78. * you need to call a proprietary method such as postgresql's
  79. * lo_* methods.
  80. *
  81. * @return resource
  82. */
  83. public function rawConnection();
  84. /*##########################################################################
  85. # Quoting
  86. ##########################################################################*/
  87. /**
  88. * Quotes a string, escaping any special characters.
  89. *
  90. * @param string $string
  91. * @return string
  92. */
  93. public function quoteString($string);
  94. /*##########################################################################
  95. # Database Statements
  96. ##########################################################################*/
  97. /**
  98. * Returns an array of records with the column names as keys, and
  99. * column values as values.
  100. *
  101. * @param string $sql SQL statement.
  102. * @param mixed $arg1 Either an array of bound parameters or a query
  103. * name.
  104. * @param string $arg2 If $arg1 contains bound parameters, the query
  105. * name.
  106. *
  107. * @return Horde_Db_Adapter_Base_Result
  108. * @throws Horde_Db_Exception
  109. */
  110. public function select($sql, $arg1 = null, $arg2 = null);
  111. /**
  112. * Returns an array of record hashes with the column names as keys and
  113. * column values as values.
  114. *
  115. * @param string $sql SQL statement.
  116. * @param mixed $arg1 Either an array of bound parameters or a query
  117. * name.
  118. * @param string $arg2 If $arg1 contains bound parameters, the query
  119. * name.
  120. *
  121. * @return array
  122. * @throws Horde_Db_Exception
  123. */
  124. public function selectAll($sql, $arg1 = null, $arg2 = null);
  125. /**
  126. * Returns a record hash with the column names as keys and column values
  127. * as values.
  128. *
  129. * @param string $sql SQL statement.
  130. * @param mixed $arg1 Either an array of bound parameters or a query
  131. * name.
  132. * @param string $arg2 If $arg1 contains bound parameters, the query
  133. * name.
  134. *
  135. * @return array
  136. * @throws Horde_Db_Exception
  137. */
  138. public function selectOne($sql, $arg1 = null, $arg2 = null);
  139. /**
  140. * Returns a single value from a record
  141. *
  142. * @param string $sql SQL statement.
  143. * @param mixed $arg1 Either an array of bound parameters or a query
  144. * name.
  145. * @param string $arg2 If $arg1 contains bound parameters, the query
  146. * name.
  147. *
  148. * @return string
  149. * @throws Horde_Db_Exception
  150. */
  151. public function selectValue($sql, $arg1 = null, $arg2 = null);
  152. /**
  153. * Returns an array of the values of the first column in a select:
  154. * selectValues("SELECT id FROM companies LIMIT 3") => [1,2,3]
  155. *
  156. * @param string $sql SQL statement.
  157. * @param mixed $arg1 Either an array of bound parameters or a query
  158. * name.
  159. * @param string $arg2 If $arg1 contains bound parameters, the query
  160. * name.
  161. *
  162. * @return array
  163. * @throws Horde_Db_Exception
  164. */
  165. public function selectValues($sql, $arg1 = null, $arg2 = null);
  166. /**
  167. * Returns an array where the keys are the first column of a select, and the
  168. * values are the second column:
  169. *
  170. * selectAssoc("SELECT id, name FROM companies LIMIT 3") => [1 => 'Ford', 2 => 'GM', 3 => 'Chrysler']
  171. *
  172. * @param string $sql SQL statement.
  173. * @param mixed $arg1 Either an array of bound parameters or a query
  174. * name.
  175. * @param string $arg2 If $arg1 contains bound parameters, the query
  176. * name.
  177. *
  178. * @return array
  179. * @throws Horde_Db_Exception
  180. */
  181. public function selectAssoc($sql, $arg1 = null, $arg2 = null);
  182. /**
  183. * Executes the SQL statement in the context of this connection.
  184. *
  185. * @deprecated Deprecated for external usage. Use select() instead.
  186. *
  187. * @param string $sql SQL statement.
  188. * @param mixed $arg1 Either an array of bound parameters or a query
  189. * name.
  190. * @param string $arg2 If $arg1 contains bound parameters, the query
  191. * name.
  192. *
  193. * @return mixed
  194. * @throws Horde_Db_Exception
  195. */
  196. public function execute($sql, $arg1 = null, $arg2 = null);
  197. /**
  198. * Inserts a row into a table.
  199. *
  200. * @param string $sql SQL statement.
  201. * @param array|string $arg1 Either an array of bound parameters or a
  202. * query name.
  203. * @param string $arg2 If $arg1 contains bound parameters, the
  204. * query name.
  205. * @param string $pk The primary key column.
  206. * @param integer $idValue The primary key value. This parameter is
  207. * required if the primary key is inserted
  208. * manually.
  209. * @param string $sequenceName The sequence name.
  210. *
  211. * @return integer Last inserted ID.
  212. * @throws Horde_Db_Exception
  213. */
  214. public function insert($sql, $arg1 = null, $arg2 = null, $pk = null,
  215. $idValue = null, $sequenceName = null);
  216. /**
  217. * Executes the update statement and returns the number of rows affected.
  218. *
  219. * @param string $sql SQL statement.
  220. * @param mixed $arg1 Either an array of bound parameters or a query
  221. * name.
  222. * @param string $arg2 If $arg1 contains bound parameters, the query
  223. * name.
  224. *
  225. * @return integer Number of rows affected.
  226. * @throws Horde_Db_Exception
  227. */
  228. public function update($sql, $arg1 = null, $arg2 = null);
  229. /**
  230. * Executes the delete statement and returns the number of rows affected.
  231. *
  232. * @param string $sql SQL statement.
  233. * @param mixed $arg1 Either an array of bound parameters or a query
  234. * name.
  235. * @param string $arg2 If $arg1 contains bound parameters, the query
  236. * name.
  237. *
  238. * @return integer Number of rows affected.
  239. * @throws Horde_Db_Exception
  240. */
  241. public function delete($sql, $arg1 = null, $arg2 = null);
  242. /**
  243. * Check if a transaction has been started.
  244. *
  245. * @return boolean True if transaction has been started.
  246. */
  247. public function transactionStarted();
  248. /**
  249. * Begins the transaction (and turns off auto-committing).
  250. */
  251. public function beginDbTransaction();
  252. /**
  253. * Commits the transaction (and turns on auto-committing).
  254. */
  255. public function commitDbTransaction();
  256. /**
  257. * Rolls back the transaction (and turns on auto-committing). Must be
  258. * done if the transaction block raises an exception or returns false.
  259. */
  260. public function rollbackDbTransaction();
  261. /**
  262. * Appends +LIMIT+ and +OFFSET+ options to a SQL statement.
  263. *
  264. * @param string $sql SQL statement.
  265. * @param array $options TODO
  266. *
  267. * @return string
  268. */
  269. public function addLimitOffset($sql, $options);
  270. /**
  271. * Appends a locking clause to an SQL statement.
  272. * This method *modifies* the +sql+ parameter.
  273. *
  274. * # SELECT * FROM suppliers FOR UPDATE
  275. * add_lock! 'SELECT * FROM suppliers', :lock => true
  276. * add_lock! 'SELECT * FROM suppliers', :lock => ' FOR UPDATE'
  277. *
  278. * @param string &$sql SQL statment.
  279. * @param array $options TODO.
  280. */
  281. public function addLock(&$sql, array $options = array());
  282. }