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

https://github.com/fastslack/joomla-cms · PHP · 463 lines · 124 code · 34 blank · 305 comment · 0 complexity · f254e5d4ba7d48e88e35c62fccb97b2d MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.UnitTest
  4. * @subpackage Database
  5. *
  6. * @copyright Copyright (C) 2005 - 2017 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;
  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. }
  81. /**
  82. * Drops a table from the database.
  83. *
  84. * @param string $table The name of the database table to drop.
  85. * @param boolean $ifExists Optionally specify that the table must exist before it is dropped.
  86. *
  87. * @return JDatabase Returns this object to support chaining.
  88. *
  89. * @since 11.4
  90. * @throws RuntimeException
  91. */
  92. public function dropTable($table, $ifExists = true)
  93. {
  94. return $this;
  95. }
  96. /**
  97. * Method to escape a string for usage in an SQL statement.
  98. *
  99. * @param string $text The string to be escaped.
  100. * @param boolean $extra Optional parameter to provide extra escaping.
  101. *
  102. * @return string The escaped string.
  103. *
  104. * @since 11.4
  105. */
  106. public function escape($text, $extra = false)
  107. {
  108. return $extra ? "/$text//" : "-$text-";
  109. }
  110. /**
  111. * Method to fetch a row from the result set cursor as an array.
  112. *
  113. * @param mixed $cursor The optional result set cursor from which to fetch the row.
  114. *
  115. * @return mixed Either the next row from the result set or false if there are no more rows.
  116. *
  117. * @since 11.4
  118. */
  119. protected function fetchArray($cursor = null)
  120. {
  121. return array();
  122. }
  123. /**
  124. * Method to fetch a row from the result set cursor as an associative array.
  125. *
  126. * @param mixed $cursor The optional result set cursor from which to fetch the row.
  127. *
  128. * @return mixed Either the next row from the result set or false if there are no more rows.
  129. *
  130. * @since 11.4
  131. */
  132. protected function fetchAssoc($cursor = null)
  133. {
  134. return array();
  135. }
  136. /**
  137. * Method to fetch a row from the result set cursor as an object.
  138. *
  139. * @param mixed $cursor The optional result set cursor from which to fetch the row.
  140. * @param string $class The class name to use for the returned row object.
  141. *
  142. * @return mixed Either the next row from the result set or false if there are no more rows.
  143. *
  144. * @since 11.4
  145. */
  146. protected function fetchObject($cursor = null, $class = 'stdClass')
  147. {
  148. return new $class;
  149. }
  150. /**
  151. * Method to free up the memory used for the result set.
  152. *
  153. * @param mixed $cursor The optional result set cursor from which to fetch the row.
  154. *
  155. * @return void
  156. *
  157. * @since 11.4
  158. */
  159. protected function freeResult($cursor = null)
  160. {
  161. return null;
  162. }
  163. /**
  164. * Get the number of affected rows for the previous executed SQL statement.
  165. *
  166. * @return integer The number of affected rows.
  167. *
  168. * @since 11.4
  169. */
  170. public function getAffectedRows()
  171. {
  172. return 0;
  173. }
  174. /**
  175. * Method to get the database collation in use by sampling a text field of a table in the database.
  176. *
  177. * @return mixed The collation in use by the database or boolean false if not supported.
  178. *
  179. * @since 11.4
  180. */
  181. public function getCollation()
  182. {
  183. return false;
  184. }
  185. /**
  186. * Method to get the database connection collation, as reported by the driver. If the connector doesn't support
  187. * reporting this value please return an empty string.
  188. *
  189. * @return string
  190. */
  191. public function getConnectionCollation()
  192. {
  193. return false;
  194. }
  195. /**
  196. * Get the number of returned rows for the previous executed SQL statement.
  197. *
  198. * @param resource $cursor An optional database cursor resource to extract the row count from.
  199. *
  200. * @return integer The number of returned rows.
  201. *
  202. * @since 11.4
  203. */
  204. public function getNumRows($cursor = null)
  205. {
  206. return 0;
  207. }
  208. /**
  209. * Get the current query object or a new JDatabaseQuery object.
  210. *
  211. * @param boolean $new False to return the current query object, True to return a new JDatabaseQuery object.
  212. *
  213. * @return JDatabaseQuery The current query object or a new object extending the JDatabaseQuery class.
  214. *
  215. * @since 11.4
  216. * @throws RuntimeException
  217. */
  218. public function getQuery($new = false)
  219. {
  220. return null;
  221. }
  222. /**
  223. * Retrieves field information about the given tables.
  224. *
  225. * @param string $table The name of the database table.
  226. * @param boolean $typeOnly True (default) to only return field types.
  227. *
  228. * @return array An array of fields by table.
  229. *
  230. * @since 11.4
  231. * @throws RuntimeException
  232. */
  233. public function getTableColumns($table, $typeOnly = true)
  234. {
  235. return array();
  236. }
  237. /**
  238. * Shows the table CREATE statement that creates the given tables.
  239. *
  240. * @param mixed $tables A table name or a list of table names.
  241. *
  242. * @return array A list of the create SQL for the tables.
  243. *
  244. * @since 11.4
  245. * @throws RuntimeException
  246. */
  247. public function getTableCreate($tables)
  248. {
  249. return '';
  250. }
  251. /**
  252. * Retrieves field information about the given tables.
  253. *
  254. * @param mixed $tables A table name or a list of table names.
  255. *
  256. * @return array An array of keys for the table(s).
  257. *
  258. * @since 11.4
  259. * @throws RuntimeException
  260. */
  261. public function getTableKeys($tables)
  262. {
  263. return array();
  264. }
  265. /**
  266. * Method to get an array of all tables in the database.
  267. *
  268. * @return array An array of all the tables in the database.
  269. *
  270. * @since 11.4
  271. * @throws RuntimeException
  272. */
  273. public function getTableList()
  274. {
  275. return array();
  276. }
  277. /**
  278. * Get the version of the database connector
  279. *
  280. * @return string The database connector version.
  281. *
  282. * @since 11.4
  283. */
  284. public function getVersion()
  285. {
  286. return '12.1';
  287. }
  288. /**
  289. * Method to get the auto-incremented value from the last INSERT statement.
  290. *
  291. * @return integer The value of the auto-increment field from the last inserted row.
  292. *
  293. * @since 11.4
  294. */
  295. public function insertid()
  296. {
  297. return 0;
  298. }
  299. /**
  300. * Locks a table in the database.
  301. *
  302. * @param string $tableName The name of the table to unlock.
  303. *
  304. * @return JDatabase Returns this object to support chaining.
  305. *
  306. * @since 11.4
  307. * @throws RuntimeException
  308. */
  309. public function lockTable($tableName)
  310. {
  311. return $this;
  312. }
  313. /**
  314. * Execute the SQL statement.
  315. *
  316. * @return mixed A database cursor resource on success, boolean false on failure.
  317. *
  318. * @since 11.4
  319. * @throws RuntimeException
  320. */
  321. public function execute()
  322. {
  323. return false;
  324. }
  325. /**
  326. * Renames a table in the database.
  327. *
  328. * @param string $oldTable The name of the table to be renamed
  329. * @param string $newTable The new name for the table.
  330. * @param string $backup Table prefix
  331. * @param string $prefix For the table - used to rename constraints in non-mysql databases
  332. *
  333. * @return JDatabase Returns this object to support chaining.
  334. *
  335. * @since 11.4
  336. * @throws RuntimeException
  337. */
  338. public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
  339. {
  340. return $this;
  341. }
  342. /**
  343. * Select a database for use.
  344. *
  345. * @param string $database The name of the database to select for use.
  346. *
  347. * @return boolean True if the database was successfully selected.
  348. *
  349. * @since 11.4
  350. * @throws RuntimeException
  351. */
  352. public function select($database)
  353. {
  354. return false;
  355. }
  356. /**
  357. * Set the connection to use UTF-8 character encoding.
  358. *
  359. * @return boolean True on success.
  360. *
  361. * @since 11.4
  362. */
  363. public function setUtf()
  364. {
  365. return false;
  366. }
  367. /**
  368. * Test to see if the connector is available.
  369. *
  370. * @return boolean True on success, false otherwise.
  371. *
  372. * @since 11.2
  373. */
  374. public static function isSupported()
  375. {
  376. return true;
  377. }
  378. /**
  379. * Method to commit a transaction.
  380. *
  381. * @param boolean $toSavepoint If true roll back to savepoint
  382. *
  383. * @return void
  384. *
  385. * @since 11.4
  386. * @throws RuntimeException
  387. */
  388. public function transactionCommit($toSavepoint = false)
  389. {
  390. }
  391. /**
  392. * Method to roll back a transaction.
  393. *
  394. * @param boolean $toSavepoint If true roll back to savepoint
  395. *
  396. * @return void
  397. *
  398. * @since 11.4
  399. * @throws RuntimeException
  400. */
  401. public function transactionRollback($toSavepoint = false)
  402. {
  403. }
  404. /**
  405. * Method to initialize a transaction.
  406. *
  407. * @param boolean $asSavepoint If true start as savepoint
  408. *
  409. * @return void
  410. *
  411. * @since 11.4
  412. * @throws RuntimeException
  413. */
  414. public function transactionStart($asSavepoint = false)
  415. {
  416. }
  417. /**
  418. * Unlocks tables in the database.
  419. *
  420. * @return JDatabase Returns this object to support chaining.
  421. *
  422. * @since 11.4
  423. * @throws RuntimeException
  424. */
  425. public function unlockTables()
  426. {
  427. return $this;
  428. }
  429. }