PageRenderTime 62ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/php/MDB/Common.php

https://bitbucket.org/adarshj/convenient_website
PHP | 4548 lines | 2288 code | 280 blank | 1980 comment | 200 complexity | b5919951d8cbc52bf61e8d78d62b2a88 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0

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

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox, |
  6. // | Stig. S. Bakken, Lukas Smith |
  7. // | All rights reserved. |
  8. // +----------------------------------------------------------------------+
  9. // | MDB is a merge of PEAR DB and Metabases that provides a unified DB |
  10. // | API as well as database abstraction for PHP applications. |
  11. // | This LICENSE is in the BSD license style. |
  12. // | |
  13. // | Redistribution and use in source and binary forms, with or without |
  14. // | modification, are permitted provided that the following conditions |
  15. // | are met: |
  16. // | |
  17. // | Redistributions of source code must retain the above copyright |
  18. // | notice, this list of conditions and the following disclaimer. |
  19. // | |
  20. // | Redistributions in binary form must reproduce the above copyright |
  21. // | notice, this list of conditions and the following disclaimer in the |
  22. // | documentation and/or other materials provided with the distribution. |
  23. // | |
  24. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
  25. // | Lukas Smith nor the names of his contributors may be used to endorse |
  26. // | or promote products derived from this software without specific prior|
  27. // | written permission. |
  28. // | |
  29. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  30. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  31. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
  32. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
  33. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
  34. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  35. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  36. // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
  37. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  38. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  39. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
  40. // | POSSIBILITY OF SUCH DAMAGE. |
  41. // +----------------------------------------------------------------------+
  42. // | Author: Lukas Smith <smith@backendmedia.com> |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: Common.php,v 1.114.4.22 2004/04/08 19:11:58 lsmith Exp $
  46. /**
  47. * @package MDB
  48. * @author Lukas Smith <smith@backendmedia.com>
  49. */
  50. // }}}
  51. // {{{ MDB_defaultDebugOutput()
  52. /**
  53. * default debug output handler
  54. *
  55. * @param object $db reference to an MDB database object
  56. * @param string $message message that should be appended to the debug
  57. * variable
  58. * @return string the corresponding error message, of FALSE
  59. * if the error code was unknown
  60. * @access public
  61. */
  62. function MDB_defaultDebugOutput(&$db, $message)
  63. {
  64. $db->debug_output .= $db->database . " $message" . $db->getOption('log_line_break');
  65. }
  66. /**
  67. * MDB_Common: Base class that is extended by each MDB driver
  68. *
  69. * @package MDB
  70. * @category Database
  71. * @author Lukas Smith <smith@backendmedia.com>
  72. */
  73. class MDB_Common extends PEAR
  74. {
  75. // {{{ properties
  76. /**
  77. * index of the MDB object withing the global $_MDB_databases array
  78. * @var integer
  79. * @access private
  80. */
  81. var $database = 0;
  82. /**
  83. * @var string
  84. * @access private
  85. */
  86. var $host = '';
  87. /**
  88. * @var string
  89. * @access private
  90. */
  91. var $port = '';
  92. /**
  93. * @var string
  94. * @access private
  95. */
  96. var $user = '';
  97. /**
  98. * @var string
  99. * @access private
  100. */
  101. var $password = '';
  102. /**
  103. * @var string
  104. * @access private
  105. */
  106. var $database_name = '';
  107. /**
  108. * @var array
  109. * @access private
  110. */
  111. var $supported = array();
  112. /**
  113. * $options["persistent"] -> boolean persistent connection true|false?
  114. * $options["debug"] -> integer numeric debug level
  115. * $options["autofree"] -> boolean
  116. * $options["lob_buffer_length"] -> integer LOB buffer length
  117. * $options["log_line_break"] -> string line-break format
  118. * $options["seqname_format"] -> string pattern for sequence name
  119. * $options["includelob"] -> boolean
  120. * $options["includemanager"] -> boolean
  121. * $options["UseTransactions"] -> boolean
  122. * $options["optimize"] -> string 'performance' or 'portability'
  123. * @var array
  124. * @access private
  125. */
  126. var $options = array(
  127. 'persistent' => FALSE,
  128. 'debug' => FALSE,
  129. 'autofree' => FALSE,
  130. 'lob_buffer_length' => 8192,
  131. 'log_line_break' => "\n",
  132. 'seqname_format' => '%s_seq',
  133. 'sequence_col_name' => 'sequence',
  134. 'includelob' => FALSE,
  135. 'includemanager' => FALSE,
  136. 'UseTransactions' => FALSE,
  137. 'optimize' => 'performance',
  138. );
  139. /**
  140. * @var string
  141. * @access private
  142. */
  143. var $escape_quotes = '';
  144. /**
  145. * @var integer
  146. * @access private
  147. */
  148. var $decimal_places = 2;
  149. /**
  150. * @var string
  151. * @access private
  152. */
  153. var $manager_included_constant = '';
  154. /**
  155. * @var string
  156. * @access private
  157. */
  158. var $manager_include = '';
  159. /**
  160. * @var string
  161. * @access private
  162. */
  163. var $manager_class_name = '';
  164. /**
  165. * @var object
  166. * @access private
  167. */
  168. var $manager;
  169. /**
  170. * @var array
  171. * @access private
  172. */
  173. var $warnings = array();
  174. /**
  175. * @var string
  176. * @access private
  177. */
  178. var $debug = '';
  179. /**
  180. * @var string
  181. * @access private
  182. */
  183. var $debug_output = '';
  184. /**
  185. * @var boolean
  186. * @access private
  187. */
  188. var $pass_debug_handle = FALSE;
  189. /**
  190. * @var boolean
  191. * @access private
  192. */
  193. var $auto_commit = TRUE;
  194. /**
  195. * @var boolean
  196. * @access private
  197. */
  198. var $in_transaction = FALSE;
  199. /**
  200. * @var integer
  201. * @access private
  202. */
  203. var $first_selected_row = 0;
  204. /**
  205. * @var integer
  206. * @access private
  207. */
  208. var $selected_row_limit = 0;
  209. /**
  210. * DB type (mysql, oci8, odbc etc.)
  211. * @var string
  212. * @access private
  213. */
  214. var $type;
  215. /**
  216. * @var array
  217. * @access private
  218. */
  219. var $prepared_queries = array();
  220. /**
  221. * @var array
  222. * @access private
  223. */
  224. var $result_types;
  225. /**
  226. * @var string
  227. * @access private
  228. */
  229. var $last_query = '';
  230. /**
  231. * @var integer
  232. * @access private
  233. */
  234. var $fetchmode = MDB_FETCHMODE_ORDERED;
  235. /**
  236. * @var integer
  237. * @access private
  238. */
  239. var $affected_rows = -1;
  240. /**
  241. * @var array
  242. * @access private
  243. */
  244. var $lobs = array();
  245. /**
  246. * @var array
  247. * @access private
  248. */
  249. var $clobs = array();
  250. /**
  251. * @var array
  252. * @access private
  253. */
  254. var $blobs = array();
  255. // }}}
  256. // {{{ constructor
  257. /**
  258. * Constructor
  259. */
  260. function MDB_Common()
  261. {
  262. $database = count($GLOBALS['_MDB_databases']) + 1;
  263. $GLOBALS['_MDB_databases'][$database] = &$this;
  264. $this->database = $database;
  265. $this->PEAR('MDB_Error');
  266. $this->supported = array();
  267. $this->errorcode_map = array();
  268. $this->fetchmode = MDB_FETCHMODE_ORDERED;
  269. }
  270. // }}}
  271. // {{{ __toString()
  272. /**
  273. * String conversation
  274. *
  275. * @return string
  276. * @access public
  277. */
  278. function __toString()
  279. {
  280. $info = get_class($this);
  281. $info .= ': (phptype = ' . $this->phptype . ', dbsyntax = ' . $this->dbsyntax . ')';
  282. if ($this->connection) {
  283. $info .= ' [connected]';
  284. }
  285. return($info);
  286. }
  287. // }}}
  288. // {{{ errorCode()
  289. /**
  290. * Map native error codes to MDB's portable ones. Requires that
  291. * the DB implementation's constructor fills in the $errorcode_map
  292. * property.
  293. *
  294. * @param mixed $nativecode the native error code, as returned by the
  295. * backend database extension (string or integer)
  296. * @return int a portable MDB error code, or FALSE if this MDB
  297. * implementation has no mapping for the given error code.
  298. * @access public
  299. */
  300. function errorCode($nativecode)
  301. {
  302. if (isset($this->errorcode_map[$nativecode])) {
  303. return($this->errorcode_map[$nativecode]);
  304. }
  305. // Fall back to MDB_ERROR if there was no mapping.
  306. return(MDB_ERROR);
  307. }
  308. // }}}
  309. // {{{ errorMessage()
  310. /**
  311. * Map a MDB error code to a textual message. This is actually
  312. * just a wrapper for MDB::errorMessage().
  313. *
  314. * @param integer $dbcode the MDB error code
  315. * @return string the corresponding error message, of FALSE
  316. * if the error code was unknown
  317. * @access public
  318. */
  319. function errorMessage($dbcode)
  320. {
  321. return(MDB::errorMessage($this->errorcode_map[$dbcode]));
  322. }
  323. // }}}
  324. // {{{ raiseError()
  325. /**
  326. * This method is used to communicate an error and invoke error
  327. * callbacks etc. Basically a wrapper for PEAR::raiseError
  328. * without the message string.
  329. *
  330. * @param mixed $code integer error code, or a PEAR error object (all
  331. * other parameters are ignored if this parameter is an object
  332. * @param int $mode error mode, see PEAR_Error docs
  333. * @param mixed $options If error mode is PEAR_ERROR_TRIGGER, this is the
  334. * error level (E_USER_NOTICE etc). If error mode is
  335. * PEAR_ERROR_CALLBACK, this is the callback function, either as a
  336. * function name, or as an array of an object and method name. For
  337. * other error modes this parameter is ignored.
  338. * @param string $userinfo Extra debug information. Defaults to the last
  339. * query and native error code.
  340. * @param mixed $nativecode Native error code, integer or string depending
  341. * the backend.
  342. * @return object a PEAR error object
  343. * @access public
  344. * @see PEAR_Error
  345. */
  346. function &raiseError($code = MDB_ERROR, $mode = NULL, $options = NULL,
  347. $userinfo = NULL, $nativecode = NULL)
  348. {
  349. // The error is yet a MDB error object
  350. if (is_object($code)) {
  351. // because we the static PEAR::raiseError, our global
  352. // handler should be used if it is set
  353. if ($mode === null && !empty($this->_default_error_mode)) {
  354. $mode = $this->_default_error_mode;
  355. $options = $this->_default_error_options;
  356. }
  357. $err = PEAR::raiseError($code, NULL, $mode, $options, NULL, NULL, TRUE);
  358. return($err);
  359. }
  360. if ($userinfo === NULL) {
  361. $userinfo = $this->last_query;
  362. }
  363. if ($nativecode) {
  364. $userinfo .= ' [nativecode=' . trim($nativecode) . ']';
  365. }
  366. $err = PEAR::raiseError(NULL, $code, $mode, $options, $userinfo, 'MDB_Error', TRUE);
  367. return($err);
  368. }
  369. // }}}
  370. // {{{ errorNative()
  371. /**
  372. * returns an errormessage, provides by the database
  373. *
  374. * @return mixed MDB_Error or message
  375. * @access public
  376. */
  377. function errorNative()
  378. {
  379. return($this->raiseError(MDB_ERROR_NOT_CAPABLE));
  380. }
  381. // }}}
  382. // {{{ resetWarnings()
  383. /**
  384. * reset the warning array
  385. *
  386. * @access public
  387. */
  388. function resetWarnings()
  389. {
  390. $this->warnings = array();
  391. }
  392. // }}}
  393. // {{{ getWarnings()
  394. /**
  395. * get all warnings in reverse order.
  396. * This means that the last warning is the first element in the array
  397. *
  398. * @return array with warnings
  399. * @access public
  400. * @see resetWarnings()
  401. */
  402. function getWarnings()
  403. {
  404. return array_reverse($this->warnings);
  405. }
  406. // }}}
  407. // {{{ setOption()
  408. /**
  409. * set the option for the db class
  410. *
  411. * @param string $option option name
  412. * @param mixed $value value for the option
  413. * @return mixed MDB_OK or MDB_Error
  414. * @access public
  415. */
  416. function setOption($option, $value)
  417. {
  418. if (isset($this->options[$option])) {
  419. $this->options[$option] = $value;
  420. return MDB_OK;
  421. }
  422. return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL, "unknown option $option"));
  423. }
  424. // }}}
  425. // {{{ getOption()
  426. /**
  427. * returns the value of an option
  428. *
  429. * @param string $option option name
  430. * @return mixed the option value or error object
  431. * @access public
  432. */
  433. function getOption($option)
  434. {
  435. if (isset($this->options[$option])) {
  436. return($this->options[$option]);
  437. }
  438. return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL, "unknown option $option"));
  439. }
  440. // }}}
  441. // {{{ captureDebugOutput()
  442. /**
  443. * set a debug handler
  444. *
  445. * @param string $capture name of the function that should be used in
  446. * debug()
  447. * @access public
  448. * @see debug()
  449. */
  450. function captureDebugOutput($capture)
  451. {
  452. $this->pass_debug_handle = $capture;
  453. $this->debug = ($capture ? 'MDB_defaultDebugOutput' : '');
  454. }
  455. // }}}
  456. // {{{ debug()
  457. /**
  458. * set a debug message
  459. *
  460. * @param string $message Message with information for the user.
  461. * @access public
  462. */
  463. function debug($message)
  464. {
  465. if (strcmp($function = $this->debug, '')) {
  466. if ($this->pass_debug_handle) {
  467. $function($this, $message);
  468. } else {
  469. $function($message);
  470. }
  471. }
  472. }
  473. // }}}
  474. // {{{ debugOutput()
  475. /**
  476. * output debug info
  477. *
  478. * @return string content of the debug_output class variable
  479. * @access public
  480. */
  481. function debugOutput()
  482. {
  483. return($this->debug_output);
  484. }
  485. // }}}
  486. // {{{ setError() (deprecated)
  487. /**
  488. * set an error (deprecated)
  489. *
  490. * @param string $scope Scope of the error message
  491. * (usually the method tht caused the error)
  492. * @param string $message Message with information for the user.
  493. * @return boolean FALSE
  494. * @access private
  495. */
  496. function setError($scope, $message)
  497. {
  498. $this->last_error = $message;
  499. $this->debug($scope . ': ' . $message);
  500. if (($function = $this->error_handler) != '') {
  501. $error = array(
  502. 'Scope' => $scope,
  503. 'Message' => $message
  504. );
  505. $function($this, $error);
  506. }
  507. return(0);
  508. }
  509. // }}}
  510. // {{{ setErrorHandler() (deprecated)
  511. /**
  512. * Specify a function that is called when an error occurs.
  513. *
  514. * @param string $function Name of the function that will be called on
  515. * error. If an empty string is specified, no handler function is
  516. * called on error. The error handler function receives two arguments.
  517. * The first argument a reference to the driver class object that
  518. * triggered the error.
  519. *
  520. * The second argument is a reference to an associative array that
  521. * provides details about the error that occured. These details provide
  522. * more information than it is returned by the MetabaseError function.
  523. *
  524. * These are the currently supported error detail entries:
  525. *
  526. * Scope
  527. * String that indicates the scope of the driver object class
  528. * within which the error occured.
  529. *
  530. * Message
  531. * Error message as is returned by the MetabaseError function.
  532. * @return string name of last function
  533. * @access public
  534. */
  535. function setErrorHandler($function)
  536. {
  537. $last_function = $this->error_handler;
  538. $this->error_handler = $function;
  539. return($last_function);
  540. }
  541. // }}}
  542. // {{{ error() (deprecated)
  543. /**
  544. * Retrieve the error message text associated with the last operation that
  545. * failed. Some functions may fail but they do not return the reason that
  546. * makes them to fail. This function is meant to retrieve a textual
  547. * description of the failure cause.
  548. *
  549. * @return string the error message text associated with the last failure.
  550. * @access public
  551. */
  552. function error()
  553. {
  554. return($this->last_error);
  555. }
  556. // }}}
  557. // {{{ _quote()
  558. /**
  559. * Quotes a string so it can be safely used in a query. It will quote
  560. * the text so it can safely be used within a query.
  561. *
  562. * @param string $text the input string to quote
  563. * @return string quoted string
  564. * @access private
  565. */
  566. function _quote($text)
  567. {
  568. if (strcmp($this->escape_quotes, "'")) {
  569. $text = str_replace($this->escape_quotes, $this->escape_quotes . $this->escape_quotes, $text);
  570. }
  571. return str_replace("'", $this->escape_quotes . "'", $text);
  572. }
  573. // }}}
  574. // {{{ quoteIdentifier()
  575. /**
  576. * Quote a string so it can be safely used as a table or column name
  577. *
  578. * Delimiting style depends on which database driver is being used.
  579. *
  580. * NOTE: just because you CAN use delimited identifiers doesn't mean
  581. * you SHOULD use them. In general, they end up causing way more
  582. * problems than they solve.
  583. *
  584. * Portability is broken by using the following characters inside
  585. * delimited identifiers:
  586. * + backtick (<kbd>`</kbd>) -- due to MySQL
  587. * + double quote (<kbd>"</kbd>) -- due to Oracle
  588. * + brackets (<kbd>[</kbd> or <kbd>]</kbd>) -- due to Access
  589. *
  590. * Delimited identifiers are known to generally work correctly under
  591. * the following drivers:
  592. * + mssql
  593. * + mysql
  594. * + mysqli
  595. * + oci8
  596. * + odbc(access)
  597. * + odbc(db2)
  598. * + pgsql
  599. * + sqlite
  600. * + sybase
  601. *
  602. * InterBase doesn't seem to be able to use delimited identifiers
  603. * via PHP 4. They work fine under PHP 5.
  604. *
  605. * @param string $str identifier name to be quoted
  606. *
  607. * @return string quoted identifier string
  608. *
  609. * @access public
  610. */
  611. function quoteIdentifier($str)
  612. {
  613. return '"' . str_replace('"', '""', $str) . '"';
  614. }
  615. // }}}
  616. // {{{ _loadModule()
  617. /**
  618. * loads an module
  619. *
  620. * @param string $scope information about what method is being loaded,
  621. * that is used for error messages
  622. * @param string $module name of the module that should be loaded
  623. * (only used for error messages)
  624. * @param string $included_constant name of the constant that should be
  625. * defined when the module has been loaded
  626. * @param string $include name of the script that includes the module
  627. * @access private
  628. */
  629. function _loadModule($scope, $module, $included_constant, $include)
  630. {
  631. if (strlen($included_constant) == 0 || !defined($included_constant)) {
  632. if($include) {
  633. $include = 'MDB/Modules/'.$include;
  634. if(MDB::isError($debug = $this->getOption('debug')) || $debug > 2) {
  635. include_once($include);
  636. } else {
  637. @include_once($include);
  638. }
  639. } else {
  640. return($this->raiseError(MDB_ERROR_LOADMODULE, NULL, NULL,
  641. $scope . ': it was not specified an existing ' . $module . ' file (' . $include . ')'));
  642. }
  643. }
  644. return(MDB_OK);
  645. }
  646. // }}}
  647. // {{{ loadLob()
  648. /**
  649. * loads the LOB module
  650. *
  651. * @param string $scope information about what method is being loaded,
  652. * that is used for error messages
  653. * @access public
  654. */
  655. function loadLob($scope = '')
  656. {
  657. if (defined('MDB_LOB_INCLUDED')) {
  658. return(MDB_OK);
  659. }
  660. $result = $this->_loadModule($scope, 'LOB',
  661. 'MDB_LOB_INCLUDED', 'LOB.php');
  662. if (MDB::isError($result)) {
  663. return($result);
  664. }
  665. return(MDB_OK);
  666. }
  667. // }}}
  668. // {{{ loadManager()
  669. /**
  670. * loads the Manager module
  671. *
  672. * @param string $scope information about what method is being loaded,
  673. * that is used for error messages
  674. * @access public
  675. */
  676. function loadManager($scope = '')
  677. {
  678. if (isset($this->manager) && is_object($this->manager)) {
  679. return(MDB_OK);
  680. }
  681. $result = $this->_loadModule($scope, 'Manager',
  682. 'MDB_MANAGER_'.strtoupper($this->phptype).'_INCLUDED',
  683. 'Manager/'.$this->phptype.'.php');
  684. if (MDB::isError($result)) {
  685. return($result);
  686. }
  687. $class_name = 'MDB_Manager_'.$this->dbsyntax;
  688. if (!class_exists($class_name)) {
  689. return($this->raiseError(MDB_ERROR_LOADMODULE, NULL, NULL,
  690. 'Unable to load extension'));
  691. }
  692. @$this->manager = new $class_name;
  693. return(MDB_OK);
  694. }
  695. // }}}
  696. // {{{ autoCommit()
  697. /**
  698. * Define whether database changes done on the database be automatically
  699. * committed. This function may also implicitly start or end a transaction.
  700. *
  701. * @param boolean $auto_commit flag that indicates whether the database
  702. * changes should be committed right after executing every query
  703. * statement. If this argument is 0 a transaction implicitly started.
  704. * Otherwise, if a transaction is in progress it is ended by committing
  705. * any database changes that were pending.
  706. * @return mixed MDB_OK on success, a MDB error on failure
  707. * @access public
  708. */
  709. function autoCommit($auto_commit)
  710. {
  711. $this->debug('AutoCommit: ' . ($auto_commit ? 'On' : 'Off'));
  712. return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL,
  713. 'Auto-commit transactions: transactions are not supported'));
  714. }
  715. // }}}
  716. // {{{ commit()
  717. /**
  718. * Commit the database changes done during a transaction that is in
  719. * progress. This function may only be called when auto-committing is
  720. * disabled, otherwise it will fail. Therefore, a new transaction is
  721. * implicitly started after committing the pending changes.
  722. *
  723. * @return mixed MDB_OK on success, a MDB error on failure
  724. * @access public
  725. */
  726. function commit()
  727. {
  728. $this->debug('Commit Transaction');
  729. return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL,
  730. 'Commit transaction: commiting transactions are not supported'));
  731. }
  732. // }}}
  733. // {{{ rollback()
  734. /**
  735. * Cancel any database changes done during a transaction that is in
  736. * progress. This function may only be called when auto-committing is
  737. * disabled, otherwise it will fail. Therefore, a new transaction is
  738. * implicitly started after canceling the pending changes.
  739. *
  740. * @return mixed MDB_OK on success, a MDB error on failure
  741. * @access public
  742. */
  743. function rollback()
  744. {
  745. $this->debug('Rollback Transaction');
  746. return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL,
  747. 'Rollback transaction: rolling back transactions are not supported'));
  748. }
  749. // }}}
  750. // {{{ disconnect()
  751. /**
  752. * Log out and disconnect from the database.
  753. *
  754. * @return mixed TRUE on success, FALSE if not connected and error
  755. * object on error
  756. * @access public
  757. */
  758. function disconnect()
  759. {
  760. if ($this->in_transaction && !MDB::isError($this->rollback()) && !MDB::isError($this->autoCommit(TRUE))) {
  761. $this->in_transaction = FALSE;
  762. }
  763. return($this->_close());
  764. }
  765. // }}}
  766. // {{{ _close()
  767. /**
  768. * all the RDBMS specific things needed to close a DB connection
  769. *
  770. * @access private
  771. */
  772. function _close()
  773. {
  774. unset($GLOBALS['_MDB_databases'][$this->database]);
  775. }
  776. // }}}
  777. // {{{ setDatabase()
  778. /**
  779. * Select a different database
  780. *
  781. * @param string $name name of the database that should be selected
  782. * @return string name of the database previously connected to
  783. * @access public
  784. */
  785. function setDatabase($name)
  786. {
  787. $previous_database_name = $this->database_name;
  788. $this->database_name = $name;
  789. return($previous_database_name);
  790. }
  791. // }}}
  792. // {{{ setDSN()
  793. /**
  794. * set the DSN
  795. *
  796. * @param mixed $dsninfo DSN string or array
  797. * @return MDB_OK
  798. * @access public
  799. */
  800. function setDSN($dsn)
  801. {
  802. $dsninfo = MDB::parseDSN($dsn);
  803. if(isset($dsninfo['hostspec'])) {
  804. $this->host = $dsninfo['hostspec'];
  805. }
  806. if(isset($dsninfo['port'])) {
  807. $this->port = $dsninfo['port'];
  808. }
  809. if(isset($dsninfo['username'])) {
  810. $this->user = $dsninfo['username'];
  811. }
  812. if(isset($dsninfo['password'])) {
  813. $this->password = $dsninfo['password'];
  814. }
  815. if(isset($dsninfo['database'])) {
  816. $this->database_name = $dsninfo['database'];
  817. }
  818. return(MDB_OK);
  819. }
  820. // }}}
  821. // {{{ getDSN()
  822. /**
  823. * return the DSN as a string
  824. *
  825. * @param string $type type to return
  826. * @return mixed DSN in the chosen type
  827. * @access public
  828. */
  829. function getDSN($type = 'string')
  830. {
  831. switch($type) {
  832. case 'array':
  833. $dsn = array(
  834. 'phptype' => $this->phptype,
  835. 'username' => $this->user,
  836. 'password' => $this->password,
  837. 'hostspec' => $this->host,
  838. 'database' => $this->database_name
  839. );
  840. break;
  841. default:
  842. $dsn = $this->phptype.'://'.$this->user.':'
  843. .$this->password.'@'.$this->host
  844. .($this->port ? (':'.$this->port) : '')
  845. .'/'.$this->database_name;
  846. break;
  847. }
  848. return($dsn);
  849. }
  850. // }}}
  851. // {{{ createDatabase()
  852. /**
  853. * create a new database
  854. *
  855. * @param string $name name of the database that should be created
  856. * @return mixed MDB_OK on success, a MDB error on failure
  857. * @access public
  858. */
  859. function createDatabase($name)
  860. {
  861. $result = $this->loadManager('Create database');
  862. if (MDB::isError($result)) {
  863. return($result);
  864. }
  865. return($this->manager->createDatabase($this, $name));
  866. }
  867. // }}}
  868. // {{{ dropDatabase()
  869. /**
  870. * drop an existing database
  871. *
  872. * @param string $name name of the database that should be dropped
  873. * @return mixed MDB_OK on success, a MDB error on failure
  874. * @access public
  875. */
  876. function dropDatabase($name)
  877. {
  878. $result = $this->loadManager('Drop database');
  879. if (MDB::isError($result)) {
  880. return($result);
  881. }
  882. return($this->manager->dropDatabase($this, $name));
  883. }
  884. // }}}
  885. // {{{ createTable()
  886. /**
  887. * create a new table
  888. *
  889. * @param string $name Name of the database that should be created
  890. * @param array $fields Associative array that contains the definition of
  891. * each field of the new table. The indexes of the array entries are
  892. * the names of the fields of the table an the array entry values are
  893. * associative arrays like those that are meant to be passed with the
  894. * field definitions to get[Type]Declaration() functions.
  895. *
  896. * Example
  897. * array(
  898. * 'id' => array(
  899. * 'type' => 'integer',
  900. * 'unsigned' => 1
  901. * 'notnull' => 1
  902. * 'default' => 0
  903. * ),
  904. * 'name' => array(
  905. * 'type' => 'text',
  906. * 'length' => 12
  907. * ),
  908. * 'password' => array(
  909. * 'type' => 'text',
  910. * 'length' => 12
  911. * )
  912. * );
  913. * @return mixed MDB_OK on success, a MDB error on failure
  914. * @access public
  915. */
  916. function createTable($name, $fields)
  917. {
  918. $result = $this->loadManager('Create table');
  919. if (MDB::isError($result)) {
  920. return($result);
  921. }
  922. return($this->manager->createTable($this, $name, $fields));
  923. }
  924. // }}}
  925. // {{{ dropTable()
  926. /**
  927. * drop an existing table
  928. *
  929. * @param string $name name of the table that should be dropped
  930. * @return mixed MDB_OK on success, a MDB error on failure
  931. * @access public
  932. */
  933. function dropTable($name)
  934. {
  935. $result = $this->loadManager('Drop table');
  936. if (MDB::isError($result)) {
  937. return($result);
  938. }
  939. return($this->manager->dropTable($this, $name));
  940. }
  941. // }}}
  942. // {{{ alterTable()
  943. /**
  944. * alter an existing table
  945. *
  946. * @param string $name name of the table that is intended to be changed.
  947. * @param array $changes associative array that contains the details of
  948. * each type of change that is intended to be performed. The types of
  949. * changes that are currently supported are defined as follows:
  950. *
  951. * name
  952. * New name for the table.
  953. *
  954. * AddedFields
  955. * Associative array with the names of fields to be added as indexes of
  956. * the array. The value of each entry of the array should be set to
  957. * another associative array with the properties of the fields to be
  958. * added. The properties of the fields should be the same as defined by
  959. * the Metabase parser.
  960. *
  961. * Additionally, there should be an entry named Declaration that is
  962. * expected to contain the portion of the field declaration already in
  963. * DBMS specific SQL code as it is used in the CREATE TABLE statement.
  964. *
  965. * RemovedFields
  966. * Associative array with the names of fields to be removed as indexes of
  967. * the array. Currently the values assigned to each entry are ignored. An
  968. * empty array should be used for future compatibility.
  969. *
  970. * RenamedFields
  971. * Associative array with the names of fields to be renamed as indexes of
  972. * the array. The value of each entry of the array should be set to another
  973. * associative array with the entry named name with the new field name and
  974. * the entry named Declaration that is expected to contain the portion of
  975. * the field declaration already in DBMS specific SQL code as it is used
  976. * in the CREATE TABLE statement.
  977. *
  978. * ChangedFields
  979. * Associative array with the names of the fields to be changed as indexes
  980. * of the array. Keep in mind that if it is intended to change either the
  981. * name of a field and any other properties, the ChangedFields array
  982. * entries should have the new names of the fields as array indexes.
  983. *
  984. * The value of each entry of the array should be set to another
  985. * associative array with the properties of the fields to that are meant
  986. * to be changed as array entries. These entries should be assigned to the
  987. * new values of the respective properties. The properties of the fields
  988. * should be the* same as defined by the Metabase parser.
  989. *
  990. * If the default property is meant to be added, removed or changed, there
  991. * should also be an entry with index ChangedDefault assigned to 1.
  992. * Similarly, if the notnull constraint is to be added or removed, there
  993. * should also be an entry with index ChangedNotNull assigned to 1.
  994. *
  995. * Additionally, there should be an entry named Declaration that is
  996. * expected to contain the portion of the field changed declaration
  997. * already in DBMS specific SQL code as it is used in the CREATE TABLE
  998. * statement.
  999. *
  1000. * Example
  1001. * array(
  1002. * 'name' => 'userlist',
  1003. * 'AddedFields' => array(
  1004. * 'quota' => array(
  1005. * 'type' => 'integer',
  1006. * 'unsigned' => 1,
  1007. * 'Declaration' => 'quota INT'
  1008. * )
  1009. * ),
  1010. * 'RemovedFields' => array(
  1011. * 'file_limit' => array(),
  1012. * 'time_limit' => array()
  1013. * ),
  1014. * 'ChangedFields' => array(
  1015. * 'gender' => array(
  1016. * 'default' => 'M',
  1017. * 'ChangeDefault' => 1,
  1018. * 'Declaration' => "gender CHAR(1) DEFAULT 'M'"
  1019. * )
  1020. * ),
  1021. * 'RenamedFields' => array(
  1022. * 'sex' => array(
  1023. * 'name' => 'gender',
  1024. * 'Declaration' => "gender CHAR(1) DEFAULT 'M'"
  1025. * )
  1026. * )
  1027. * )
  1028. *
  1029. * @param boolean $check indicates whether the function should just check
  1030. * if the DBMS driver can perform the requested table alterations if
  1031. * the value is TRUE or actually perform them otherwise.
  1032. * @return mixed MDB_OK on success, a MDB error on failure
  1033. * @access public
  1034. */
  1035. function alterTable($name, $changes, $check)
  1036. {
  1037. $result = $this->loadManager('Alter table');
  1038. if (MDB::isError($result)) {
  1039. return($result);
  1040. }
  1041. return($this->manager->alterTable($this, $name, $changes, $check));
  1042. }
  1043. // }}}
  1044. // {{{ listDatabases()
  1045. /**
  1046. * list all databases
  1047. *
  1048. * @return mixed data array on success, a MDB error on failure
  1049. * @access public
  1050. */
  1051. function listDatabases()
  1052. {
  1053. $result = $this->loadManager('List databases');
  1054. if (MDB::isError($result)) {
  1055. return($result);
  1056. }
  1057. return($this->manager->listDatabases($this));
  1058. }
  1059. // }}}
  1060. // {{{ listUsers()
  1061. /**
  1062. * list all users
  1063. *
  1064. * @return mixed data array on success, a MDB error on failure
  1065. * @access public
  1066. */
  1067. function listUsers()
  1068. {
  1069. $result = $this->loadManager('List users');
  1070. if (MDB::isError($result)) {
  1071. return($result);
  1072. }
  1073. return($this->manager->listUsers($this));
  1074. }
  1075. // }}}
  1076. // {{{ listViews()
  1077. /**
  1078. * list all viewes in the current database
  1079. *
  1080. * @return mixed data array on success, a MDB error on failure
  1081. * @access public
  1082. */
  1083. function listViews()
  1084. {
  1085. $result = $this->loadManager('List views');
  1086. if (MDB::isError($result)) {
  1087. return($result);
  1088. }
  1089. return($this->manager->listViews($this));
  1090. }
  1091. // }}}
  1092. // {{{ listFunctions()
  1093. /**
  1094. * list all functions in the current database
  1095. *
  1096. * @return mixed data array on success, a MDB error on failure
  1097. * @access public
  1098. */
  1099. function listFunctions()
  1100. {
  1101. $result = $this->loadManager('List functions');
  1102. if (MDB::isError($result)) {
  1103. return($result);
  1104. }
  1105. return($this->manager->listFunctions($this));
  1106. }
  1107. // }}}
  1108. // {{{ listTables()
  1109. /**
  1110. * list all tables in the current database
  1111. *
  1112. * @return mixed data array on success, a MDB error on failure
  1113. * @access public
  1114. */
  1115. function listTables()
  1116. {
  1117. $result = $this->loadManager('List tables');
  1118. if (MDB::isError($result)) {
  1119. return($result);
  1120. }
  1121. return($this->manager->listTables($this));
  1122. }
  1123. // }}}
  1124. // {{{ listTableFields()
  1125. /**
  1126. * list all fields in a tables in the current database
  1127. *
  1128. * @param string $table name of table that should be used in method
  1129. * @return mixed data array on success, a MDB error on failure
  1130. * @access public
  1131. */
  1132. function listTableFields($table)
  1133. {
  1134. $result = $this->loadManager('List table fields');
  1135. if (MDB::isError($result)) {
  1136. return($result);
  1137. }
  1138. return($this->manager->listTableFields($this, $table));
  1139. }
  1140. // }}}
  1141. // {{{ getTableFieldDefinition()
  1142. /**
  1143. * get the stucture of a field into an array
  1144. *
  1145. * @param string $table name of table that should be used in method
  1146. * @param string $fields name of field that should be used in method
  1147. * @return mixed data array on success, a MDB error on failure
  1148. * @access public
  1149. */
  1150. function getTableFieldDefinition($table, $field)
  1151. {
  1152. $result = $this->loadManager('Get table field definition');
  1153. if (MDB::isError($result)) {
  1154. return($result);
  1155. }
  1156. return($this->manager->getTableFieldDefinition($this, $table, $field));
  1157. }
  1158. // }}}
  1159. // {{{ getFieldDeclaration()
  1160. /**
  1161. * get declaration of a field
  1162. *
  1163. * @param string $field_name name of the field to be created
  1164. * @param string $field associative array with the name of the properties
  1165. * of the field being declared as array indexes. Currently, the types
  1166. * of supported field properties are as follows:
  1167. *
  1168. * default
  1169. * Boolean value to be used as default for this field.
  1170. *
  1171. * notnull
  1172. * Boolean flag that indicates whether this field is constrained
  1173. * to not be set to NULL.
  1174. * @return mixed string on success, a MDB error on failure
  1175. * @access public
  1176. */
  1177. function getFieldDeclaration($field_name, $field)
  1178. {
  1179. $result = $this->loadManager('Get table field definition');
  1180. if (MDB::isError($result)) {
  1181. return($result);
  1182. }
  1183. return($this->manager->getFieldDeclaration($this, $field_name, $field));
  1184. }
  1185. // }}}
  1186. // {{{ getFieldDeclarationList()
  1187. /**
  1188. * get declaration of a number of field in bulk
  1189. *
  1190. * @param string $fields a multidimensional associative array.
  1191. * The first dimension determines the field name, while the second
  1192. * dimension is keyed with the name of the properties
  1193. * of the field being declared as array indexes. Currently, the types
  1194. * of supported field properties are as follows:
  1195. *
  1196. * default
  1197. * Boolean value to be used as default for this field.
  1198. *
  1199. * notnull
  1200. * Boolean flag that indicates whether this field is constrained
  1201. * to not be set to NULL.
  1202. *
  1203. * default
  1204. * Boolean value to be used as default for this field.
  1205. *
  1206. * notnull
  1207. * Boolean flag that indicates whether this field is constrained
  1208. * to not be set to NULL.
  1209. * @return mixed string on success, a MDB error on failure
  1210. * @access public
  1211. */
  1212. function getFieldDeclarationList($fields)
  1213. {
  1214. $result = $this->loadManager('Get table field list');
  1215. if (MDB::isError($result)) {
  1216. return($result);
  1217. }
  1218. return($this->manager->getFieldDeclarationList($this, $fields));
  1219. }
  1220. // }}}
  1221. // {{{ _isSequenceName()
  1222. /**
  1223. * list all tables in the current database
  1224. *
  1225. * @param string $sqn string that containts name of a potential sequence
  1226. * @return mixed name of the sequence if $sqn is a name of a sequence, else FALSE
  1227. * @access private
  1228. */
  1229. function _isSequenceName($sqn)
  1230. {
  1231. $result = $this->loadManager('is sequence name');
  1232. if (MDB::isError($result)) {
  1233. return($result);
  1234. }
  1235. return($this->manager->_isSequenceName($this, $sqn));
  1236. }
  1237. // }}}
  1238. // {{{ createIndex()
  1239. /**
  1240. * get the stucture of a field into an array
  1241. *
  1242. * @param string $table name of the table on which the index is to be
  1243. * created
  1244. * @param string $name name of the index to be created
  1245. * @param array $definition associative array that defines properties of
  1246. * the index to be created. Currently, only one property named FIELDS
  1247. * is supported. This property is also an associative with the names
  1248. * of the index fields as array indexes. Each entry of this array is
  1249. * set to another type of associative array that specifies properties
  1250. * of the index that are specific to each field.
  1251. *
  1252. * Currently, only the sorting property is supported. It should be
  1253. * used to define the sorting direction of the index. It may be set
  1254. * to either ascending or descending. Not all DBMS support index
  1255. * sorting direction configuration. The DBMS drivers of those that do
  1256. * not support it ignore this property. Use the function support() to
  1257. * determine whether the DBMS driver can manage indexes.
  1258. *
  1259. * Example
  1260. * array(
  1261. * 'FIELDS' => array(
  1262. * 'user_name' => array(
  1263. * 'sorting' => 'ascending'
  1264. * ),
  1265. * 'last_login' => array()
  1266. * )
  1267. * )
  1268. * @return mixed MDB_OK on success, a MDB error on failure
  1269. * @access public
  1270. */
  1271. function createIndex($table, $name, $definition)
  1272. {
  1273. $result = $this->loadManager('Create index');
  1274. if (MDB::isError($result)) {
  1275. return($result);
  1276. }
  1277. return($this->manager->createIndex($this, $table, $name, $definition));
  1278. }
  1279. // }}}
  1280. // {{{ dropIndex()
  1281. /**
  1282. * drop existing index
  1283. *
  1284. * @param string $table name of table that should be used in method
  1285. * @param string $name name of the index to be dropped
  1286. * @return mixed MDB_OK on success, a MDB error on failure
  1287. * @access public
  1288. */
  1289. function dropIndex($table, $name)
  1290. {
  1291. $result = $this->loadManager('Drop index');
  1292. if (MDB::isError($result)) {
  1293. return($result);
  1294. }
  1295. return($this->manager->dropIndex($this, $table , $name));
  1296. }
  1297. // }}}
  1298. // {{{ listTableIndexes()
  1299. /**
  1300. * list all indexes in a table
  1301. *
  1302. * @param string $table name of table that should be used in method
  1303. * @return mixed data array on success, a MDB error on failure
  1304. * @access public
  1305. */
  1306. function listTableIndexes($table)
  1307. {
  1308. $result = $this->loadManager('List table index');
  1309. if (MDB::isError($result)) {
  1310. return($result);
  1311. }
  1312. return($this->manager->listTableIndexes($this, $table));
  1313. }
  1314. // }}}
  1315. // {{{ getTableIndexDefinition()
  1316. /**
  1317. * get the stucture of an index into an array
  1318. *
  1319. * @param string $table name of table that should be used in method
  1320. * @param string $index name of index that should be used in method
  1321. * @return mixed data array on success, a MDB error on failure
  1322. * @access public
  1323. */
  1324. function getTableIndexDefinition($table, $index)
  1325. {
  1326. $result = $this->loadManager('Get table index definition');
  1327. if (MDB::isError($result)) {
  1328. return($result);
  1329. }
  1330. return($this->manager->getTableIndexDefinition($this, $table, $index));
  1331. }
  1332. // }}}
  1333. // {{{ createSequence()
  1334. /**
  1335. * create sequence
  1336. *
  1337. * @param string $name name of the sequence to be created
  1338. * @param string $start start value of the sequence; default is 1
  1339. * @return mixed MDB_OK on success, a MDB error on failure
  1340. * @access public
  1341. */
  1342. function createSequence($name, $start = 1)
  1343. {
  1344. $result = $this->loadManager('Create sequence');
  1345. if (MDB::isError($result)) {
  1346. return($result);
  1347. }
  1348. return($this->manager->createSequence($this, $name, $start));
  1349. }
  1350. // }}}
  1351. // {{{ dropSequence()
  1352. /**
  1353. * drop existing sequence
  1354. *
  1355. * @param string $name name of the sequence to be dropped
  1356. * @return mixed MDB_OK on success, a MDB error on failure
  1357. * @access public
  1358. */
  1359. function dropSequence($name)
  1360. {
  1361. $result = $this->loadManager('Drop sequence');
  1362. if (MDB::isError($result)) {
  1363. return($result);
  1364. }
  1365. return($this->manager->dropSequence($this, $name));
  1366. }
  1367. // }}}
  1368. // {{{ listSequences()
  1369. /**
  1370. * list all tables in the current database
  1371. *
  1372. * @return mixed data array on success, a MDB error on failure
  1373. * @access public
  1374. */
  1375. function listSequences()
  1376. {
  1377. $result = $this->loadManager('List sequences');
  1378. if (MDB::isError($result)) {
  1379. return($result);
  1380. }
  1381. return($this->manager->listSequences($this));
  1382. }
  1383. // }}}
  1384. // {{{ getSequenceDefinition()
  1385. /**
  1386. * get the stucture of a sequence into an array
  1387. *
  1388. * @param string $sequence name of sequence that should be used in method
  1389. * @return mixed data array on success, a MDB error on failure
  1390. * @access public
  1391. */
  1392. function getSequenceDefinition($sequence)
  1393. {
  1394. $result = $this->loadManager('Get sequence definition');
  1395. if (MDB::isError($result)) {
  1396. return($result);
  1397. }
  1398. return($this->manager->getSequenceDefinition($this, $sequence));
  1399. }
  1400. // }}}
  1401. // {{{ query()
  1402. /**
  1403. * Send a query to the database and return any results
  1404. *
  1405. * @param string $query the SQL query
  1406. * @param mixed $types array that contains the types of the columns in
  1407. * the result set
  1408. * @return mixed a result handle or MDB_OK on success, a MDB error on failure
  1409. * @access public
  1410. */
  1411. function query($query, $types = NULL)
  1412. {
  1413. $this->debug("Query: $query");
  1414. return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL, 'Query: database queries are not implemented'));
  1415. }
  1416. // }}}
  1417. // {{{ setSelectedRowRange()
  1418. /**
  1419. * set the range of the next query
  1420. *
  1421. * @param string $first first row to select
  1422. * @param string $limit number of rows to select
  1423. * @return mixed MDB_OK on success, a MDB error on failure
  1424. * @access public
  1425. */
  1426. function setSelectedRowRange($first, $limit)
  1427. {
  1428. if (!isset($this->supported['SelectRowRanges'])) {
  1429. return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL,
  1430. 'Set selected row range: selecting row ranges is not supported by this driver'));
  1431. }
  1432. $first = (int)$first;
  1433. if ($first < 0) {
  1434. return($this->raiseError(MDB_ERROR_SYNTAX, NULL, NULL,
  1435. 'Set selected row range: it was not specified a valid first selected range row'));
  1436. }
  1437. $limit = (int)$limit;
  1438. if ($limit < 1) {
  1439. return($this->raiseError(MDB_ERROR_SYNTAX, NULL, NULL,
  1440. 'Set selected row range: it was not specified a valid selected range row limit'));
  1441. }
  1442. $this->first_selected_row = $first;
  1443. $this->selected_row_limit = $limit;
  1444. return(MDB_OK);
  1445. }
  1446. // }}}
  1447. // {{{ limitQuery()
  1448. /**
  1449. * Generates a limited query
  1450. *
  1451. * @param string $query query
  1452. * @param mixed $types array that contains the types of the columns in
  1453. * the result set
  1454. * @param integer $from the row to start to fetching
  1455. * @param integer $count the numbers of rows to fetch
  1456. * @return mixed a valid ressource pointer or a MDB_Error
  1457. * @access public
  1458. */
  1459. function limitQuery($query, $types = NULL, $from, $count)
  1460. {
  1461. $result = $this->setSelectedRowRange($from, $count);
  1462. if (MDB::isError($result)) {
  1463. return($result);
  1464. }
  1465. return($this->query($query, $types));
  1466. }
  1467. // }}}
  1468. // {{{ subSelect()
  1469. /**
  1470. * simple subselect emulation: leaves the query untouched for all RDBMS
  1471. * that support subselects
  1472. *
  1473. * @access public
  1474. *
  1475. * @param string $query the SQL query for the subselect that may only
  1476. * return a column
  1477. * @param string $quote determines if the data needs to be quoted before
  1478. * being returned
  1479. *
  1480. * @return string the query
  1481. */
  1482. function subSelect($query, $quote = FALSE)
  1483. {
  1484. if ($this->supported['SubSelects'] == 1) {
  1485. return($query);
  1486. }
  1487. return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL, 'Subselect: subselect not implemented'));
  1488. }
  1489. // }}}
  1490. // {{{ replace()
  1491. /**
  1492. * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
  1493. * query, except that if there is already a row in the table with the same
  1494. * key field values, the REPLACE query just updates its values instead of
  1495. * inserting a new row.
  1496. *
  1497. * The REPLACE type of query does not make part of the SQL standards. Since
  1498. * pratically only MySQL implements it natively, this type of query is
  1499. * emulated through this method for other DBMS using standard types of
  1500. * queries inside …

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