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

/ railoapacheportable/php/PEAR/MDB2/Driver/ibase.php

http://railoapacheportable.googlecode.com/
PHP | 1480 lines | 918 code | 115 blank | 447 comment | 183 complexity | 6bc9cb90113fe68e8bbca26c41c4407d MD5 | raw file
Possible License(s): BSD-2-Clause, Apache-2.0, EPL-1.0, LGPL-3.0, GPL-3.0, AGPL-1.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-2.1, BSD-3-Clause, AGPL-3.0, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // vim: set et ts=4 sw=4 fdm=marker:
  3. // +----------------------------------------------------------------------+
  4. // | PHP versions 4 and 5 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
  7. // | Stig. S. Bakken, Lukas Smith, Lorenzo Alberton |
  8. // | All rights reserved. |
  9. // +----------------------------------------------------------------------+
  10. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
  11. // | API as well as database abstraction for PHP applications. |
  12. // | This LICENSE is in the BSD license style. |
  13. // | |
  14. // | Redistribution and use in source and binary forms, with or without |
  15. // | modification, are permitted provided that the following conditions |
  16. // | are met: |
  17. // | |
  18. // | Redistributions of source code must retain the above copyright |
  19. // | notice, this list of conditions and the following disclaimer. |
  20. // | |
  21. // | Redistributions in binary form must reproduce the above copyright |
  22. // | notice, this list of conditions and the following disclaimer in the |
  23. // | documentation and/or other materials provided with the distribution. |
  24. // | |
  25. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
  26. // | Lukas Smith nor the names of his contributors may be used to endorse |
  27. // | or promote products derived from this software without specific prior|
  28. // | written permission. |
  29. // | |
  30. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  31. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  32. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
  33. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
  34. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
  35. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  36. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  37. // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
  38. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  39. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  40. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
  41. // | POSSIBILITY OF SUCH DAMAGE. |
  42. // +----------------------------------------------------------------------+
  43. // | Author: Lorenzo Alberton <l.alberton@quipo.it> |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: ibase.php,v 1.205 2007/05/03 11:56:58 quipo Exp $
  47. /**
  48. * MDB2 FireBird/InterBase driver
  49. *
  50. * @package MDB2
  51. * @category Database
  52. * @author Lorenzo Alberton <l.alberton@quipo.it>
  53. */
  54. class MDB2_Driver_ibase extends MDB2_Driver_Common
  55. {
  56. // {{{ properties
  57. var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => "'", 'escape_pattern' => '\\');
  58. var $identifier_quoting = array('start' => '', 'end' => '', 'escape' => false);
  59. var $transaction_id = 0;
  60. var $query_parameters = array();
  61. var $query_parameter_values = array();
  62. // }}}
  63. // {{{ constructor
  64. /**
  65. * Constructor
  66. */
  67. function __construct()
  68. {
  69. parent::__construct();
  70. $this->phptype = 'ibase';
  71. $this->dbsyntax = 'ibase';
  72. $this->supported['sequences'] = true;
  73. $this->supported['indexes'] = true;
  74. $this->supported['affected_rows'] = function_exists('ibase_affected_rows');
  75. $this->supported['summary_functions'] = true;
  76. $this->supported['order_by_text'] = true;
  77. $this->supported['transactions'] = true;
  78. $this->supported['savepoints'] = true;
  79. $this->supported['current_id'] = true;
  80. $this->supported['limit_queries'] = 'emulated';
  81. $this->supported['LOBs'] = true;
  82. $this->supported['replace'] = false;
  83. $this->supported['sub_selects'] = true;
  84. $this->supported['auto_increment'] = true;
  85. $this->supported['primary_key'] = true;
  86. $this->supported['result_introspection'] = true;
  87. $this->supported['prepared_statements'] = true;
  88. $this->supported['identifier_quoting'] = false;
  89. $this->supported['pattern_escaping'] = true;
  90. $this->supported['new_link'] = false;
  91. $this->options['DBA_username'] = false;
  92. $this->options['DBA_password'] = false;
  93. $this->options['database_path'] = '';
  94. $this->options['database_extension'] = '.gdb';
  95. $this->options['server_version'] = '';
  96. }
  97. // }}}
  98. // {{{ errorInfo()
  99. /**
  100. * This method is used to collect information about an error
  101. *
  102. * @param integer $error
  103. * @return array
  104. * @access public
  105. */
  106. function errorInfo($error = null)
  107. {
  108. $native_msg = @ibase_errmsg();
  109. if (function_exists('ibase_errcode')) {
  110. $native_code = @ibase_errcode();
  111. } else {
  112. // memo for the interbase php module hackers: we need something similar
  113. // to mysql_errno() to retrieve error codes instead of this ugly hack
  114. if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_msg, $m)) {
  115. $native_code = (int)$m[2];
  116. } else {
  117. $native_code = null;
  118. }
  119. }
  120. if (is_null($error)) {
  121. $error = MDB2_ERROR;
  122. if ($native_code) {
  123. // try to interpret Interbase error code (that's why we need ibase_errno()
  124. // in the interbase module to return the real error code)
  125. switch ($native_code) {
  126. case -204:
  127. if (isset($m[3]) && is_int(strpos($m[3], 'Table unknown'))) {
  128. $errno = MDB2_ERROR_NOSUCHTABLE;
  129. }
  130. break;
  131. default:
  132. static $ecode_map;
  133. if (empty($ecode_map)) {
  134. $ecode_map = array(
  135. -104 => MDB2_ERROR_SYNTAX,
  136. -150 => MDB2_ERROR_ACCESS_VIOLATION,
  137. -151 => MDB2_ERROR_ACCESS_VIOLATION,
  138. -155 => MDB2_ERROR_NOSUCHTABLE,
  139. -157 => MDB2_ERROR_NOSUCHFIELD,
  140. -158 => MDB2_ERROR_VALUE_COUNT_ON_ROW,
  141. -170 => MDB2_ERROR_MISMATCH,
  142. -171 => MDB2_ERROR_MISMATCH,
  143. -172 => MDB2_ERROR_INVALID,
  144. // -204 => // Covers too many errors, need to use regex on msg
  145. -205 => MDB2_ERROR_NOSUCHFIELD,
  146. -206 => MDB2_ERROR_NOSUCHFIELD,
  147. -208 => MDB2_ERROR_INVALID,
  148. -219 => MDB2_ERROR_NOSUCHTABLE,
  149. -297 => MDB2_ERROR_CONSTRAINT,
  150. -303 => MDB2_ERROR_INVALID,
  151. -413 => MDB2_ERROR_INVALID_NUMBER,
  152. -530 => MDB2_ERROR_CONSTRAINT,
  153. -551 => MDB2_ERROR_ACCESS_VIOLATION,
  154. -552 => MDB2_ERROR_ACCESS_VIOLATION,
  155. // -607 => // Covers too many errors, need to use regex on msg
  156. -625 => MDB2_ERROR_CONSTRAINT_NOT_NULL,
  157. -803 => MDB2_ERROR_CONSTRAINT,
  158. -804 => MDB2_ERROR_VALUE_COUNT_ON_ROW,
  159. // -902 => // Covers too many errors, need to use regex on msg
  160. -904 => MDB2_ERROR_CONNECT_FAILED,
  161. -922 => MDB2_ERROR_NOSUCHDB,
  162. -923 => MDB2_ERROR_CONNECT_FAILED,
  163. -924 => MDB2_ERROR_CONNECT_FAILED
  164. );
  165. }
  166. if (isset($ecode_map[$native_code])) {
  167. $error = $ecode_map[$native_code];
  168. }
  169. break;
  170. }
  171. } else {
  172. static $error_regexps;
  173. if (!isset($error_regexps)) {
  174. $error_regexps = array(
  175. '/generator .* is not defined/'
  176. => MDB2_ERROR_SYNTAX, // for compat. w ibase_errcode()
  177. '/table.*(not exist|not found|unknown)/i'
  178. => MDB2_ERROR_NOSUCHTABLE,
  179. '/table .* already exists/i'
  180. => MDB2_ERROR_ALREADY_EXISTS,
  181. '/unsuccessful metadata update .* failed attempt to store duplicate value/i'
  182. => MDB2_ERROR_ALREADY_EXISTS,
  183. '/unsuccessful metadata update .* not found/i'
  184. => MDB2_ERROR_NOT_FOUND,
  185. '/validation error for column .* value "\*\*\* null/i'
  186. => MDB2_ERROR_CONSTRAINT_NOT_NULL,
  187. '/violation of [\w ]+ constraint/i'
  188. => MDB2_ERROR_CONSTRAINT,
  189. '/conversion error from string/i'
  190. => MDB2_ERROR_INVALID_NUMBER,
  191. '/no permission for/i'
  192. => MDB2_ERROR_ACCESS_VIOLATION,
  193. '/arithmetic exception, numeric overflow, or string truncation/i'
  194. => MDB2_ERROR_INVALID,
  195. '/feature is not supported/i'
  196. => MDB2_ERROR_NOT_CAPABLE,
  197. );
  198. }
  199. foreach ($error_regexps as $regexp => $code) {
  200. if (preg_match($regexp, $native_msg, $m)) {
  201. $error = $code;
  202. break;
  203. }
  204. }
  205. }
  206. }
  207. return array($error, $native_code, $native_msg);
  208. }
  209. // }}}
  210. // {{{ quoteIdentifier()
  211. /**
  212. * Delimited identifiers are a nightmare with InterBase, so they're disabled
  213. *
  214. * @param string $str identifier name to be quoted
  215. * @param bool $check_option check the 'quote_identifier' option
  216. *
  217. * @return string quoted identifier string
  218. *
  219. * @access public
  220. */
  221. function quoteIdentifier($str, $check_option = false)
  222. {
  223. if ($check_option && !$this->options['quote_identifier']) {
  224. return $str;
  225. }
  226. return strtoupper($str);
  227. }
  228. // }}}
  229. // {{{ getConnection()
  230. /**
  231. * Returns a native connection
  232. *
  233. * @return mixed a valid MDB2 connection object,
  234. * or a MDB2 error object on error
  235. * @access public
  236. */
  237. function getConnection()
  238. {
  239. $result = $this->connect();
  240. if (PEAR::isError($result)) {
  241. return $result;
  242. }
  243. if ($this->in_transaction) {
  244. return $this->transaction_id;
  245. }
  246. return $this->connection;
  247. }
  248. // }}}
  249. // {{{ beginTransaction()
  250. /**
  251. * Start a transaction or set a savepoint.
  252. *
  253. * @param string name of a savepoint to set
  254. * @return mixed MDB2_OK on success, a MDB2 error on failure
  255. *
  256. * @access public
  257. */
  258. function beginTransaction($savepoint = null)
  259. {
  260. $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
  261. if (!is_null($savepoint)) {
  262. if (!$this->in_transaction) {
  263. return $this->raiseError(MDB2_ERROR_INVALID, null, null,
  264. 'savepoint cannot be released when changes are auto committed', __FUNCTION__);
  265. }
  266. $query = 'SAVEPOINT '.$savepoint;
  267. return $this->_doQuery($query, true);
  268. } elseif ($this->in_transaction) {
  269. return MDB2_OK; //nothing to do
  270. }
  271. $connection = $this->getConnection();
  272. if (PEAR::isError($connection)) {
  273. return $connection;
  274. }
  275. $result = @ibase_trans(IBASE_DEFAULT, $connection);
  276. if (!$result) {
  277. return $this->raiseError(null, null, null,
  278. 'could not start a transaction', __FUNCTION__);
  279. }
  280. $this->transaction_id = $result;
  281. $this->in_transaction = true;
  282. return MDB2_OK;
  283. }
  284. // }}}
  285. // {{{ commit()
  286. /**
  287. * Commit the database changes done during a transaction that is in
  288. * progress or release a savepoint. This function may only be called when
  289. * auto-committing is disabled, otherwise it will fail. Therefore, a new
  290. * transaction is implicitly started after committing the pending changes.
  291. *
  292. * @param string name of a savepoint to release
  293. * @return mixed MDB2_OK on success, a MDB2 error on failure
  294. *
  295. * @access public
  296. */
  297. function commit($savepoint = null)
  298. {
  299. $this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
  300. if (!$this->in_transaction) {
  301. return $this->raiseError(MDB2_ERROR_INVALID, null, null,
  302. 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
  303. }
  304. if (!is_null($savepoint)) {
  305. $query = 'RELEASE SAVEPOINT '.$savepoint;
  306. return $this->_doQuery($query, true);
  307. }
  308. if (!@ibase_commit($this->transaction_id)) {
  309. return $this->raiseError(null, null, null,
  310. 'could not commit a transaction', __FUNCTION__);
  311. }
  312. $this->in_transaction = false;
  313. $this->transaction_id = 0;
  314. return MDB2_OK;
  315. }
  316. // }}}
  317. // {{{ rollback()
  318. /**
  319. * Cancel any database changes done during a transaction or since a specific
  320. * savepoint that is in progress. This function may only be called when
  321. * auto-committing is disabled, otherwise it will fail. Therefore, a new
  322. * transaction is implicitly started after canceling the pending changes.
  323. *
  324. * @param string name of a savepoint to rollback to
  325. * @return mixed MDB2_OK on success, a MDB2 error on failure
  326. *
  327. * @access public
  328. */
  329. function rollback($savepoint = null)
  330. {
  331. $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
  332. if (!$this->in_transaction) {
  333. return $this->raiseError(MDB2_ERROR_INVALID, null, null,
  334. 'rollback cannot be done changes are auto committed', __FUNCTION__);
  335. }
  336. if (!is_null($savepoint)) {
  337. $query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
  338. return $this->_doQuery($query, true);
  339. }
  340. if ($this->transaction_id && !@ibase_rollback($this->transaction_id)) {
  341. return $this->raiseError(null, null, null,
  342. 'Could not rollback a pending transaction: '.@ibase_errmsg(), __FUNCTION__);
  343. }
  344. $this->in_transaction = false;
  345. $this->transaction_id = 0;
  346. return MDB2_OK;
  347. }
  348. // }}}
  349. // {{{ setTransactionIsolation()
  350. /**
  351. * Set the transacton isolation level.
  352. *
  353. * @param string standard isolation level (SQL-92)
  354. * READ UNCOMMITTED (allows dirty reads)
  355. * READ COMMITTED (prevents dirty reads)
  356. * REPEATABLE READ (prevents nonrepeatable reads)
  357. * SERIALIZABLE (prevents phantom reads)
  358. * @param array some transaction options:
  359. * 'wait' => 'WAIT' | 'NO WAIT'
  360. * 'rw' => 'READ WRITE' | 'READ ONLY'
  361. * @return mixed MDB2_OK on success, a MDB2 error on failure
  362. *
  363. * @access public
  364. * @since 2.1.1
  365. */
  366. function setTransactionIsolation($isolation, $options = array())
  367. {
  368. $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
  369. switch ($isolation) {
  370. case 'READ UNCOMMITTED':
  371. $ibase_isolation = 'READ COMMITTED RECORD_VERSION';
  372. break;
  373. case 'READ COMMITTED':
  374. $ibase_isolation = 'READ COMMITTED NO RECORD_VERSION';
  375. break;
  376. case 'REPEATABLE READ':
  377. $ibase_isolation = 'SNAPSHOT';
  378. break;
  379. case 'SERIALIZABLE':
  380. $ibase_isolation = 'SNAPSHOT TABLE STABILITY';
  381. break;
  382. default:
  383. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
  384. 'isolation level is not supported: '.$isolation, __FUNCTION__);
  385. }
  386. if (!empty($options['wait'])) {
  387. switch ($options['wait']) {
  388. case 'WAIT':
  389. case 'NO WAIT':
  390. $wait = $options['wait'];
  391. break;
  392. default:
  393. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
  394. 'wait option is not supported: '.$options['wait'], __FUNCTION__);
  395. }
  396. }
  397. if (!empty($options['rw'])) {
  398. switch ($options['rw']) {
  399. case 'READ ONLY':
  400. case 'READ WRITE':
  401. $rw = $options['wait'];
  402. break;
  403. default:
  404. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
  405. 'wait option is not supported: '.$options['rw'], __FUNCTION__);
  406. }
  407. }
  408. $query = "SET TRANSACTION $rw $wait ISOLATION LEVEL $ibase_isolation";
  409. return $this->_doQuery($query, true);
  410. }
  411. // }}}
  412. // {{{ getDatabaseFile($database_name)
  413. /**
  414. * Builds the string with path+dbname+extension
  415. *
  416. * @return string full database path+file
  417. * @access protected
  418. */
  419. function _getDatabaseFile($database_name)
  420. {
  421. if ($database_name == '') {
  422. return $database_name;
  423. }
  424. $ret = $this->options['database_path'] . $database_name;
  425. if (!preg_match('/\.[fg]db$/i', $database_name)) {
  426. $ret .= $this->options['database_extension'];
  427. }
  428. return $ret;
  429. }
  430. // }}}
  431. // {{{ _doConnect()
  432. /**
  433. * Does the grunt work of connecting to the database
  434. *
  435. * @return mixed connection resource on success, MDB2 Error Object on failure
  436. * @access protected
  437. */
  438. function _doConnect($database_name, $persistent = false)
  439. {
  440. $user = $this->dsn['username'];
  441. $pw = $this->dsn['password'];
  442. $dbhost = $this->dsn['hostspec'] ?
  443. ($this->dsn['hostspec'].':'.$database_name) : $database_name;
  444. $params = array();
  445. $params[] = $dbhost;
  446. $params[] = !empty($user) ? $user : null;
  447. $params[] = !empty($pw) ? $pw : null;
  448. $params[] = isset($this->dsn['charset']) ? $this->dsn['charset'] : null;
  449. $params[] = isset($this->dsn['buffers']) ? $this->dsn['buffers'] : null;
  450. $params[] = isset($this->dsn['dialect']) ? $this->dsn['dialect'] : null;
  451. $params[] = isset($this->dsn['role']) ? $this->dsn['role'] : null;
  452. $connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect';
  453. $connection = @call_user_func_array($connect_function, $params);
  454. if ($connection <= 0) {
  455. return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
  456. 'unable to establish a connection', __FUNCTION__);
  457. }
  458. if (empty($this->dsn['disable_iso_date'])) {
  459. if (function_exists('ibase_timefmt')) {
  460. @ibase_timefmt("%Y-%m-%d %H:%M:%S", IBASE_TIMESTAMP);
  461. @ibase_timefmt("%Y-%m-%d", IBASE_DATE);
  462. } else {
  463. @ini_set("ibase.timestampformat", "%Y-%m-%d %H:%M:%S");
  464. //@ini_set("ibase.timeformat", "%H:%M:%S");
  465. @ini_set("ibase.dateformat", "%Y-%m-%d");
  466. }
  467. }
  468. return $connection;
  469. }
  470. // }}}
  471. // {{{ connect()
  472. /**
  473. * Connect to the database
  474. *
  475. * @return true on success, MDB2 Error Object on failure
  476. * @access public
  477. */
  478. function connect()
  479. {
  480. $database_file = $this->_getDatabaseFile($this->database_name);
  481. if (is_resource($this->connection)) {
  482. if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
  483. && $this->connected_database_name == $database_file
  484. && $this->opened_persistent == $this->options['persistent']
  485. ) {
  486. return MDB2_OK;
  487. }
  488. $this->disconnect(false);
  489. }
  490. if (!PEAR::loadExtension('interbase')) {
  491. return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  492. 'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
  493. }
  494. if (!empty($this->database_name)) {
  495. $connection = $this->_doConnect($database_file, $this->options['persistent']);
  496. if (PEAR::isError($connection)) {
  497. return $connection;
  498. }
  499. $this->connection =& $connection;
  500. $this->connected_dsn = $this->dsn;
  501. $this->connected_database_name = $database_file;
  502. $this->opened_persistent = $this->options['persistent'];
  503. $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
  504. $this->supported['limit_queries'] = ($this->dbsyntax == 'firebird') ? true : 'emulated';
  505. }
  506. return MDB2_OK;
  507. }
  508. // }}}
  509. // {{{ setCharset()
  510. /**
  511. * Set the charset on the current connection
  512. *
  513. * @param string charset
  514. * @param resource connection handle
  515. *
  516. * @return true on success, MDB2 Error Object on failure
  517. */
  518. function setCharset($charset, $connection = null)
  519. {
  520. if (is_null($connection)) {
  521. $connection = $this->getConnection();
  522. if (PEAR::isError($connection)) {
  523. return $connection;
  524. }
  525. }
  526. $query = 'SET NAMES '.$this->quote($charset, 'text');
  527. $result = @ibase_query($connection, $query);
  528. if (!$result) {
  529. return $this->raiseError(null, null, null,
  530. 'Unable to set client charset: '.$charset, __FUNCTION__);
  531. }
  532. return MDB2_OK;
  533. }
  534. // }}}
  535. // {{{ disconnect()
  536. /**
  537. * Log out and disconnect from the database.
  538. *
  539. * @param boolean $force if the disconnect should be forced even if the
  540. * connection is opened persistently
  541. * @return mixed true on success, false if not connected and error
  542. * object on error
  543. * @access public
  544. */
  545. function disconnect($force = true)
  546. {
  547. if (is_resource($this->connection)) {
  548. if ($this->in_transaction) {
  549. $dsn = $this->dsn;
  550. $database_name = $this->database_name;
  551. $persistent = $this->options['persistent'];
  552. $this->dsn = $this->connected_dsn;
  553. $this->database_name = $this->connected_database_name;
  554. $this->options['persistent'] = $this->opened_persistent;
  555. $this->rollback();
  556. $this->dsn = $dsn;
  557. $this->database_name = $database_name;
  558. $this->options['persistent'] = $persistent;
  559. }
  560. if (!$this->opened_persistent || $force) {
  561. @ibase_close($this->connection);
  562. }
  563. }
  564. return parent::disconnect($force);
  565. }
  566. // }}}
  567. // {{{ _doQuery()
  568. /**
  569. * Execute a query
  570. * @param string $query query
  571. * @param boolean $is_manip if the query is a manipulation query
  572. * @param resource $connection
  573. * @param string $database_name
  574. * @return result or error object
  575. * @access protected
  576. */
  577. function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
  578. {
  579. $this->last_query = $query;
  580. $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
  581. if ($result) {
  582. if (PEAR::isError($result)) {
  583. return $result;
  584. }
  585. $query = $result;
  586. }
  587. if ($this->getOption('disable_query')) {
  588. if ($is_manip) {
  589. return 0;
  590. }
  591. return null;
  592. }
  593. if (is_null($connection)) {
  594. $connection = $this->getConnection();
  595. if (PEAR::isError($connection)) {
  596. return $connection;
  597. }
  598. }
  599. $result = @ibase_query($connection, $query);
  600. if ($result === false) {
  601. $err =& $this->raiseError(null, null, null,
  602. 'Could not execute statement', __FUNCTION__);
  603. return $err;
  604. }
  605. $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'post', 'result' => $result));
  606. return $result;
  607. }
  608. // }}}
  609. // {{{ _affectedRows()
  610. /**
  611. * Returns the number of rows affected
  612. *
  613. * @param resource $result
  614. * @param resource $connection
  615. * @return mixed MDB2 Error Object or the number of rows affected
  616. * @access private
  617. */
  618. function _affectedRows($connection, $result = null)
  619. {
  620. if (is_null($connection)) {
  621. $connection = $this->getConnection();
  622. if (PEAR::isError($connection)) {
  623. return $connection;
  624. }
  625. }
  626. return (function_exists('ibase_affected_rows') ? @ibase_affected_rows($connection) : 0);
  627. }
  628. // }}}
  629. // {{{ _modifyQuery()
  630. /**
  631. * Changes a query string for various DBMS specific reasons
  632. *
  633. * @param string $query query to modify
  634. * @param boolean $is_manip if it is a DML query
  635. * @param integer $limit limit the number of rows
  636. * @param integer $offset start reading from given offset
  637. * @return string modified query
  638. * @access protected
  639. */
  640. function _modifyQuery($query, $is_manip, $limit, $offset)
  641. {
  642. if ($limit > 0 && $this->supports('limit_queries') === true) {
  643. $query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
  644. "SELECT FIRST $limit SKIP $offset", $query);
  645. }
  646. return $query;
  647. }
  648. // }}}
  649. // {{{ getServerVersion()
  650. /**
  651. * return version information about the server
  652. *
  653. * @param bool $native determines if the raw version string should be returned
  654. * @return mixed array/string with version information or MDB2 error object
  655. * @access public
  656. */
  657. function getServerVersion($native = false)
  658. {
  659. $server_info = false;
  660. if ($this->connected_server_info) {
  661. $server_info = $this->connected_server_info;
  662. } elseif ($this->options['server_version']) {
  663. $server_info = $this->options['server_version'];
  664. } elseif ($this->options['DBA_username']) {
  665. $ibserv = @ibase_service_attach($this->dsn['hostspec'], $this->options['DBA_username'], $this->options['DBA_password']);
  666. $server_info = @ibase_server_info($ibserv, IBASE_SVC_SERVER_VERSION);
  667. @ibase_service_detach($ibserv);
  668. }
  669. if (!$server_info) {
  670. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
  671. 'Requires either "server_version" or "DBA_username"/"DBA_password" option', __FUNCTION__);
  672. }
  673. // cache server_info
  674. $this->connected_server_info = $server_info;
  675. if (!$native) {
  676. //WI-V1.5.3.4854 Firebird 1.5
  677. if (!preg_match('/-V([\d\.]*)/', $server_info, $matches)) {
  678. return $this->raiseError(MDB2_ERROR_INVALID, null, null,
  679. 'Could not parse version information:'.$server_info, __FUNCTION__);
  680. }
  681. $tmp = explode('.', $matches[1], 4);
  682. $server_info = array(
  683. 'major' => isset($tmp[0]) ? $tmp[0] : null,
  684. 'minor' => isset($tmp[1]) ? $tmp[1] : null,
  685. 'patch' => isset($tmp[2]) ? $tmp[2] : null,
  686. 'extra' => isset($tmp[3]) ? $tmp[3] : null,
  687. 'native' => $server_info,
  688. );
  689. }
  690. return $server_info;
  691. }
  692. // }}}
  693. // {{{ prepare()
  694. /**
  695. * Prepares a query for multiple execution with execute().
  696. * With some database backends, this is emulated.
  697. * prepare() requires a generic query as string like
  698. * 'INSERT INTO numbers VALUES(?,?)' or
  699. * 'INSERT INTO numbers VALUES(:foo,:bar)'.
  700. * The ? and :[a-zA-Z] and are placeholders which can be set using
  701. * bindParam() and the query can be send off using the execute() method.
  702. *
  703. * @param string $query the query to prepare
  704. * @param mixed $types array that contains the types of the placeholders
  705. * @param mixed $result_types array that contains the types of the columns in
  706. * the result set or MDB2_PREPARE_RESULT, if set to
  707. * MDB2_PREPARE_MANIP the query is handled as a manipulation query
  708. * @param mixed $lobs key (field) value (parameter) pair for all lob placeholders
  709. * @return mixed resource handle for the prepared query on success, a MDB2
  710. * error on failure
  711. * @access public
  712. * @see bindParam, execute
  713. */
  714. function &prepare($query, $types = null, $result_types = null, $lobs = array())
  715. {
  716. if ($this->options['emulate_prepared']) {
  717. $obj =& parent::prepare($query, $types, $result_types, $lobs);
  718. return $obj;
  719. }
  720. $is_manip = ($result_types === MDB2_PREPARE_MANIP);
  721. $offset = $this->offset;
  722. $limit = $this->limit;
  723. $this->offset = $this->limit = 0;
  724. $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
  725. if ($result) {
  726. if (PEAR::isError($result)) {
  727. return $result;
  728. }
  729. $query = $result;
  730. }
  731. $placeholder_type_guess = $placeholder_type = null;
  732. $question = '?';
  733. $colon = ':';
  734. $positions = array();
  735. $position = 0;
  736. while ($position < strlen($query)) {
  737. $q_position = strpos($query, $question, $position);
  738. $c_position = strpos($query, $colon, $position);
  739. if ($q_position && $c_position) {
  740. $p_position = min($q_position, $c_position);
  741. } elseif ($q_position) {
  742. $p_position = $q_position;
  743. } elseif ($c_position) {
  744. $p_position = $c_position;
  745. } else {
  746. break;
  747. }
  748. if (is_null($placeholder_type)) {
  749. $placeholder_type_guess = $query[$p_position];
  750. }
  751. $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
  752. if (PEAR::isError($new_pos)) {
  753. return $new_pos;
  754. }
  755. if ($new_pos != $position) {
  756. $position = $new_pos;
  757. continue; //evaluate again starting from the new position
  758. }
  759. if ($query[$position] == $placeholder_type_guess) {
  760. if (is_null($placeholder_type)) {
  761. $placeholder_type = $query[$p_position];
  762. $question = $colon = $placeholder_type;
  763. }
  764. if ($placeholder_type == ':') {
  765. $parameter = preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si', '\\1', $query);
  766. if ($parameter === '') {
  767. $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
  768. 'named parameter with an empty name', __FUNCTION__);
  769. return $err;
  770. }
  771. $positions[] = $parameter;
  772. $query = substr_replace($query, '?', $position, strlen($parameter)+1);
  773. } else {
  774. $positions[] = count($positions);
  775. }
  776. $position = $p_position + 1;
  777. } else {
  778. $position = $p_position;
  779. }
  780. }
  781. $connection = $this->getConnection();
  782. if (PEAR::isError($connection)) {
  783. return $connection;
  784. }
  785. $statement = @ibase_prepare($connection, $query);
  786. if (!$statement) {
  787. $err =& $this->raiseError(null, null, null,
  788. 'Could not create statement', __FUNCTION__);
  789. return $err;
  790. }
  791. $class_name = 'MDB2_Statement_'.$this->phptype;
  792. $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
  793. $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
  794. return $obj;
  795. }
  796. // }}}
  797. // {{{ getSequenceName()
  798. /**
  799. * adds sequence name formatting to a sequence name
  800. *
  801. * @param string $sqn name of the sequence
  802. * @return string formatted sequence name
  803. * @access public
  804. */
  805. function getSequenceName($sqn)
  806. {
  807. return strtoupper(parent::getSequenceName($sqn));
  808. }
  809. // }}}
  810. // {{{ nextID()
  811. /**
  812. * Returns the next free id of a sequence
  813. *
  814. * @param string $seq_name name of the sequence
  815. * @param boolean $ondemand when true the sequence is
  816. * automatic created, if it
  817. * not exists
  818. * @return mixed MDB2 Error Object or id
  819. * @access public
  820. */
  821. function nextID($seq_name, $ondemand = true)
  822. {
  823. $sequence_name = $this->getSequenceName($seq_name);
  824. $query = 'SELECT GEN_ID('.$sequence_name.', 1) as the_value FROM RDB$DATABASE';
  825. $this->expectError('*');
  826. $result = $this->queryOne($query, 'integer');
  827. $this->popExpect();
  828. if (PEAR::isError($result)) {
  829. if ($ondemand) {
  830. $this->loadModule('Manager', null, true);
  831. $result = $this->manager->createSequence($seq_name);
  832. if (PEAR::isError($result)) {
  833. return $this->raiseError($result, null, null,
  834. 'on demand sequence could not be created', __FUNCTION__);
  835. } else {
  836. return $this->nextID($seq_name, false);
  837. }
  838. }
  839. }
  840. return $result;
  841. }
  842. // }}}
  843. // {{{ lastInsertID()
  844. /**
  845. * Returns the autoincrement ID if supported or $id or fetches the current
  846. * ID in a sequence called: $table.(empty($field) ? '' : '_'.$field)
  847. *
  848. * @param string $table name of the table into which a new row was inserted
  849. * @param string $field name of the field into which a new row was inserted
  850. * @return mixed MDB2 Error Object or id
  851. * @access public
  852. */
  853. function lastInsertID($table = null, $field = null)
  854. {
  855. $seq = $table.(empty($field) ? '' : '_'.$field);
  856. return $this->currID($seq);
  857. }
  858. // }}}
  859. // {{{ currID()
  860. /**
  861. * Returns the current id of a sequence
  862. *
  863. * @param string $seq_name name of the sequence
  864. * @return mixed MDB2 Error Object or id
  865. * @access public
  866. */
  867. function currID($seq_name)
  868. {
  869. $sequence_name = $this->getSequenceName($seq_name);
  870. $query = 'SELECT GEN_ID('.$sequence_name.', 0) as the_value FROM RDB$DATABASE';
  871. $value = $this->queryOne($query);
  872. if (PEAR::isError($value)) {
  873. return $this->raiseError($value, null, null,
  874. 'Unable to select from ' . $seq_name, __FUNCTION__);
  875. }
  876. if (!is_numeric($value)) {
  877. return $this->raiseError(MDB2_ERROR, null, null,
  878. 'could not find value in sequence table', __FUNCTION__);
  879. }
  880. return $value;
  881. }
  882. // }}}
  883. }
  884. /**
  885. * MDB2 FireBird/InterBase result driver
  886. *
  887. * @package MDB2
  888. * @category Database
  889. * @author Lorenzo Alberton <l.alberton@quipo.it>
  890. */
  891. class MDB2_Result_ibase extends MDB2_Result_Common
  892. {
  893. // {{{ _skipLimitOffset()
  894. /**
  895. * Skip the first row of a result set.
  896. *
  897. * @param resource $result
  898. * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
  899. * @access protected
  900. */
  901. function _skipLimitOffset()
  902. {
  903. if ($this->db->supports('limit_queries') === true) {
  904. return true;
  905. }
  906. if ($this->limit) {
  907. if ($this->rownum > $this->limit) {
  908. return false;
  909. }
  910. }
  911. if ($this->offset) {
  912. while ($this->offset_count < $this->offset) {
  913. ++$this->offset_count;
  914. if (!is_array(@ibase_fetch_row($this->result))) {
  915. $this->offset_count = $this->offset;
  916. return false;
  917. }
  918. }
  919. }
  920. return true;
  921. }
  922. // }}}
  923. // {{{ fetchRow()
  924. /**
  925. * Fetch a row and insert the data into an existing array.
  926. *
  927. * @param int $fetchmode how the array data should be indexed
  928. * @param int $rownum number of the row where the data can be found
  929. * @return int data array on success, a MDB2 error on failure
  930. * @access public
  931. */
  932. function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
  933. {
  934. if ($this->result === true) {
  935. //query successfully executed, but without results...
  936. $null = null;
  937. return $null;
  938. }
  939. if (!$this->_skipLimitOffset()) {
  940. $null = null;
  941. return $null;
  942. }
  943. if (!is_null($rownum)) {
  944. $seek = $this->seek($rownum);
  945. if (PEAR::isError($seek)) {
  946. return $seek;
  947. }
  948. }
  949. if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
  950. $fetchmode = $this->db->fetchmode;
  951. }
  952. if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
  953. $row = @ibase_fetch_assoc($this->result);
  954. if (is_array($row)
  955. && $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
  956. ) {
  957. $row = array_change_key_case($row, $this->db->options['field_case']);
  958. }
  959. } else {
  960. $row = @ibase_fetch_row($this->result);
  961. }
  962. if (!$row) {
  963. if ($this->result === false) {
  964. $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  965. 'resultset has already been freed', __FUNCTION__);
  966. return $err;
  967. }
  968. $null = null;
  969. return $null;
  970. }
  971. $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL;
  972. $rtrim = false;
  973. if ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) {
  974. if (empty($this->types)) {
  975. $mode += MDB2_PORTABILITY_RTRIM;
  976. } else {
  977. $rtrim = true;
  978. }
  979. }
  980. if ($mode) {
  981. $this->db->_fixResultArrayValues($row, $mode);
  982. }
  983. if (!empty($this->types)) {
  984. $row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
  985. }
  986. if (!empty($this->values)) {
  987. $this->_assignBindColumns($row);
  988. }
  989. if ($fetchmode === MDB2_FETCHMODE_OBJECT) {
  990. $object_class = $this->db->options['fetch_class'];
  991. if ($object_class == 'stdClass') {
  992. $row = (object) $row;
  993. } else {
  994. $row = &new $object_class($row);
  995. }
  996. }
  997. ++$this->rownum;
  998. return $row;
  999. }
  1000. // }}}
  1001. // {{{ _getColumnNames()
  1002. /**
  1003. * Retrieve the names of columns returned by the DBMS in a query result.
  1004. *
  1005. * @return mixed Array variable that holds the names of columns as keys
  1006. * or an MDB2 error on failure.
  1007. * Some DBMS may not return any columns when the result set
  1008. * does not contain any rows.
  1009. * @access private
  1010. */
  1011. function _getColumnNames()
  1012. {
  1013. $columns = array();
  1014. $numcols = $this->numCols();
  1015. if (PEAR::isError($numcols)) {
  1016. return $numcols;
  1017. }
  1018. for ($column = 0; $column < $numcols; $column++) {
  1019. $column_info = @ibase_field_info($this->result, $column);
  1020. $columns[$column_info['alias']] = $column;
  1021. }
  1022. if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  1023. $columns = array_change_key_case($columns, $this->db->options['field_case']);
  1024. }
  1025. return $columns;
  1026. }
  1027. // }}}
  1028. // {{{ numCols()
  1029. /**
  1030. * Count the number of columns returned by the DBMS in a query result.
  1031. *
  1032. * @return mixed integer value with the number of columns, a MDB2 error
  1033. * on failure
  1034. * @access public
  1035. */
  1036. function numCols()
  1037. {
  1038. if ($this->result === true) {
  1039. //query successfully executed, but without results...
  1040. return 0;
  1041. }
  1042. if (!is_resource($this->result)) {
  1043. return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  1044. 'numCols(): not a valid ibase resource', __FUNCTION__);
  1045. }
  1046. $cols = @ibase_num_fields($this->result);
  1047. if (is_null($cols)) {
  1048. if ($this->result === false) {
  1049. return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  1050. 'resultset has already been freed', __FUNCTION__);
  1051. } elseif (is_null($this->result)) {
  1052. return count($this->types);
  1053. }
  1054. return $this->db->raiseError(null, null, null,
  1055. 'Could not get column count', __FUNCTION__);
  1056. }
  1057. return $cols;
  1058. }
  1059. // }}}
  1060. // {{{ free()
  1061. /**
  1062. * Free the internal resources associated with $result.
  1063. *
  1064. * @return boolean true on success, false if $result is invalid
  1065. * @access public
  1066. */
  1067. function free()
  1068. {
  1069. if (is_resource($this->result) && $this->db->connection) {
  1070. $free = @ibase_free_result($this->result);
  1071. if ($free === false) {
  1072. return $this->db->raiseError(null, null, null,
  1073. 'Could not free result', __FUNCTION__);
  1074. }
  1075. }
  1076. $this->result = false;
  1077. return MDB2_OK;
  1078. }
  1079. // }}}
  1080. }
  1081. /**
  1082. * MDB2 FireBird/InterBase buffered result driver
  1083. *
  1084. * @package MDB2
  1085. * @category Database
  1086. * @author Lorenzo Alberton <l.alberton@quipo.it>
  1087. */
  1088. class MDB2_BufferedResult_ibase extends MDB2_Result_ibase
  1089. {
  1090. // {{{ class vars
  1091. var $buffer;
  1092. var $buffer_rownum = - 1;
  1093. // }}}
  1094. // {{{ _fillBuffer()
  1095. /**
  1096. * Fill the row buffer
  1097. *
  1098. * @param int $rownum row number upto which the buffer should be filled
  1099. * if the row number is null all rows are ready into the buffer
  1100. * @return boolean true on success, false on failure
  1101. * @access protected
  1102. */
  1103. function _fillBuffer($rownum = null)
  1104. {
  1105. if (isset($this->buffer) && is_array($this->buffer)) {
  1106. if (is_null($rownum)) {
  1107. if (!end($this->buffer)) {
  1108. return false;
  1109. }
  1110. } elseif (isset($this->buffer[$rownum])) {
  1111. return (bool) $this->buffer[$rownum];
  1112. }
  1113. }
  1114. if (!$this->_skipLimitOffset()) {
  1115. return false;
  1116. }
  1117. $buffer = true;
  1118. while ((is_null($rownum) || $this->buffer_rownum < $rownum)
  1119. && (!$this->limit || $this->buffer_rownum < $this->limit)
  1120. && ($buffer = @ibase_fetch_row($this->result))
  1121. ) {
  1122. ++$this->buffer_rownum;
  1123. $this->buffer[$this->buffer_rownum] = $buffer;
  1124. }
  1125. if (!$buffer) {
  1126. ++$this->buffer_rownum;
  1127. $this->buffer[$this->buffer_rownum] = false;
  1128. return false;
  1129. } elseif ($this->limit && $this->buffer_rownum >= $this->limit) {
  1130. ++$this->buffer_rownum;
  1131. $this->buffer[$this->buffer_rownum] = false;
  1132. }
  1133. return true;
  1134. }
  1135. // }}}
  1136. // {{{ fetchRow()
  1137. /**
  1138. * Fetch a row and insert the data into an existing array.
  1139. *
  1140. * @param int $fetchmode how the array data should be indexed
  1141. * @param int $rownum number of the row where the data can be found
  1142. * @return int data array on success, a MDB2 error on failure
  1143. * @access public
  1144. */
  1145. function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
  1146. {
  1147. if ($this->result === true || is_null($this->result)) {
  1148. //query successfully executed, but without results...
  1149. $null = null;
  1150. return $null;
  1151. }
  1152. if ($this->result === false) {
  1153. $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  1154. 'resultset has already been freed', __FUNCTION__);
  1155. return $err;
  1156. }
  1157. if (!is_null($rownum)) {
  1158. $seek = $this->seek($rownum);
  1159. if (PEAR::isError($seek)) {
  1160. return $seek;
  1161. }
  1162. }
  1163. $target_rownum = $this->rownum + 1;
  1164. if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
  1165. $fetchmode = $this->db->fetchmode;
  1166. }
  1167. if (!$this->_fillBuffer($target_rownum)) {
  1168. $null = null;
  1169. return $null;
  1170. }
  1171. $row = $this->buffer[$target_rownum];
  1172. if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
  1173. $column_names = $this->getColumnNames();
  1174. foreach ($column_names as $name => $i) {
  1175. $column_names[$name] = $row[$i];
  1176. }
  1177. $row = $column_names;
  1178. }
  1179. $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL;
  1180. $rtrim = false;
  1181. if ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) {
  1182. if (empty($this->types)) {
  1183. $mode += MDB2_PORTABILITY_RTRIM;
  1184. } else {
  1185. $rtrim = true;
  1186. }
  1187. }
  1188. if ($mode) {
  1189. $this->db->_fixResultArrayValues($row, $mode);
  1190. }
  1191. if (!empty($this->types)) {
  1192. $row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
  1193. }
  1194. if (!empty($this->values)) {
  1195. $this->_assignBindColumns($row);
  1196. }
  1197. if ($fetchmode === MDB2_FETCHMODE_OBJECT) {
  1198. $object_class = $this->db->options['fetch_class'];
  1199. if ($object_class == 'stdClass') {
  1200. $row = (object) $row;
  1201. } else {
  1202. $row = &new $object_class($row);
  1203. }
  1204. }
  1205. ++$this->rownum;
  1206. return $row;
  1207. }
  1208. // }}}
  1209. // {{{ seek()
  1210. /**
  1211. * Seek to a specific row in a result set
  1212. *
  1213. * @param int $rownum number of the row where the data can be found
  1214. * @return mixed MDB2_OK on success, a MDB2 error on failure
  1215. * @access public
  1216. */
  1217. function seek($rownum = 0)
  1218. {
  1219. if ($this->result === false) {
  1220. return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  1221. 'resultset has already been freed', __FUNCTION__);
  1222. }
  1223. $this->rownum = $rownum - 1;
  1224. return MDB2_OK;
  1225. }
  1226. // }}}
  1227. // {{{ valid()
  1228. /**
  1229. * Check if the end of the result set has been reached
  1230. *
  1231. * @return mixed true or false on sucess, a MDB2 error on failure
  1232. * @access public
  1233. */
  1234. function valid()
  1235. {
  1236. if ($this->result === false) {
  1237. return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  1238. 'resultset has already been freed', __FUNCTION__);
  1239. } elseif (is_null($this->result)) {
  1240. return true;
  1241. }
  1242. if ($this->_fillBuffer($this->rownum + 1)) {
  1243. return true;
  1244. }
  1245. return false;
  1246. }
  1247. // }}}
  1248. // {{{ numRows()
  1249. /**
  1250. * Returns the number of rows in a result object
  1251. *
  1252. * @return mixed MDB2 Error Object or the number of rows
  1253. * @access public
  1254. */
  1255. function numRows()
  1256. {
  1257. if ($this->result === false) {
  1258. return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  1259. 'resultset has already been freed', __FUNCTION__);
  1260. } elseif (is_null($this->result)) {
  1261. return 0;
  1262. }
  1263. $this->_fillBuffer();
  1264. return $this->buffer_rownum;
  1265. }
  1266. // }}}
  1267. // {{{ free()
  1268. /**
  1269. * Free the internal resources associated with $result.
  1270. *
  1271. * @return boolean true on success, false if $result is invalid
  1272. * @access public
  1273. */
  1274. function free()
  1275. {
  1276. $this->buffer = null;
  1277. $this->buffer_rownum = null;
  1278. return parent::free();
  1279. }
  1280. // }}}
  1281. }
  1282. /**
  1283. * MDB2 FireBird/InterBase statement driver
  1284. *
  1285. * @package MDB2
  1286. * @category Database
  1287. * @author Lorenzo Alberton <l.alberton@quipo.it>
  1288. */
  1289. class MDB2_Statement_ibase extends MDB2_Statement_Common
  1290. {
  1291. // {{{ _execute()
  1292. /**
  1293. * Execute a prepared query statement helper method.
  1294. *
  1295. * @…

Large files files are truncated, but you can click here to view the full file