source: branches/comu-ver2/patches/MDB2.patch @ 18755

Revision 18755, 6.9 KB checked in by nanasess, 14 years ago (diff)

MDB2 に置き替えるためのパッチを追加(#564)

  • Property svn:keywords set to Id Revision Date
  • html/define.php

     
    22/** HTMLディレクトリからのDATAディレクトリの相対パス */ 
    33define("HTML2DATA_DIR", "../data/"); 
    44 
     5/** data/module 以下の PEAR ライブラリのみを使用する */ 
     6set_include_path(realpath(dirname(__FILE__) . "/" . HTML2DATA_DIR . "module")); 
     7 
    58/** 
    69 * DIR_INDEX_FILE にアクセスするときにファイル名を使用するか 
    710 * 
  • data/class/SC_DbConn.php

     
    2222 */ 
    2323 
    2424$current_dir = realpath(dirname(__FILE__)); 
    25 require_once($current_dir . "/../module/DB.php"); 
     25require_once($current_dir . "/../module/MDB2.php"); 
    2626 
    2727$g_arr_objDbConn = array(); 
    2828 
     
    6060        } 
    6161 
    6262        if ($new) { 
    63             $this->conn = DB::connect($this->dsn, $options); 
     63            // TODO singleton の方が良いかも 
     64            $this->conn = MDB2::connect($this->dsn, $options); 
    6465            $g_arr_objDbConn[$this->dsn] = $this->conn; 
    6566 
     67            // TODO MDB2::setCharset() を使った方が良い? 
    6668            if (DB_TYPE == 'mysql') { 
    6769                $g_arr_objDbConn[$this->dsn]->query('SET NAMES utf8'); // FIXME mysql_set_charset を使える環境では、その方が良さそう (2010/03/03 Seasoft 塚田) 
    6870                $g_arr_objDbConn[$this->dsn]->query("SET SESSION sql_mode = 'ANSI'"); 
     
    7173            $this->conn = $g_arr_objDbConn[$this->dsn]; 
    7274        } 
    7375 
     76        $this->conn->setFetchMode(MDB2_FETCHMODE_ASSOC); 
    7477        $this->err_disp = $err_disp; 
    7578        $this->dbFactory = SC_DB_DBFactory_Ex::getInstance(); 
    7679    } 
    7780 
    7881    // クエリの実行 
    79     function query($n ,$arr = "", $ignore_err = false){ 
     82    function query($n ,$arr = array(), $ignore_err = false){ 
    8083        // mysqlの場合にはビュー表を変換する 
    8184        if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 
    8285 
     86        $sth = $this->conn->prepare($n); 
    8387        if ( $arr ) { 
    84             $result = $this->conn->query($n, $arr); 
     88            $result = $sth->execute($arr); 
    8589        } else { 
    86             $result = $this->conn->query($n); 
     90            $result = $sth->execute(); 
    8791        } 
    8892 
    8993        if ($this->conn->isError($result) && !$ignore_err){ 
     
    9599    } 
    96100 
    97101    // 一件のみ取得 
    98     function getOne($n, $arr = ""){ 
     102    function getOne($n, $arr = array()){ 
    99103 
    100104        // mysqlの場合にはビュー表を変換する 
    101105        if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 
    102106 
     107        $sth = $this->conn->prepare($n); 
    103108        if ( $arr ) { 
    104             $result = $this->conn->getOne($n, $arr); 
     109            $affected = $sth->execute($arr); 
    105110        } else { 
    106             $result = $this->conn->getOne($n); 
     111            $affected = $sth->execute(); 
    107112        } 
    108         if ($this->conn->isError($result)){ 
    109             $this->send_err_mail($result ,$n); 
     113 
     114        if ($this->conn->isError($affected)){ 
     115            $this->send_err_mail($affected ,$n); 
    110116        } 
    111         $this->result = $result; 
    112  
     117        $this->result = $affected->fetchOne(); 
    113118        return $this->result; 
    114119    } 
    115120     
     
    125130         
    126131        // mysqlの場合にはビュー表を変換する 
    127132        if (DB_TYPE == "mysql") $sql = $this->dbFactory->sfChangeMySQL($sql); 
     133 
     134        $sth = $this->conn->prepare($n); 
     135        if ($arr) { 
     136            $affected = $sth->execute($arr); 
     137        } else { 
     138            $affected = $sth->execute(); 
     139        } 
     140        if ($this->conn->isError($affected)) { 
     141            $this->send_err_mail($affected, $n); 
     142        } 
     143        $this->result = $affected->fetchRow($fetchmode); 
    128144         
    129         $result = $this->conn->getRow($sql, $arrVal ,$fetchmode); 
    130          
    131         if ($this->conn->isError($result)){ 
    132             $this->send_err_mail($result ,$sql); 
    133         } 
    134         $this->result = $result; 
    135145        return $this->result; 
    136146    } 
    137147 
    138     function getCol($n, $col, $arr = "") { 
     148    function getCol($n, $col, $arr = array()) { 
    139149 
    140150        // mysqlの場合にはビュー表を変換する 
    141151        if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 
    142152 
     153        $sth = $this->conn->prepare($n); 
    143154        if ($arr) { 
    144             $result = $this->conn->getCol($n, $col, $arr); 
     155            $affected = $sth->execute($arr); 
    145156        } else { 
    146             $result = $this->conn->getCol($n, $col); 
     157            $affected = $sth->execute(); 
    147158        } 
    148         if ($this->conn->isError($result)) { 
    149             $this->send_err_mail($result, $n); 
     159        if ($this->conn->isError($affected)) { 
     160            $this->send_err_mail($affected, $n); 
    150161        } 
    151         $this->result = $result; 
     162        $this->result = $affected->fetchCol($col); 
    152163        return $this->result; 
    153164    } 
    154165 
     
    160171     * @param integer $fetchmode 使用するフェッチモード。デフォルトは DB_FETCHMODE_ASSOC。 
    161172     * @return array データを含む2次元配列。失敗した場合に 0 または DB_Error オブジェクトを返します。 
    162173     */ 
    163     function getAll($sql, $arrVal = "", $fetchmode = DB_FETCHMODE_ASSOC) { 
     174    function getAll($sql, $arrVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 
    164175 
    165176        // mysqlの場合にはビュー表を変換する 
    166177        if (DB_TYPE == "mysql") $sql = $this->dbFactory->sfChangeMySQL($sql); 
     
    175186            return 0; 
    176187        } 
    177188 
     189        $sth = $this->conn->prepare($sql); 
     190 
    178191        if ($arrVal) { // FIXME 判定が曖昧 
    179             $result = $this->conn->getAll($sql, $arrVal, $fetchmode); 
     192            $affected = $sth->execute($arrVal); 
    180193        } else { 
    181             $result = $this->conn->getAll($sql, $fetchmode); 
     194            $affected = $sth->execute(); 
    182195        } 
    183196 
    184         if ($this->conn->isError($result)) { 
    185             $this->send_err_mail($result, $sql); 
     197        if ($this->conn->isError($affected)) { 
     198            $this->send_err_mail($affected, $sql); 
    186199        } 
    187         $this->result = $result; 
     200        $this->result = $affected->fetchAll($fetchmode); 
    188201 
    189202        return $this->result; 
    190203    } 
  • data/class/SC_Query.php

     
    8888     * @param integer $fetchmode 使用するフェッチモード。デフォルトは DB_FETCHMODE_ASSOC。 
    8989     * @return array|null 
    9090     */ 
    91     function select($col, $table, $where = "", $arrval = array(), $fetchmode = DB_FETCHMODE_ASSOC) { 
     91    function select($col, $table, $where = "", $arrval = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 
    9292        $sqlse = $this->getSql($col, $table, $where); 
    9393        $ret = $this->conn->getAll($sqlse, $arrval, $fetchmode); 
     94 
    9495        return $ret; 
    9596    } 
    9697 
Note: See TracBrowser for help on using the repository browser.