DriverInterface.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.6.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Database;
  16. use Cake\Database\Query;
  17. /**
  18. * Interface for database driver.
  19. *
  20. * @method $this disableAutoQuoting()
  21. */
  22. interface DriverInterface
  23. {
  24. /**
  25. * Establishes a connection to the database server.
  26. *
  27. * @return bool True on success, false on failure.
  28. */
  29. public function connect();
  30. /**
  31. * Disconnects from database server.
  32. *
  33. * @return void
  34. */
  35. public function disconnect();
  36. /**
  37. * Returns correct connection resource or object that is internally used.
  38. *
  39. * @return object Connection object used internally.
  40. */
  41. public function getConnection();
  42. /**
  43. * Set the internal connection object.
  44. *
  45. * @param object $connection The connection instance.
  46. * @return $this
  47. */
  48. public function setConnection($connection);
  49. /**
  50. * Returns whether php is able to use this driver for connecting to database.
  51. *
  52. * @return bool True if it is valid to use this driver.
  53. */
  54. public function enabled();
  55. /**
  56. * Prepares a sql statement to be executed.
  57. *
  58. * @param string|\Cake\Database\Query $query The query to turn into a prepared statement.
  59. * @return \Cake\Database\StatementInterface
  60. */
  61. public function prepare($query);
  62. /**
  63. * Starts a transaction.
  64. *
  65. * @return bool True on success, false otherwise.
  66. */
  67. public function beginTransaction();
  68. /**
  69. * Commits a transaction.
  70. *
  71. * @return bool True on success, false otherwise.
  72. */
  73. public function commitTransaction();
  74. /**
  75. * Rollbacks a transaction.
  76. *
  77. * @return bool True on success, false otherwise.
  78. */
  79. public function rollbackTransaction();
  80. /**
  81. * Get the SQL for releasing a save point.
  82. *
  83. * @param string $name The table name.
  84. * @return string
  85. */
  86. public function releaseSavePointSQL($name);
  87. /**
  88. * Get the SQL for creating a save point.
  89. *
  90. * @param string $name The table name.
  91. * @return string
  92. */
  93. public function savePointSQL($name);
  94. /**
  95. * Get the SQL for rollingback a save point.
  96. *
  97. * @param string $name The table name.
  98. * @return string
  99. */
  100. public function rollbackSavePointSQL($name);
  101. /**
  102. * Get the SQL for disabling foreign keys.
  103. *
  104. * @return string
  105. */
  106. public function disableForeignKeySQL();
  107. /**
  108. * Get the SQL for enabling foreign keys.
  109. *
  110. * @return string
  111. */
  112. public function enableForeignKeySQL();
  113. /**
  114. * Returns whether the driver supports adding or dropping constraints
  115. * to already created tables.
  116. *
  117. * @return bool true if driver supports dynamic constraints.
  118. */
  119. public function supportsDynamicConstraints();
  120. /**
  121. * Returns whether this driver supports save points for nested transactions.
  122. *
  123. * @return bool True if save points are supported, false otherwise.
  124. */
  125. public function supportsSavePoints();
  126. /**
  127. * Returns a value in a safe representation to be used in a query string
  128. *
  129. * @param mixed $value The value to quote.
  130. * @param string $type Type to be used for determining kind of quoting to perform.
  131. * @return string
  132. */
  133. public function quote($value, $type);
  134. /**
  135. * Checks if the driver supports quoting.
  136. *
  137. * @return bool
  138. */
  139. public function supportsQuoting();
  140. /**
  141. * Returns a callable function that will be used to transform a passed Query object.
  142. * This function, in turn, will return an instance of a Query object that has been
  143. * transformed to accommodate any specificities of the SQL dialect in use.
  144. *
  145. * @param string $type The type of query to be transformed
  146. * (select, insert, update, delete).
  147. * @return callable
  148. */
  149. public function queryTranslator($type);
  150. /**
  151. * Get the schema dialect.
  152. *
  153. * Used by Cake\Database\Schema package to reflect schema and
  154. * generate schema.
  155. *
  156. * If all the tables that use this Driver specify their
  157. * own schemas, then this may return null.
  158. *
  159. * @return \Cake\Database\Schema\BaseSchema
  160. */
  161. public function schemaDialect();
  162. /**
  163. * Quotes a database identifier (a column name, table name, etc..) to
  164. * be used safely in queries without the risk of using reserved words.
  165. *
  166. * @param string $identifier The identifier expression to quote.
  167. * @return string
  168. */
  169. public function quoteIdentifier($identifier);
  170. /**
  171. * Escapes values for use in schema definitions.
  172. *
  173. * @param mixed $value The value to escape.
  174. * @return string String for use in schema definitions.
  175. */
  176. public function schemaValue($value);
  177. /**
  178. * Returns the schema name that's being used.
  179. *
  180. * @return string
  181. */
  182. public function schema();
  183. /**
  184. * Returns last id generated for a table or sequence in database.
  185. *
  186. * @param string|null $table table name or sequence to get last insert value from.
  187. * @param string|null $column the name of the column representing the primary key.
  188. * @return string|int
  189. */
  190. public function lastInsertId($table = null, $column = null);
  191. /**
  192. * Checks whether or not the driver is connected.
  193. *
  194. * @return bool
  195. */
  196. public function isConnected();
  197. /**
  198. * Sets whether or not this driver should automatically quote identifiers
  199. * in queries.
  200. *
  201. * @param bool $enable Whether to enable auto quoting
  202. * @return $this
  203. */
  204. public function enableAutoQuoting($enable = true);
  205. /**
  206. * Returns whether or not this driver should automatically quote identifiers
  207. * in queries.
  208. *
  209. * @return bool
  210. */
  211. public function isAutoQuotingEnabled();
  212. /**
  213. * Transforms the passed query to this Driver's dialect and returns an instance
  214. * of the transformed query and the full compiled SQL string.
  215. *
  216. * @param \Cake\Database\Query $query The query to compile.
  217. * @param \Cake\Database\ValueBinder $generator The value binder to use.
  218. * @return array containing 2 entries. The first entity is the transformed query
  219. * and the second one the compiled SQL.
  220. */
  221. public function compileQuery(Query $query, ValueBinder $generator);
  222. /**
  223. * Returns an instance of a QueryCompiler.
  224. *
  225. * @return \Cake\Database\QueryCompiler
  226. */
  227. public function newCompiler();
  228. }