Changeset 19690


Ignore:
Timestamp:
2010/11/30 02:50:21 (13 years ago)
Author:
AMUAMU
Message:

#564 MDB2化による各種問題の改善
#835 郵便番号辞書の登録でエラーになる(MySQL)の問題改善
#515 SC_Query内のPHP5.3非推奨関数の除去(PHP5.3対応)
#781 INSERT/UPDATEの速度向上(規格のデータベースを木構造に)

SC_Queryがメモリリークしている問題の改善を全面的に行った、副次的に #835 が改善。
テストデータ作成スクリプトがMySQLでデータ作成が出来ない問題も改善。
これによりmemory_limitが低い環境や、DBのプロセスあたりのメモリ最大使用量が低い環境でも動くようになったはず。

UPDATE/INSERT/DELETE時に正しい返値を返さない問題の修正(反映された数が正しく帰るようにした。queryに残っていたDML実行時のTODOも解決。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/SC_Query.php

    r19675 r19690  
    5555        } 
    5656 
    57         // Debugモード指定 
    58         $options['debug'] = PEAR_DB_DEBUG; 
     57        // Debugモード指定  
     58        // 常時ONにするとメモリが解放されない。 
     59        // 連続クエリ実行時に問題が生じる。 
     60        if(DEBUG_MODE) { 
     61            $options['debug'] = PEAR_DB_DEBUG; 
     62        } else { 
     63            $options['debug'] = 0; 
     64        } 
     65 
    5966        // 持続的接続オプション 
    6067        $options['persistent'] = PEAR_DB_PERSISTENT; 
     68 
     69        // バッファリング trueにするとメモリが解放されない。 
     70        // 連続クエリ実行時に問題が生じる。 
     71        $options['result_buffering'] = false; 
    6172 
    6273        if ($new) { 
     
    411422 
    412423        if(count($sqlval) <= 0 ) return false; 
    413  
    414424        foreach ($sqlval as $key => $val) { 
    415425            $strcol .= $key . ','; 
    416             if(eregi("^Now\(\)$", $val)) { 
     426            if(strcasecmp("Now()", $val) === 0) { 
    417427                $strval .= 'Now(),'; 
     428            } else if(strpos($val, '~') === 0) { 
     429                $strval .= preg_replace("/^~/", "", $val); 
    418430            } else { 
    419431                $strval .= '?,'; 
     
    426438        } 
    427439        // 文末の","を削除 
    428         $strcol = ereg_replace(",$","",$strcol); 
    429         // 文末の","を削除 
    430         $strval = ereg_replace(",$","",$strval); 
     440        $strcol = preg_replace("/,$/", "", $strcol); 
     441        $strval = preg_replace("/,$/", "", $strval); 
    431442        $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; 
    432443        // INSERT文の実行 
    433         $ret = $this->query($sqlin, $arrval); 
     444        $ret = $this->query($sqlin, $arrval, false, null, MDB2_PREPARE_MANIP); 
    434445 
    435446        return $ret; 
     
    451462        $arrVal = array(); 
    452463        $find = false; 
     464 
    453465        foreach ($sqlval as $key => $val) { 
    454             if (eregi("^Now\(\)$", $val)) { 
     466            if (strcasecmp("Now()", $val) === 0) { 
    455467                $arrCol[] = $key . '= Now()'; 
     468            } else if(strpos('~', $val) === 0) { 
     469                $arrCol[] = $key . '= ' . $val; 
    456470            } else { 
    457471                $arrCol[] = $key . '= ?'; 
     
    487501 
    488502        // UPDATE文の実行 
    489         return $this->query($sqlup, $arrVal); 
     503        return $this->query($sqlup, $arrVal, false, null, MDB2_PREPARE_MANIP); 
    490504    } 
    491505 
     
    626640            $sqlde = "DELETE FROM $table WHERE $where"; 
    627641        } 
    628         $ret = $this->query($sqlde, $arrval); 
     642        $ret = $this->query($sqlde, $arrval, false, null, MDB2_PREPARE_MANIP); 
    629643        return $ret; 
    630644    } 
     
    667681     * SQL を実行する. 
    668682     * 
    669      * XXX 更新系には exec() を使用するべき 
     683     * FIXME $ignore_errが無視されるようになっているが互換性として問題が無いか確認が必要 
    670684     * 
    671685     * @param string $n 実行する SQL 文 
    672      * @param array $arrval ブレースホルダに挿入する値 
     686     * @param array $arr ブレースホルダに挿入する値 
     687     * @param boolean $ignore_err MDB2切替で無効化されている (エラーが発生しても処理を続行する場合 true) 
     688     * @param mixed $types プレースホルダの型指定 デフォルトnull = string 
     689     * @param mixed $result_types 返値の型指定またはDML実行(MDB2_PREPARE_MANIP) 
    673690     * @return array SQL の実行結果の配列 
    674691     */ 
    675     function query($n ,$arr = array(), $ignore_err = false){ 
     692    function query($n ,$arr = array(), $ignore_err = false, $types = null, $result_types = MDB2_PREPARE_RESULT ){ 
    676693 
    677694        $n = $this->dbFactory->sfChangeMySQL($n); 
    678695 
    679         $sth =& $this->prepare($n); 
     696        $sth =& $this->prepare($n, $types, $result_types); 
    680697        if (PEAR::isError($sth) && $this->force_run) { 
    681698            return; 
     
    686703            return; 
    687704        } 
    688  
     705         
     706        //PREPAREの解放 
     707        $sth->free(); 
     708         
    689709        return $result; 
    690710    } 
     
    775795     * @access private 
    776796     * @param string $sql プリペアドステートメントを構築する SQL 
     797     * @param mixed $types プレースホルダの型指定 デフォルト null 
     798     * @param mixed $result_types 返値の型指定またはDML実行(MDB2_PREPARE_MANIP)、nullは指定無し 
    777799     * @return MDB2_Statement_Common プリペアドステートメントインスタンス 
    778800     */ 
    779     function prepare($sql) { 
    780         $sth =& $this->conn->prepare($sql); 
     801    function prepare($sql, $types = null, $result_types = MDB2_PREPARE_RESULT) { 
     802        $sth =& $this->conn->prepare($sql, $types, $result_types); 
    781803        if (PEAR::isError($sth)) { 
    782804            if (!$this->force_run) { 
Note: See TracChangeset for help on using the changeset viewer.