Source for file interfaces.php

Documentation is available at interfaces.php

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