PageRenderTime 34ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/tests/Zend/Db/Adapter/Static.php

http://firephp.googlecode.com/
PHP | 327 lines | 116 code | 35 blank | 176 comment | 5 complexity | 865490bd9ca40c382f4bc8c03f40d63a MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Db
  17. * @subpackage Adapter
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Static.php 13281 2008-12-15 20:53:30Z mikaelkael $
  21. */
  22. /**
  23. * PHPUnit_Util_Filter
  24. */
  25. require_once 'PHPUnit/Util/Filter.php';
  26. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  27. /**
  28. * @see Zend_Db_Adapter_Abstract
  29. */
  30. require_once 'Zend/Db/Adapter/Abstract.php';
  31. /**
  32. * @see Zend_Db_Statement_Static
  33. */
  34. require_once 'Zend/Db/Statement/Static.php';
  35. /**
  36. * Class for connecting to SQL databases and performing common operations.
  37. *
  38. * @category Zend
  39. * @package Zend_Db
  40. * @subpackage Adapter
  41. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. */
  44. class Zend_Db_Adapter_Static extends Zend_Db_Adapter_Abstract
  45. {
  46. public $config = null;
  47. /**
  48. * The number of seconds to sleep upon query execution
  49. *
  50. * @var integer
  51. */
  52. protected $_onQuerySleep = 0;
  53. /**
  54. * Sets the number of seconds to sleep upon query execution
  55. *
  56. * @param integer $seconds
  57. * @return Zend_Db_Adapter_Static Provides a fluent interface
  58. */
  59. public function setOnQuerySleep($seconds = 0)
  60. {
  61. $this->_onQuerySleep = (integer) $seconds;
  62. return $this;
  63. }
  64. /**
  65. * Returns the number of seconds to sleep upon query execution
  66. *
  67. * @return integer
  68. */
  69. public function getOnQuerySleep()
  70. {
  71. return $this->_onQuerySleep;
  72. }
  73. /**
  74. * Check for config options that are mandatory.
  75. * Throw exceptions if any are missing.
  76. *
  77. * @param array $config
  78. * @throws Zend_Db_Adapter_Exception
  79. */
  80. protected function _checkRequiredOptions(array $config)
  81. {
  82. // we need at least a dbname
  83. if (! array_key_exists('dbname', $config)) {
  84. require_once 'Zend/Db/Adapter/Exception.php';
  85. throw new Zend_Db_Adapter_Exception("Configuration must have a key for 'dbname' that names the database instance");
  86. }
  87. $this->config = $config;
  88. }
  89. /**
  90. * Prepares and executes a SQL statement with bound data.
  91. *
  92. * @param string|Zend_Db_Select $sql The SQL statement with placeholders.
  93. * @param mixed $bind An array of data to bind to the placeholders.
  94. * @return Zend_Db_Statement (may also be PDOStatement in the case of PDO)
  95. */
  96. public function query($sql, $bind = array())
  97. {
  98. // connect to the database if needed
  99. $this->_connect();
  100. // is the $sql a Zend_Db_Select object?
  101. if ($sql instanceof Zend_Db_Select) {
  102. $sql = $sql->__toString();
  103. }
  104. // make sure $bind to an array;
  105. // don't use (array) typecasting because
  106. // because $bind may be a Zend_Db_Expr object
  107. if (!is_array($bind)) {
  108. $bind = array($bind);
  109. }
  110. // prepare and execute the statement with profiling
  111. $stmt = $this->prepare($sql);
  112. $q = $this->_profiler->queryStart($sql);
  113. if ($this->_onQuerySleep > 0) {
  114. sleep($this->_onQuerySleep);
  115. }
  116. $stmt->execute($bind);
  117. $this->_profiler->queryEnd($q);
  118. // return the results embedded in the prepared statement object
  119. $stmt->setFetchMode($this->_fetchMode);
  120. return $stmt;
  121. }
  122. /**
  123. * Returns a list of the tables in the database.
  124. *
  125. * @return array
  126. */
  127. public function listTables()
  128. {
  129. return array('dummy');
  130. }
  131. /**
  132. * Returns the column descriptions for a table.
  133. *
  134. * The return value is an associative array keyed by the column name,
  135. * as returned by the RDBMS.
  136. *
  137. * The value of each array element is an associative array
  138. * with the following keys:
  139. *
  140. * SCHEMA_NAME => string; name of database or schema
  141. * TABLE_NAME => string;
  142. * COLUMN_NAME => string; column name
  143. * COLUMN_POSITION => number; ordinal position of column in table
  144. * DATA_TYPE => string; SQL datatype name of column
  145. * DEFAULT => string; default expression of column, null if none
  146. * NULLABLE => boolean; true if column can have nulls
  147. * LENGTH => number; length of CHAR/VARCHAR
  148. * SCALE => number; scale of NUMERIC/DECIMAL
  149. * PRECISION => number; precision of NUMERIC/DECIMAL
  150. * UNSIGNED => boolean; unsigned property of an integer type
  151. * PRIMARY => boolean; true if column is part of the primary key
  152. * PRIMARY_POSITION => integer; position of column in primary key
  153. *
  154. * @param string $tableName
  155. * @param string $schemaName OPTIONAL
  156. * @return array
  157. */
  158. public function describeTable($tableName, $schemaName = null)
  159. {
  160. return array(
  161. 'SCHEMA_NAME' => $schemaName,
  162. 'TABLE_NAME' => $tableName,
  163. 'COLUMN_NAME' => null,
  164. 'COLUMN_POSITION' => null,
  165. 'DATA_TYPE' => null,
  166. 'DEFAULT' => null,
  167. 'NULLABLE' => null,
  168. 'LENGTH' => null,
  169. 'SCALE' => null,
  170. 'PRECISION' => null,
  171. 'UNSIGNED' => null,
  172. 'PRIMARY' => null,
  173. 'PRIMARY_POSITION' => null,
  174. );
  175. }
  176. /**
  177. * Creates a connection to the database.
  178. *
  179. * @return void
  180. */
  181. protected function _connect()
  182. {
  183. $this->_connection = $this;
  184. return;
  185. }
  186. /**
  187. * Test if a connection is active
  188. *
  189. * @return boolean
  190. */
  191. public function isConnected()
  192. {
  193. return ((bool) (!is_null($this->_connection)));
  194. }
  195. /**
  196. * Force the connection to close.
  197. *
  198. * @return void
  199. */
  200. public function closeConnection()
  201. {
  202. $this->_connection = null;
  203. }
  204. /**
  205. * Prepare a statement and return a PDOStatement-like object.
  206. *
  207. * @param string|Zend_Db_Select $sql SQL query
  208. * @return Zend_Db_Statment_Static
  209. */
  210. public function prepare($sql)
  211. {
  212. return new Zend_Db_Statement_Static();
  213. }
  214. /**
  215. * Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
  216. *
  217. * As a convention, on RDBMS brands that support sequences
  218. * (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
  219. * from the arguments and returns the last id generated by that sequence.
  220. * On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
  221. * returns the last value generated for such a column, and the table name
  222. * argument is disregarded.
  223. *
  224. * @param string $tableName OPTIONAL Name of table.
  225. * @param string $primaryKey OPTIONAL Name of primary key column.
  226. * @return integer
  227. */
  228. public function lastInsertId($tableName = null, $primaryKey = 'id')
  229. {
  230. return null;
  231. }
  232. /**
  233. * Begin a transaction.
  234. */
  235. protected function _beginTransaction()
  236. {
  237. return true;
  238. }
  239. /**
  240. * Commit a transaction.
  241. */
  242. protected function _commit()
  243. {
  244. return true;
  245. }
  246. /**
  247. * Roll-back a transaction.
  248. */
  249. protected function _rollBack()
  250. {
  251. return true;
  252. }
  253. /**
  254. * Set the fetch mode.
  255. *
  256. * @param integer $mode
  257. */
  258. public function setFetchMode($mode)
  259. {
  260. return;
  261. }
  262. /**
  263. * Adds an adapter-specific LIMIT clause to the SELECT statement.
  264. *
  265. * @param mixed $sql
  266. * @param integer $count
  267. * @param integer $offset
  268. * @return string
  269. */
  270. public function limit($sql, $count, $offset = 0)
  271. {
  272. return $sql . " LIMIT $count OFFSET $offset";
  273. }
  274. /**
  275. * Check if the adapter supports real SQL parameters.
  276. *
  277. * @param string $type
  278. * @return bool
  279. */
  280. public function supportsParameters($type)
  281. {
  282. return true;
  283. }
  284. /**
  285. * Retrieve server version in PHP style
  286. *
  287. * @return string
  288. */
  289. public function getServerVersion() {
  290. return "5.6.7.8";
  291. }
  292. }