Ignore:
Timestamp:
2009/03/06 20:21:51 (15 years ago)
Author:
Seasoft
Message:

・PEAR::DB を Ver.1.7.14RC1(2007-11-27)ベースに更改。
・不適切な文字列比較を修正。

 http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=1808&forum=9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/comu-ver2/data/module/DB/common.php

    r15532 r17877  
    1919 * @author     Tomas V.V. Cox <cox@idecnet.com> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    4141 * @author     Tomas V.V. Cox <cox@idecnet.com> 
    4242 * @author     Daniel Convissor <danielc@php.net> 
    43  * @copyright  1997-2005 The PHP Group 
     43 * @copyright  1997-2007 The PHP Group 
    4444 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    45  * @version    Release: @package_version@ 
     45 * @version    Release: 1.7.14RC1 
    4646 * @link       http://pear.php.net/package/DB 
    4747 */ 
     
    121121     */ 
    122122    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; 
    123138 
    124139 
     
    425440    function quoteSmart($in) 
    426441    { 
    427         if (is_int($in) || is_double($in)) { 
     442        if (is_int($in)) { 
    428443            return $in; 
     444        } elseif (is_float($in)) { 
     445            return $this->quoteFloat($in); 
    429446        } elseif (is_bool($in)) { 
    430             return $in ? 1 : 0; 
     447            return $this->quoteBoolean($in); 
    431448        } elseif (is_null($in)) { 
    432449            return 'NULL'; 
    433450        } else { 
     451            if ($this->dbsyntax == 'access' 
     452                && preg_match('/^#.+#$/', $in)) 
     453            { 
     454                return $this->escapeSimple($in); 
     455            } 
    434456            return "'" . $this->escapeSimple($in) . "'"; 
    435457        } 
    436458    } 
    437459 
     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      
    438492    // }}} 
    439493    // {{{ escapeSimple() 
     
    838892            return $sth; 
    839893        } 
    840         $ret =& $this->execute($sth, array_values($fields_values)); 
     894        $ret = $this->execute($sth, array_values($fields_values)); 
    841895        $this->freePrepared($sth); 
    842896        return $ret; 
     
    932986     *     'filename.txt' 
    933987     * ); 
    934      * $res =& $db->execute($sth, $data); 
     988     * $res = $db->execute($sth, $data); 
    935989     * </code> 
    936990     * 
     
    9521006    function &execute($stmt, $data = array()) 
    9531007    { 
    954  
    9551008        $realquery = $this->executeEmulateQuery($stmt, $data); 
    9561009        if (DB::isError($realquery)) { 
     
    9621015            return $result; 
    9631016        } else { 
    964             $tmp =& new DB_result($this, $result); 
     1017            $tmp = new DB_result($this, $result); 
    9651018            return $tmp; 
    9661019        } 
     
    9911044        $data = (array)$data; 
    9921045        $this->last_parameters = $data; 
    993      
     1046 
    9941047        if (count($this->prepare_types[$stmt]) != count($data)) { 
    9951048            $this->last_query = $this->prepared_queries[$stmt]; 
     
    10021055        foreach ($data as $value) { 
    10031056            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                } 
    10091062            } elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) { 
    10101063                $fp = @fopen($value, 'rb'); 
     
    10471100    { 
    10481101        foreach ($data as $value) { 
    1049             $res =& $this->execute($stmt, $value); 
     1102            $res = $this->execute($stmt, $value); 
    10501103            if (DB::isError($res)) { 
    10511104                return $res; 
     
    11601213                return $sth; 
    11611214            } 
    1162             $ret =& $this->execute($sth, $params); 
     1215            $ret = $this->execute($sth, $params); 
    11631216            $this->freePrepared($sth, false); 
    11641217            return $ret; 
     
    11691222                return $result; 
    11701223            } else { 
    1171                 $tmp =& new DB_result($this, $result); 
     1224                $tmp = new DB_result($this, $result); 
    11721225                return $tmp; 
    11731226            } 
     
    12001253            return $query; 
    12011254        } 
    1202         $result =& $this->query($query, $params); 
     1255        $result = $this->query($query, $params); 
    12031256        if (is_a($result, 'DB_result')) { 
    12041257            $result->setOption('limit_from', $from); 
     
    12351288                return $sth; 
    12361289            } 
    1237             $res =& $this->execute($sth, $params); 
     1290            $res = $this->execute($sth, $params); 
    12381291            $this->freePrepared($sth); 
    12391292        } else { 
    1240             $res =& $this->query($query); 
     1293            $res = $this->query($query); 
    12411294        } 
    12421295 
     
    12991352                return $sth; 
    13001353            } 
    1301             $res =& $this->execute($sth, $params); 
     1354            $res = $this->execute($sth, $params); 
    13021355            $this->freePrepared($sth); 
    13031356        } else { 
    1304             $res =& $this->query($query); 
     1357            $res = $this->query($query); 
    13051358        } 
    13061359 
     
    13501403            } 
    13511404 
    1352             $res =& $this->execute($sth, $params); 
     1405            $res = $this->execute($sth, $params); 
    13531406            $this->freePrepared($sth); 
    13541407        } else { 
    1355             $res =& $this->query($query); 
     1408            $res = $this->query($query); 
    13561409        } 
    13571410 
     
    13661419        } else { 
    13671420            if (!array_key_exists($col, $row)) { 
    1368                 $ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD); 
     1421                $ret = $this->raiseError(DB_ERROR_NOSUCHFIELD); 
    13691422            } else { 
    13701423                $ret = array($row[$col]); 
     
    14821535            } 
    14831536 
    1484             $res =& $this->execute($sth, $params); 
     1537            $res = $this->execute($sth, $params); 
    14851538            $this->freePrepared($sth); 
    14861539        } else { 
    1487             $res =& $this->query($query); 
     1540            $res = $this->query($query); 
    14881541        } 
    14891542 
     
    14971550 
    14981551        if ($cols < 2) { 
    1499             $tmp =& $this->raiseError(DB_ERROR_TRUNCATED); 
     1552            $tmp = $this->raiseError(DB_ERROR_TRUNCATED); 
    15001553            return $tmp; 
    15011554        } 
     
    16011654            } 
    16021655        } 
     1656 
    16031657        if (sizeof($params) > 0) { 
    16041658            $sth = $this->prepare($query); 
     
    16081662            } 
    16091663 
    1610             $res =& $this->execute($sth, $params); 
     1664            $res = $this->execute($sth, $params); 
    16111665            $this->freePrepared($sth); 
    16121666        } else { 
    1613             $res =& $this->query($query); 
     1667            $res = $this->query($query); 
    16141668        } 
    16151669 
     
    16321686 
    16331687        if (DB::isError($row)) { 
    1634             $tmp =& $this->raiseError($row); 
     1688            $tmp = $this->raiseError($row); 
    16351689            return $tmp; 
    16361690        } 
     
    18191873     * @param mixed   native error code, integer or string depending the 
    18201874     *                 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 
    18211879     * 
    18221880     * @return object  the PEAR_Error object 
     
    18251883     */ 
    18261884    function &raiseError($code = DB_ERROR, $mode = null, $options = null, 
    1827                          $userinfo = null, $nativecode = null) 
     1885                         $userinfo = null, $nativecode = null, $dummy1 = null, 
     1886                         $dummy2 = null) 
    18281887    { 
    18291888        // The error is yet a DB error object 
     
    21082167 
    21092168    // }}} 
     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    // }}} 
    21102215    // {{{ _rtrimArrayValues() 
    21112216 
Note: See TracChangeset for help on using the changeset viewer.