Changeset 17877 for branches/comu-ver2/data/module/DB/common.php
- Timestamp:
- 2009/03/06 20:21:51 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/comu-ver2/data/module/DB/common.php
r15532 r17877 19 19 * @author Tomas V.V. Cox <cox@idecnet.com> 20 20 * @author Daniel Convissor <danielc@php.net> 21 * @copyright 1997-200 5The PHP Group21 * @copyright 1997-2007 The PHP Group 22 22 * @license http://www.php.net/license/3_0.txt PHP License 3.0 23 23 * @version CVS: $Id$ … … 41 41 * @author Tomas V.V. Cox <cox@idecnet.com> 42 42 * @author Daniel Convissor <danielc@php.net> 43 * @copyright 1997-200 5The PHP Group43 * @copyright 1997-2007 The PHP Group 44 44 * @license http://www.php.net/license/3_0.txt PHP License 3.0 45 * @version Release: @package_version@45 * @version Release: 1.7.14RC1 46 46 * @link http://pear.php.net/package/DB 47 47 */ … … 121 121 */ 122 122 var $prepared_queries = array(); 123 124 /** 125 * Flag indicating that the last query was a manipulation query. 126 * @access protected 127 * @var boolean 128 */ 129 var $_last_query_manip = false; 130 131 /** 132 * Flag indicating that the next query <em>must</em> be a manipulation 133 * query. 134 * @access protected 135 * @var boolean 136 */ 137 var $_next_query_manip = false; 123 138 124 139 … … 425 440 function quoteSmart($in) 426 441 { 427 if (is_int($in) || is_double($in)) {442 if (is_int($in)) { 428 443 return $in; 444 } elseif (is_float($in)) { 445 return $this->quoteFloat($in); 429 446 } elseif (is_bool($in)) { 430 return $ in ? 1 : 0;447 return $this->quoteBoolean($in); 431 448 } elseif (is_null($in)) { 432 449 return 'NULL'; 433 450 } else { 451 if ($this->dbsyntax == 'access' 452 && preg_match('/^#.+#$/', $in)) 453 { 454 return $this->escapeSimple($in); 455 } 434 456 return "'" . $this->escapeSimple($in) . "'"; 435 457 } 436 458 } 437 459 460 // }}} 461 // {{{ quoteBoolean() 462 463 /** 464 * Formats a boolean value for use within a query in a locale-independent 465 * manner. 466 * 467 * @param boolean the boolean value to be quoted. 468 * @return string the quoted string. 469 * @see DB_common::quoteSmart() 470 * @since Method available since release 1.7.8. 471 */ 472 function quoteBoolean($boolean) { 473 return $boolean ? '1' : '0'; 474 } 475 476 // }}} 477 // {{{ quoteFloat() 478 479 /** 480 * Formats a float value for use within a query in a locale-independent 481 * manner. 482 * 483 * @param float the float value to be quoted. 484 * @return string the quoted string. 485 * @see DB_common::quoteSmart() 486 * @since Method available since release 1.7.8. 487 */ 488 function quoteFloat($float) { 489 return "'".$this->escapeSimple(str_replace(',', '.', strval(floatval($float))))."'"; 490 } 491 438 492 // }}} 439 493 // {{{ escapeSimple() … … 838 892 return $sth; 839 893 } 840 $ret = &$this->execute($sth, array_values($fields_values));894 $ret = $this->execute($sth, array_values($fields_values)); 841 895 $this->freePrepared($sth); 842 896 return $ret; … … 932 986 * 'filename.txt' 933 987 * ); 934 * $res = &$db->execute($sth, $data);988 * $res = $db->execute($sth, $data); 935 989 * </code> 936 990 * … … 952 1006 function &execute($stmt, $data = array()) 953 1007 { 954 955 1008 $realquery = $this->executeEmulateQuery($stmt, $data); 956 1009 if (DB::isError($realquery)) { … … 962 1015 return $result; 963 1016 } else { 964 $tmp = &new DB_result($this, $result);1017 $tmp = new DB_result($this, $result); 965 1018 return $tmp; 966 1019 } … … 991 1044 $data = (array)$data; 992 1045 $this->last_parameters = $data; 993 1046 994 1047 if (count($this->prepare_types[$stmt]) != count($data)) { 995 1048 $this->last_query = $this->prepared_queries[$stmt]; … … 1002 1055 foreach ($data as $value) { 1003 1056 if ($this->prepare_types[$stmt][$i] == DB_PARAM_SCALAR) { 1004 if ($value != "") {1005 $realquery .= $this->quoteSmart($value);1006 }else{1007 $realquery .= 'NULL';1008 1057 if (strlen($value) == 0) { 1058 $realquery .= 'NULL'; 1059 } else { 1060 $realquery .= $this->quoteSmart($value); 1061 } 1009 1062 } elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) { 1010 1063 $fp = @fopen($value, 'rb'); … … 1047 1100 { 1048 1101 foreach ($data as $value) { 1049 $res = &$this->execute($stmt, $value);1102 $res = $this->execute($stmt, $value); 1050 1103 if (DB::isError($res)) { 1051 1104 return $res; … … 1160 1213 return $sth; 1161 1214 } 1162 $ret = &$this->execute($sth, $params);1215 $ret = $this->execute($sth, $params); 1163 1216 $this->freePrepared($sth, false); 1164 1217 return $ret; … … 1169 1222 return $result; 1170 1223 } else { 1171 $tmp = &new DB_result($this, $result);1224 $tmp = new DB_result($this, $result); 1172 1225 return $tmp; 1173 1226 } … … 1200 1253 return $query; 1201 1254 } 1202 $result = &$this->query($query, $params);1255 $result = $this->query($query, $params); 1203 1256 if (is_a($result, 'DB_result')) { 1204 1257 $result->setOption('limit_from', $from); … … 1235 1288 return $sth; 1236 1289 } 1237 $res = &$this->execute($sth, $params);1290 $res = $this->execute($sth, $params); 1238 1291 $this->freePrepared($sth); 1239 1292 } else { 1240 $res = &$this->query($query);1293 $res = $this->query($query); 1241 1294 } 1242 1295 … … 1299 1352 return $sth; 1300 1353 } 1301 $res = &$this->execute($sth, $params);1354 $res = $this->execute($sth, $params); 1302 1355 $this->freePrepared($sth); 1303 1356 } else { 1304 $res = &$this->query($query);1357 $res = $this->query($query); 1305 1358 } 1306 1359 … … 1350 1403 } 1351 1404 1352 $res = &$this->execute($sth, $params);1405 $res = $this->execute($sth, $params); 1353 1406 $this->freePrepared($sth); 1354 1407 } else { 1355 $res = &$this->query($query);1408 $res = $this->query($query); 1356 1409 } 1357 1410 … … 1366 1419 } else { 1367 1420 if (!array_key_exists($col, $row)) { 1368 $ret = &$this->raiseError(DB_ERROR_NOSUCHFIELD);1421 $ret = $this->raiseError(DB_ERROR_NOSUCHFIELD); 1369 1422 } else { 1370 1423 $ret = array($row[$col]); … … 1482 1535 } 1483 1536 1484 $res = &$this->execute($sth, $params);1537 $res = $this->execute($sth, $params); 1485 1538 $this->freePrepared($sth); 1486 1539 } else { 1487 $res = &$this->query($query);1540 $res = $this->query($query); 1488 1541 } 1489 1542 … … 1497 1550 1498 1551 if ($cols < 2) { 1499 $tmp = &$this->raiseError(DB_ERROR_TRUNCATED);1552 $tmp = $this->raiseError(DB_ERROR_TRUNCATED); 1500 1553 return $tmp; 1501 1554 } … … 1601 1654 } 1602 1655 } 1656 1603 1657 if (sizeof($params) > 0) { 1604 1658 $sth = $this->prepare($query); … … 1608 1662 } 1609 1663 1610 $res = &$this->execute($sth, $params);1664 $res = $this->execute($sth, $params); 1611 1665 $this->freePrepared($sth); 1612 1666 } else { 1613 $res = &$this->query($query);1667 $res = $this->query($query); 1614 1668 } 1615 1669 … … 1632 1686 1633 1687 if (DB::isError($row)) { 1634 $tmp = &$this->raiseError($row);1688 $tmp = $this->raiseError($row); 1635 1689 return $tmp; 1636 1690 } … … 1819 1873 * @param mixed native error code, integer or string depending the 1820 1874 * backend 1875 * @param mixed dummy parameter for E_STRICT compatibility with 1876 * PEAR::raiseError 1877 * @param mixed dummy parameter for E_STRICT compatibility with 1878 * PEAR::raiseError 1821 1879 * 1822 1880 * @return object the PEAR_Error object … … 1825 1883 */ 1826 1884 function &raiseError($code = DB_ERROR, $mode = null, $options = null, 1827 $userinfo = null, $nativecode = null) 1885 $userinfo = null, $nativecode = null, $dummy1 = null, 1886 $dummy2 = null) 1828 1887 { 1829 1888 // The error is yet a DB error object … … 2108 2167 2109 2168 // }}} 2169 // {{{ nextQueryIsManip() 2170 2171 /** 2172 * Sets (or unsets) a flag indicating that the next query will be a 2173 * manipulation query, regardless of the usual DB::isManip() heuristics. 2174 * 2175 * @param boolean true to set the flag overriding the isManip() behaviour, 2176 * false to clear it and fall back onto isManip() 2177 * 2178 * @return void 2179 * 2180 * @access public 2181 */ 2182 function nextQueryIsManip($manip) 2183 { 2184 $this->_next_query_manip = $manip; 2185 } 2186 2187 // }}} 2188 // {{{ _checkManip() 2189 2190 /** 2191 * Checks if the given query is a manipulation query. This also takes into 2192 * account the _next_query_manip flag and sets the _last_query_manip flag 2193 * (and resets _next_query_manip) according to the result. 2194 * 2195 * @param string The query to check. 2196 * 2197 * @return boolean true if the query is a manipulation query, false 2198 * otherwise 2199 * 2200 * @access protected 2201 */ 2202 function _checkManip($query) 2203 { 2204 if ($this->_next_query_manip || DB::isManip($query)) { 2205 $this->_last_query_manip = true; 2206 } else { 2207 $this->_last_query_manip = false; 2208 } 2209 $this->_next_query_manip = false; 2210 return $this->_last_query_manip; 2211 $manip = $this->_next_query_manip; 2212 } 2213 2214 // }}} 2110 2215 // {{{ _rtrimArrayValues() 2111 2216
Note: See TracChangeset
for help on using the changeset viewer.