1: <?php
2:
3: /**
4: * This file is part of the "dibi" - smart database abstraction layer.
5: *
6: * Copyright (c) 2005, 2010 David Grudl (http://davidgrudl.com)
7: *
8: * This source file is subject to the "dibi license", and/or
9: * GPL license. For more information please see http://dibiphp.com
10: * @package dibi
11: */
12:
13:
14:
15: /**
16: * Provides an interface between a dataset and data-aware components.
17: * @package dibi
18: */
19: interface IDataSource extends Countable, IteratorAggregate
20: {
21: //function IteratorAggregate::getIterator();
22: //function Countable::count();
23: }
24:
25:
26:
27:
28:
29: /**
30: * Defines method that must profiler implement.
31: * @package dibi
32: */
33: interface IDibiProfiler
34: {
35: /**#@+ event type */
36: const CONNECT = 1;
37: const SELECT = 4;
38: const INSERT = 8;
39: const DELETE = 16;
40: const UPDATE = 32;
41: const QUERY = 60; // SELECT | INSERT | DELETE | UPDATE
42: const BEGIN = 64;
43: const COMMIT = 128;
44: const ROLLBACK = 256;
45: const TRANSACTION = 448; // BEGIN | COMMIT | ROLLBACK
46: const EXCEPTION = 512;
47: const ALL = 1023;
48: /**#@-*/
49:
50: /**
51: * Before event notification.
52: * @param DibiConnection
53: * @param int event name
54: * @param string sql
55: * @return int
56: */
57: function before(DibiConnection $connection, $event, $sql = NULL);
58:
59: /**
60: * After event notification.
61: * @param int
62: * @param DibiResult
63: * @return void
64: */
65: function after($ticket, $result = NULL);
66:
67: /**
68: * After exception notification.
69: * @param DibiDriverException
70: * @return void
71: */
72: function exception(DibiDriverException $exception);
73:
74: }
75:
76:
77:
78:
79:
80: /**
81: * dibi driver interface.
82: *
83: * @author David Grudl
84: */
85: interface IDibiDriver
86: {
87:
88: /**
89: * Connects to a database.
90: * @param array
91: * @return void
92: * @throws DibiException
93: */
94: function connect(array &$config);
95:
96: /**
97: * Disconnects from a database.
98: * @return void
99: * @throws DibiException
100: */
101: function disconnect();
102:
103: /**
104: * Internal: Executes the SQL query.
105: * @param string SQL statement.
106: * @return IDibiResultDriver|NULL
107: * @throws DibiDriverException
108: */
109: function query($sql);
110:
111: /**
112: * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
113: * @return int|FALSE number of rows or FALSE on error
114: */
115: function getAffectedRows();
116:
117: /**
118: * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
119: * @return int|FALSE int on success or FALSE on failure
120: */
121: function getInsertId($sequence);
122:
123: /**
124: * Begins a transaction (if supported).
125: * @param string optional savepoint name
126: * @return void
127: * @throws DibiDriverException
128: */
129: function begin($savepoint = NULL);
130:
131: /**
132: * Commits statements in a transaction.
133: * @param string optional savepoint name
134: * @return void
135: * @throws DibiDriverException
136: */
137: function commit($savepoint = NULL);
138:
139: /**
140: * Rollback changes in a transaction.
141: * @param string optional savepoint name
142: * @return void
143: * @throws DibiDriverException
144: */
145: function rollback($savepoint = NULL);
146:
147: /**
148: * Returns the connection resource.
149: * @return mixed
150: */
151: function getResource();
152:
153: /**
154: * Returns the connection reflector.
155: * @return IDibiReflector
156: */
157: function getReflector();
158:
159: /**
160: * Encodes data for use in a SQL statement.
161: * @param string value
162: * @param string type (dibi::TEXT, dibi::BOOL, ...)
163: * @return string encoded value
164: * @throws InvalidArgumentException
165: */
166: function escape($value, $type);
167:
168: /**
169: * Encodes string for use in a LIKE statement.
170: * @param string
171: * @param int
172: * @return string
173: */
174: function escapeLike($value, $pos);
175:
176: /**
177: * Injects LIMIT/OFFSET to the SQL query.
178: * @param string &$sql The SQL query that will be modified.
179: * @param int $limit
180: * @param int $offset
181: * @return void
182: */
183: function applyLimit(&$sql, $limit, $offset);
184:
185: }
186:
187:
188:
189:
190:
191: /**
192: * dibi result set driver interface.
193: *
194: * @author David Grudl
195: */
196: interface IDibiResultDriver
197: {
198:
199: /**
200: * Returns the number of rows in a result set.
201: * @return int
202: */
203: function getRowCount();
204:
205: /**
206: * Moves cursor position without fetching row.
207: * @param int the 0-based cursor pos to seek to
208: * @return boolean TRUE on success, FALSE if unable to seek to specified record
209: * @throws DibiException
210: */
211: function seek($row);
212:
213: /**
214: * Fetches the row at current position and moves the internal cursor to the next position.
215: * @param bool TRUE for associative array, FALSE for numeric
216: * @return array array on success, nonarray if no next record
217: * @internal
218: */
219: function fetch($type);
220:
221: /**
222: * Frees the resources allocated for this result set.
223: * @param resource result set resource
224: * @return void
225: */
226: function free();
227:
228: /**
229: * Returns metadata for all columns in a result set.
230: * @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
231: */
232: function getResultColumns();
233:
234: /**
235: * Returns the result set resource.
236: * @return mixed
237: */
238: function getResultResource();
239:
240: /**
241: * Decodes data from result set.
242: * @param string value
243: * @param string type (dibi::BINARY)
244: * @return string decoded value
245: * @throws InvalidArgumentException
246: */
247: function unescape($value, $type);
248:
249: }
250:
251:
252:
253:
254:
255: /**
256: * dibi driver reflection.
257: *
258: * @author David Grudl
259: */
260: interface IDibiReflector
261: {
262:
263: /**
264: * Returns list of tables.
265: * @return array of {name [, (bool) view ]}
266: */
267: function getTables();
268:
269: /**
270: * Returns metadata for all columns in a table.
271: * @param string
272: * @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
273: */
274: function getColumns($table);
275:
276: /**
277: * Returns metadata for all indexes in a table.
278: * @param string
279: * @return array of {name, (array of names) columns [, (bool) unique, (bool) primary ]}
280: */
281: function getIndexes($table);
282:
283: /**
284: * Returns metadata for all foreign keys in a table.
285: * @param string
286: * @return array
287: */
288: function getForeignKeys($table);
289:
290: }
291: