PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/suites/unit/joomla/database/stubs/nosqldriver.php

http://github.com/joomla/joomla-platform
PHP | 453 lines | 121 code | 33 blank | 299 comment | 0 complexity | 0fb72d36e1b5704f2ffcf5b62ff7018b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @package Joomla.UnitTest
  4. * @subpackage Database
  5. *
  6. * @copyright Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. /**
  10. * Test class JDatabase.
  11. *
  12. * @package Joomla.UnitTest
  13. * @subpackage Database
  14. * @since 11.4
  15. */
  16. class JDatabaseDriverNosql extends JDatabaseDriver
  17. {
  18. /**
  19. * The name of the database driver.
  20. *
  21. * @var string
  22. * @since 11.4
  23. */
  24. public $name = 'nosql';
  25. /**
  26. * The character(s) used to quote SQL statement names such as table names or field names,
  27. * etc. The child classes should define this as necessary. If a single character string the
  28. * same character is used for both sides of the quoted name, else the first character will be
  29. * used for the opening quote and the second for the closing quote.
  30. *
  31. * @var string
  32. * @since 11.4
  33. */
  34. protected $nameQuote = '[]';
  35. /**
  36. * The null or zero representation of a timestamp for the database driver. This should be
  37. * defined in child classes to hold the appropriate value for the engine.
  38. *
  39. * @var string
  40. * @since 11.4
  41. */
  42. protected $nullDate = '1BC';
  43. /**
  44. * @var string The minimum supported database version.
  45. * @since 12.1
  46. */
  47. protected static $dbMinimum = '12.1';
  48. /**
  49. * Connects to the database if needed.
  50. *
  51. * @return void Returns void if the database connected successfully.
  52. *
  53. * @since 12.1
  54. * @throws RuntimeException
  55. */
  56. public function connect()
  57. {
  58. return true;
  59. }
  60. /**
  61. * Determines if the connection to the server is active.
  62. *
  63. * @return boolean True if connected to the database engine.
  64. *
  65. * @since 11.4
  66. */
  67. public function connected()
  68. {
  69. return true;
  70. }
  71. /**
  72. * Disconnects the database.
  73. *
  74. * @return void
  75. *
  76. * @since 12.1
  77. */
  78. public function disconnect()
  79. {
  80. return;
  81. }
  82. /**
  83. * Drops a table from the database.
  84. *
  85. * @param string $table The name of the database table to drop.
  86. * @param boolean $ifExists Optionally specify that the table must exist before it is dropped.
  87. *
  88. * @return JDatabase Returns this object to support chaining.
  89. *
  90. * @since 11.4
  91. * @throws RuntimeException
  92. */
  93. public function dropTable($table, $ifExists = true)
  94. {
  95. return $this;
  96. }
  97. /**
  98. * Method to escape a string for usage in an SQL statement.
  99. *
  100. * @param string $text The string to be escaped.
  101. * @param boolean $extra Optional parameter to provide extra escaping.
  102. *
  103. * @return string The escaped string.
  104. *
  105. * @since 11.4
  106. */
  107. public function escape($text, $extra = false)
  108. {
  109. return $extra ? "/$text//" : "-$text-";
  110. }
  111. /**
  112. * Method to fetch a row from the result set cursor as an array.
  113. *
  114. * @param mixed $cursor The optional result set cursor from which to fetch the row.
  115. *
  116. * @return mixed Either the next row from the result set or false if there are no more rows.
  117. *
  118. * @since 11.4
  119. */
  120. protected function fetchArray($cursor = null)
  121. {
  122. return array();
  123. }
  124. /**
  125. * Method to fetch a row from the result set cursor as an associative array.
  126. *
  127. * @param mixed $cursor The optional result set cursor from which to fetch the row.
  128. *
  129. * @return mixed Either the next row from the result set or false if there are no more rows.
  130. *
  131. * @since 11.4
  132. */
  133. protected function fetchAssoc($cursor = null)
  134. {
  135. return array();
  136. }
  137. /**
  138. * Method to fetch a row from the result set cursor as an object.
  139. *
  140. * @param mixed $cursor The optional result set cursor from which to fetch the row.
  141. * @param string $class The class name to use for the returned row object.
  142. *
  143. * @return mixed Either the next row from the result set or false if there are no more rows.
  144. *
  145. * @since 11.4
  146. */
  147. protected function fetchObject($cursor = null, $class = 'stdClass')
  148. {
  149. return new $class;
  150. }
  151. /**
  152. * Method to free up the memory used for the result set.
  153. *
  154. * @param mixed $cursor The optional result set cursor from which to fetch the row.
  155. *
  156. * @return void
  157. *
  158. * @since 11.4
  159. */
  160. protected function freeResult($cursor = null)
  161. {
  162. return null;
  163. }
  164. /**
  165. * Get the number of affected rows for the previous executed SQL statement.
  166. *
  167. * @return integer The number of affected rows.
  168. *
  169. * @since 11.4
  170. */
  171. public function getAffectedRows()
  172. {
  173. return 0;
  174. }
  175. /**
  176. * Method to get the database collation in use by sampling a text field of a table in the database.
  177. *
  178. * @return mixed The collation in use by the database or boolean false if not supported.
  179. *
  180. * @since 11.4
  181. */
  182. public function getCollation()
  183. {
  184. return false;
  185. }
  186. /**
  187. * Get the number of returned rows for the previous executed SQL statement.
  188. *
  189. * @param resource $cursor An optional database cursor resource to extract the row count from.
  190. *
  191. * @return integer The number of returned rows.
  192. *
  193. * @since 11.4
  194. */
  195. public function getNumRows($cursor = null)
  196. {
  197. return 0;
  198. }
  199. /**
  200. * Get the current query object or a new JDatabaseQuery object.
  201. *
  202. * @param boolean $new False to return the current query object, True to return a new JDatabaseQuery object.
  203. *
  204. * @return JDatabaseQuery The current query object or a new object extending the JDatabaseQuery class.
  205. *
  206. * @since 11.4
  207. * @throws RuntimeException
  208. */
  209. public function getQuery($new = false)
  210. {
  211. return null;
  212. }
  213. /**
  214. * Retrieves field information about the given tables.
  215. *
  216. * @param string $table The name of the database table.
  217. * @param boolean $typeOnly True (default) to only return field types.
  218. *
  219. * @return array An array of fields by table.
  220. *
  221. * @since 11.4
  222. * @throws RuntimeException
  223. */
  224. public function getTableColumns($table, $typeOnly = true)
  225. {
  226. return array();
  227. }
  228. /**
  229. * Shows the table CREATE statement that creates the given tables.
  230. *
  231. * @param mixed $tables A table name or a list of table names.
  232. *
  233. * @return array A list of the create SQL for the tables.
  234. *
  235. * @since 11.4
  236. * @throws RuntimeException
  237. */
  238. public function getTableCreate($tables)
  239. {
  240. return '';
  241. }
  242. /**
  243. * Retrieves field information about the given tables.
  244. *
  245. * @param mixed $tables A table name or a list of table names.
  246. *
  247. * @return array An array of keys for the table(s).
  248. *
  249. * @since 11.4
  250. * @throws RuntimeException
  251. */
  252. public function getTableKeys($tables)
  253. {
  254. return array();
  255. }
  256. /**
  257. * Method to get an array of all tables in the database.
  258. *
  259. * @return array An array of all the tables in the database.
  260. *
  261. * @since 11.4
  262. * @throws RuntimeException
  263. */
  264. public function getTableList()
  265. {
  266. return array();
  267. }
  268. /**
  269. * Get the version of the database connector
  270. *
  271. * @return string The database connector version.
  272. *
  273. * @since 11.4
  274. */
  275. public function getVersion()
  276. {
  277. return '12.1';
  278. }
  279. /**
  280. * Method to get the auto-incremented value from the last INSERT statement.
  281. *
  282. * @return integer The value of the auto-increment field from the last inserted row.
  283. *
  284. * @since 11.4
  285. */
  286. public function insertid()
  287. {
  288. return 0;
  289. }
  290. /**
  291. * Locks a table in the database.
  292. *
  293. * @param string $tableName The name of the table to unlock.
  294. *
  295. * @return JDatabase Returns this object to support chaining.
  296. *
  297. * @since 11.4
  298. * @throws RuntimeException
  299. */
  300. public function lockTable($tableName)
  301. {
  302. return $this;
  303. }
  304. /**
  305. * Execute the SQL statement.
  306. *
  307. * @return mixed A database cursor resource on success, boolean false on failure.
  308. *
  309. * @since 11.4
  310. * @throws RuntimeException
  311. */
  312. public function execute()
  313. {
  314. return false;
  315. }
  316. /**
  317. * Renames a table in the database.
  318. *
  319. * @param string $oldTable The name of the table to be renamed
  320. * @param string $newTable The new name for the table.
  321. * @param string $backup Table prefix
  322. * @param string $prefix For the table - used to rename constraints in non-mysql databases
  323. *
  324. * @return JDatabase Returns this object to support chaining.
  325. *
  326. * @since 11.4
  327. * @throws RuntimeException
  328. */
  329. public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
  330. {
  331. return $this;
  332. }
  333. /**
  334. * Select a database for use.
  335. *
  336. * @param string $database The name of the database to select for use.
  337. *
  338. * @return boolean True if the database was successfully selected.
  339. *
  340. * @since 11.4
  341. * @throws RuntimeException
  342. */
  343. public function select($database)
  344. {
  345. return false;
  346. }
  347. /**
  348. * Set the connection to use UTF-8 character encoding.
  349. *
  350. * @return boolean True on success.
  351. *
  352. * @since 11.4
  353. */
  354. public function setUTF()
  355. {
  356. return false;
  357. }
  358. /**
  359. * Test to see if the connector is available.
  360. *
  361. * @return boolean True on success, false otherwise.
  362. *
  363. * @since 11.2
  364. */
  365. public static function isSupported()
  366. {
  367. return true;
  368. }
  369. /**
  370. * Method to commit a transaction.
  371. *
  372. * @param boolean $toSavepoint If true roll back to savepoint
  373. *
  374. * @return void
  375. *
  376. * @since 11.4
  377. * @throws RuntimeException
  378. */
  379. public function transactionCommit($toSavepoint = false)
  380. {
  381. }
  382. /**
  383. * Method to roll back a transaction.
  384. *
  385. * @param boolean $toSavepoint If true roll back to savepoint
  386. *
  387. * @return void
  388. *
  389. * @since 11.4
  390. * @throws RuntimeException
  391. */
  392. public function transactionRollback($toSavepoint = false)
  393. {
  394. }
  395. /**
  396. * Method to initialize a transaction.
  397. *
  398. * @param boolean $asSavepoint If true start as savepoint
  399. *
  400. * @return void
  401. *
  402. * @since 11.4
  403. * @throws RuntimeException
  404. */
  405. public function transactionStart($asSavepoint = false)
  406. {
  407. }
  408. /**
  409. * Unlocks tables in the database.
  410. *
  411. * @return JDatabase Returns this object to support chaining.
  412. *
  413. * @since 11.4
  414. * @throws RuntimeException
  415. */
  416. public function unlockTables()
  417. {
  418. return $this;
  419. }
  420. }