Ignore:
Timestamp:
2013/08/02 13:22:57 (11 years ago)
Author:
Seasoft
Message:

#2322 (セッションのGC処理がエラーとなる)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13-dev/data/module/MDB2/Driver/mysql.php

    r20764 r23022  
    4444// +----------------------------------------------------------------------+ 
    4545// 
    46 // $Id: mysql.php,v 1.214 2008/11/16 21:45:08 quipo Exp $ 
     46// $Id: mysql.php 327320 2012-08-27 15:52:50Z danielc $ 
    4747// 
    4848 
     
    5858    // {{{ properties 
    5959 
    60     var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => '\\', 'escape_pattern' => '\\'); 
    61  
    62     var $identifier_quoting = array('start' => '`', 'end' => '`', 'escape' => '`'); 
    63  
    64     var $sql_comments = array( 
     60    public $string_quoting = array( 
     61        'start' => "'", 
     62        'end' => "'", 
     63        'escape' => '\\', 
     64        'escape_pattern' => '\\', 
     65    ); 
     66 
     67    public $identifier_quoting = array( 
     68        'start' => '`', 
     69        'end' => '`', 
     70        'escape' => '`', 
     71    ); 
     72 
     73    public $sql_comments = array( 
    6574        array('start' => '-- ', 'end' => "\n", 'escape' => false), 
    6675        array('start' => '#', 'end' => "\n", 'escape' => false), 
     
    6877    ); 
    6978 
    70     var $server_capabilities_checked = false; 
    71  
    72     var $start_transaction = false; 
    73  
    74     var $varchar_max_length = 255; 
     79    protected $server_capabilities_checked = false; 
     80 
     81    protected $start_transaction = false; 
     82 
     83    public $varchar_max_length = 255; 
    7584 
    7685    // }}} 
     
    118127    // }}} 
    119128    // {{{ _reCheckSupportedOptions() 
    120      
     129 
    121130    /** 
    122131     * If the user changes certain options, other capabilities may depend 
     
    298307        } 
    299308        $connection = $this->getConnection(); 
    300         if (PEAR::isError($connection)) { 
     309        if (MDB2::isError($connection)) { 
    301310            return $connection; 
    302311        } 
     
    339348        } 
    340349        $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 0'; 
    341         $result =& $this->_doQuery($query, true); 
    342         if (PEAR::isError($result)) { 
     350        $result = $this->_doQuery($query, true); 
     351        if (MDB2::isError($result)) { 
    343352            return $result; 
    344353        } 
     
    386395        } 
    387396 
    388         $result =& $this->_doQuery('COMMIT', true); 
    389         if (PEAR::isError($result)) { 
     397        $result = $this->_doQuery('COMMIT', true); 
     398        if (MDB2::isError($result)) { 
    390399            return $result; 
    391400        } 
    392401        if (!$this->start_transaction) { 
    393402            $query = 'SET AUTOCOMMIT = 1'; 
    394             $result =& $this->_doQuery($query, true); 
    395             if (PEAR::isError($result)) { 
     403            $result = $this->_doQuery($query, true); 
     404            if (MDB2::isError($result)) { 
    396405                return $result; 
    397406            } 
     
    432441 
    433442        $query = 'ROLLBACK'; 
    434         $result =& $this->_doQuery($query, true); 
    435         if (PEAR::isError($result)) { 
     443        $result = $this->_doQuery($query, true); 
     444        if (MDB2::isError($result)) { 
    436445            return $result; 
    437446        } 
    438447        if (!$this->start_transaction) { 
    439448            $query = 'SET AUTOCOMMIT = 1'; 
    440             $result =& $this->_doQuery($query, true); 
    441             if (PEAR::isError($result)) { 
     449            $result = $this->_doQuery($query, true); 
     450            if (MDB2::isError($result)) { 
    442451                return $result; 
    443452            } 
     
    458467     *                  REPEATABLE READ (prevents nonrepeatable reads) 
    459468     *                  SERIALIZABLE (prevents phantom reads) 
     469     * @param   array some transaction options: 
     470     *                  'wait' => 'WAIT' | 'NO WAIT' 
     471     *                  'rw'   => 'READ WRITE' | 'READ ONLY' 
     472     * 
    460473     * @return  mixed   MDB2_OK on success, a MDB2 error on failure 
    461474     * 
     
    463476     * @since   2.1.1 
    464477     */ 
    465     function setTransactionIsolation($isolation) 
     478    function setTransactionIsolation($isolation, $options = array()) 
    466479    { 
    467480        $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true)); 
     
    496509    function _doConnect($username, $password, $persistent = false) 
    497510    { 
    498         if (!PEAR::loadExtension($this->phptype)) { 
     511        if (!extension_loaded($this->phptype)) { 
    499512            return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 
    500513                'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__); 
     
    502515 
    503516        $params = array(); 
    504         if ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix') { 
     517        $unix = ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix'); 
     518        if (empty($this->dsn['hostspec'])) { 
     519            $this->dsn['hostspec'] = $unix ? '' : 'localhost'; 
     520        } 
     521        if ($this->dsn['hostspec']) { 
     522            $params[0] = $this->dsn['hostspec'] . ($this->dsn['port'] ? ':' . $this->dsn['port'] : ''); 
     523        } else { 
    505524            $params[0] = ':' . $this->dsn['socket']; 
    506         } else { 
    507             $params[0] = $this->dsn['hostspec'] ? $this->dsn['hostspec'] 
    508                          : 'localhost'; 
    509             if ($this->dsn['port']) { 
    510                 $params[0].= ':' . $this->dsn['port']; 
    511             } 
    512525        } 
    513526        $params[] = $username ? $username : null; 
     
    539552        if (!empty($this->dsn['charset'])) { 
    540553            $result = $this->setCharset($this->dsn['charset'], $connection); 
    541             if (PEAR::isError($result)) { 
     554            if (MDB2::isError($result)) { 
    542555                $this->disconnect(false); 
    543556                return $result; 
     
    574587            $this->options['persistent'] 
    575588        ); 
    576         if (PEAR::isError($connection)) { 
     589        if (MDB2::isError($connection)) { 
    577590            return $connection; 
    578591        } 
     
    615628        if (is_null($connection)) { 
    616629            $connection = $this->getConnection(); 
    617             if (PEAR::isError($connection)) { 
     630            if (MDB2::isError($connection)) { 
    618631                return $connection; 
    619632            } 
     
    627640        if (function_exists('mysql_set_charset') && version_compare($client_info, '5.0.6')) { 
    628641            if (!$result = mysql_set_charset($charset, $connection)) { 
    629                 $err =& $this->raiseError(null, null, null, 
     642                $err = $this->raiseError(null, null, null, 
    630643                    'Could not set client character set', __FUNCTION__); 
    631644                return $err; 
     
    635648        $query = "SET NAMES '".mysql_real_escape_string($charset, $connection)."'"; 
    636649        if (!is_null($collation)) { 
    637             $query .= " COLLATE '".mysqli_real_escape_string($connection, $collation)."'"; 
     650            $query .= " COLLATE '".mysql_real_escape_string($collation, $connection)."'"; 
    638651        } 
    639652        return $this->_doQuery($query, true, $connection); 
     
    656669                                        $this->dsn['password'], 
    657670                                        $this->options['persistent']); 
    658         if (PEAR::isError($connection)) { 
     671        if (MDB2::isError($connection)) { 
    659672            return $connection; 
    660673        } 
     
    710723    // {{{ standaloneQuery() 
    711724 
    712    /** 
     725    /** 
    713726     * execute a query as DBA 
    714727     * 
     
    720733     * @access public 
    721734     */ 
    722     function &standaloneQuery($query, $types = null, $is_manip = false) 
     735    function standaloneQuery($query, $types = null, $is_manip = false) 
    723736    { 
    724737        $user = $this->options['DBA_username']? $this->options['DBA_username'] : $this->dsn['username']; 
    725738        $pass = $this->options['DBA_password']? $this->options['DBA_password'] : $this->dsn['password']; 
    726739        $connection = $this->_doConnect($user, $pass, $this->options['persistent']); 
    727         if (PEAR::isError($connection)) { 
     740        if (MDB2::isError($connection)) { 
    728741            return $connection; 
    729742        } 
     
    733746        $this->offset = $this->limit = 0; 
    734747        $query = $this->_modifyQuery($query, $is_manip, $limit, $offset); 
    735          
    736         $result =& $this->_doQuery($query, $is_manip, $connection, $this->database_name); 
    737         if (!PEAR::isError($result)) { 
     748 
     749        $result = $this->_doQuery($query, $is_manip, $connection, $this->database_name); 
     750        if (!MDB2::isError($result)) { 
    738751            $result = $this->_affectedRows($connection, $result); 
    739752        } 
     
    755768     * @access protected 
    756769     */ 
    757     function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null) 
     770    function _doQuery($query, $is_manip = false, $connection = null, $database_name = null) 
    758771    { 
    759772        $this->last_query = $query; 
    760773        $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre')); 
    761774        if ($result) { 
    762             if (PEAR::isError($result)) { 
     775            if (MDB2::isError($result)) { 
    763776                return $result; 
    764777            } 
     
    772785        if (is_null($connection)) { 
    773786            $connection = $this->getConnection(); 
    774             if (PEAR::isError($connection)) { 
     787            if (MDB2::isError($connection)) { 
    775788                return $connection; 
    776789            } 
     
    794807            ? 'mysql_query' : 'mysql_unbuffered_query'; 
    795808        $result = @$function($query, $connection); 
    796         if (!$result) { 
    797             $err =& $this->raiseError(null, null, null, 
     809        if (!$result && 0 !== mysql_errno($connection)) { 
     810            $err = $this->raiseError(null, null, null, 
    798811                'Could not execute statement', __FUNCTION__); 
    799812            return $err; 
     
    819832        if (is_null($connection)) { 
    820833            $connection = $this->getConnection(); 
    821             if (PEAR::isError($connection)) { 
     834            if (MDB2::isError($connection)) { 
    822835                return $connection; 
    823836            } 
     
    893906    { 
    894907        $connection = $this->getConnection(); 
    895         if (PEAR::isError($connection)) { 
     908        if (MDB2::isError($connection)) { 
    896909            return $connection; 
    897910        } 
     
    946959            $this->start_transaction = false; 
    947960            $this->varchar_max_length = 255; 
    948              
     961 
    949962            $server_info = $this->getServerVersion(); 
    950963            if (is_array($server_info)) { 
     
    984997 
    985998    /** 
    986      * Utility method, used by prepare() to avoid misinterpreting MySQL user  
     999     * Utility method, used by prepare() to avoid misinterpreting MySQL user 
    9871000     * defined variables (SELECT @x:=5) for placeholders. 
    9881001     * Check if the placeholder is a false positive, i.e. if it is an user defined 
     
    10331046     * @see bindParam, execute 
    10341047     */ 
    1035     function &prepare($query, $types = null, $result_types = null, $lobs = array()) 
    1036     { 
     1048    function prepare($query, $types = null, $result_types = null, $lobs = array()) 
     1049    { 
     1050        // connect to get server capabilities (http://pear.php.net/bugs/16147) 
     1051        $connection = $this->getConnection(); 
     1052        if (MDB2::isError($connection)) { 
     1053            return $connection; 
     1054        } 
     1055 
    10371056        if ($this->options['emulate_prepared'] 
    10381057            || $this->supported['prepared_statements'] !== true 
    10391058        ) { 
    1040             $obj =& parent::prepare($query, $types, $result_types, $lobs); 
    1041             return $obj; 
     1059            return parent::prepare($query, $types, $result_types, $lobs); 
    10421060        } 
    10431061        $is_manip = ($result_types === MDB2_PREPARE_MANIP); 
     
    10481066        $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre')); 
    10491067        if ($result) { 
    1050             if (PEAR::isError($result)) { 
     1068            if (MDB2::isError($result)) { 
    10511069                return $result; 
    10521070            } 
     
    10731091                $placeholder_type_guess = $query[$p_position]; 
    10741092            } 
    1075              
     1093 
    10761094            $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position); 
    1077             if (PEAR::isError($new_pos)) { 
     1095            if (MDB2::isError($new_pos)) { 
    10781096                return $new_pos; 
    10791097            } 
     
    10821100                continue; //evaluate again starting from the new position 
    10831101            } 
    1084              
     1102 
    10851103            //make sure this is not part of an user defined variable 
    10861104            $new_pos = $this->_skipUserDefinedVariable($query, $position); 
     
    10991117                    $parameter = preg_replace($regexp, '\\1', $query); 
    11001118                    if ($parameter === '') { 
    1101                         $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, 
     1119                        $err = $this->raiseError(MDB2_ERROR_SYNTAX, null, null, 
    11021120                            'named parameter name must match "bindname_format" option', __FUNCTION__); 
    11031121                        return $err; 
     
    11131131            } 
    11141132        } 
    1115         $connection = $this->getConnection(); 
    1116         if (PEAR::isError($connection)) { 
    1117             return $connection; 
    1118         } 
     1133 
    11191134        static $prep_statement_counter = 1; 
    11201135        $statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter++ . sha1(microtime() + mt_rand())); 
    11211136        $statement_name = substr(strtolower($statement_name), 0, $this->options['max_identifiers_length']); 
    11221137        $query = "PREPARE $statement_name FROM ".$this->quote($query, 'text'); 
    1123         $statement =& $this->_doQuery($query, true, $connection); 
    1124         if (PEAR::isError($statement)) { 
     1138        $statement = $this->_doQuery($query, true, $connection); 
     1139        if (MDB2::isError($statement)) { 
    11251140            return $statement; 
    11261141        } 
     
    12161231                $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null; 
    12171232                $value = $this->quote($fields[$name]['value'], $type); 
    1218                 if (PEAR::isError($value)) { 
     1233                if (MDB2::isError($value)) { 
    12191234                    return $value; 
    12201235                } 
     
    12351250 
    12361251        $connection = $this->getConnection(); 
    1237         if (PEAR::isError($connection)) { 
     1252        if (MDB2::isError($connection)) { 
    12381253            return $connection; 
    12391254        } 
     
    12411256        $table = $this->quoteIdentifier($table, true); 
    12421257        $query = "REPLACE INTO $table ($query) VALUES ($values)"; 
    1243         $result =& $this->_doQuery($query, true, $connection); 
    1244         if (PEAR::isError($result)) { 
     1258        $result = $this->_doQuery($query, true, $connection); 
     1259        if (MDB2::isError($result)) { 
    12451260            return $result; 
    12461261        } 
     
    12691284        $this->pushErrorHandling(PEAR_ERROR_RETURN); 
    12701285        $this->expectError(MDB2_ERROR_NOSUCHTABLE); 
    1271         $result =& $this->_doQuery($query, true); 
     1286        $result = $this->_doQuery($query, true); 
    12721287        $this->popExpect(); 
    12731288        $this->popErrorHandling(); 
    1274         if (PEAR::isError($result)) { 
     1289        if (MDB2::isError($result)) { 
    12751290            if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) { 
    12761291                $this->loadModule('Manager', null, true); 
    12771292                $result = $this->manager->createSequence($seq_name); 
    1278                 if (PEAR::isError($result)) { 
     1293                if (MDB2::isError($result)) { 
    12791294                    return $this->raiseError($result, null, null, 
    12801295                        'on demand sequence '.$seq_name.' could not be created', __FUNCTION__); 
     
    12881303        if (is_numeric($value)) { 
    12891304            $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value"; 
    1290             $result =& $this->_doQuery($query, true); 
    1291             if (PEAR::isError($result)) { 
     1305            $result = $this->_doQuery($query, true); 
     1306            if (MDB2::isError($result)) { 
    12921307                $this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name; 
    12931308            } 
     
    13111326    { 
    13121327        // not using mysql_insert_id() due to http://pear.php.net/bugs/bug.php?id=8051 
    1313         return $this->queryOne('SELECT LAST_INSERT_ID()', 'integer'); 
     1328        // not casting to integer to handle BIGINT http://pear.php.net/bugs/bug.php?id=17650 
     1329        return $this->queryOne('SELECT LAST_INSERT_ID()'); 
    13141330    } 
    13151331 
     
    13531369     * @access public 
    13541370     */ 
    1355     function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 
     1371    function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) 
    13561372    { 
    13571373        if (!is_null($rownum)) { 
    13581374            $seek = $this->seek($rownum); 
    1359             if (PEAR::isError($seek)) { 
     1375            if (MDB2::isError($seek)) { 
    13601376                return $seek; 
    13611377            } 
     
    13641380            $fetchmode = $this->db->fetchmode; 
    13651381        } 
    1366         if ($fetchmode & MDB2_FETCHMODE_ASSOC) { 
     1382        if (   $fetchmode == MDB2_FETCHMODE_ASSOC 
     1383            || $fetchmode == MDB2_FETCHMODE_OBJECT 
     1384        ) { 
    13671385            $row = @mysql_fetch_assoc($this->result); 
    13681386            if (is_array($row) 
     
    13771395        if (!$row) { 
    13781396            if ($this->result === false) { 
    1379                 $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
     1397                $err = $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 
    13801398                    'resultset has already been freed', __FUNCTION__); 
    13811399                return $err; 
    13821400            } 
    1383             $null = null; 
    1384             return $null; 
     1401            return null; 
    13851402        } 
    13861403        $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; 
     
    13961413            $this->db->_fixResultArrayValues($row, $mode); 
    13971414        } 
    1398         if (!empty($this->types)) { 
     1415        if (   (   $fetchmode != MDB2_FETCHMODE_ASSOC 
     1416                && $fetchmode != MDB2_FETCHMODE_OBJECT) 
     1417            && !empty($this->types) 
     1418        ) { 
    13991419            $row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim); 
     1420        } elseif (($fetchmode == MDB2_FETCHMODE_ASSOC 
     1421                || $fetchmode == MDB2_FETCHMODE_OBJECT) 
     1422            && !empty($this->types_assoc) 
     1423        ) { 
     1424            $row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim); 
    14001425        } 
    14011426        if (!empty($this->values)) { 
     
    14071432                $row = (object) $row; 
    14081433            } else { 
    1409                 $row = &new $object_class($row); 
     1434                $rowObj = new $object_class($row); 
     1435                $row = $rowObj; 
    14101436            } 
    14111437        } 
     
    14301456        $columns = array(); 
    14311457        $numcols = $this->numCols(); 
    1432         if (PEAR::isError($numcols)) { 
     1458        if (MDB2::isError($numcols)) { 
    14331459            return $numcols; 
    14341460        } 
     
    15391565    { 
    15401566        $numrows = $this->numRows(); 
    1541         if (PEAR::isError($numrows)) { 
     1567        if (MDB2::isError($numrows)) { 
    15421568            return $numrows; 
    15431569        } 
     
    15691595        return $rows; 
    15701596    } 
     1597 
     1598    // }}} 
    15711599} 
    15721600 
     
    15921620     * @access private 
    15931621     */ 
    1594     function &_execute($result_class = true, $result_wrap_class = false) 
     1622    function _execute($result_class = true, $result_wrap_class = true) 
    15951623    { 
    15961624        if (is_null($this->statement)) { 
    1597             $result =& parent::_execute($result_class, $result_wrap_class); 
     1625            $result = parent::_execute($result_class, $result_wrap_class); 
    15981626            return $result; 
    15991627        } 
     
    16061634 
    16071635        $connection = $this->db->getConnection(); 
    1608         if (PEAR::isError($connection)) { 
     1636        if (MDB2::isError($connection)) { 
    16091637            return $connection; 
    16101638        } 
     
    16181646                        'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__); 
    16191647                } 
     1648                $close = false; 
    16201649                $value = $this->values[$parameter]; 
    16211650                $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null; 
     
    16401669                } 
    16411670                $quoted = $this->db->quote($value, $type); 
    1642                 if (PEAR::isError($quoted)) { 
     1671                if (MDB2::isError($quoted)) { 
    16431672                    return $quoted; 
    16441673                } 
    16451674                $param_query = 'SET @'.$parameter.' = '.$quoted; 
    16461675                $result = $this->db->_doQuery($param_query, true, $connection); 
    1647                 if (PEAR::isError($result)) { 
     1676                if (MDB2::isError($result)) { 
    16481677                    return $result; 
    16491678                } 
     
    16531682 
    16541683        $result = $this->db->_doQuery($query, $this->is_manip, $connection); 
    1655         if (PEAR::isError($result)) { 
     1684        if (MDB2::isError($result)) { 
    16561685            return $result; 
    16571686        } 
     
    16621691        } 
    16631692 
    1664         $result =& $this->db->_wrapResult($result, $this->result_types, 
     1693        $result = $this->db->_wrapResult($result, $this->result_types, 
    16651694            $result_class, $result_wrap_class, $this->limit, $this->offset); 
    16661695        $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'post', 'result' => $result)); 
     
    16871716        if (!is_null($this->statement)) { 
    16881717            $connection = $this->db->getConnection(); 
    1689             if (PEAR::isError($connection)) { 
     1718            if (MDB2::isError($connection)) { 
    16901719                return $connection; 
    16911720            } 
Note: See TracChangeset for help on using the changeset viewer.