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