Ignore:
Timestamp:
2012/01/06 19:54:03 (12 years ago)
Author:
kotani
Message:

Merge from version-2_11-dev

File:
1 edited

Legend:

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

    r21284 r21390  
    106106 
    107107    /** 
    108      *  エラー判定を行う. 
     108     * エラー判定を行う. 
    109109     * 
    110110     * @deprecated PEAR::isError() を使用して下さい 
     
    126126     * @return integer 件数 
    127127     */ 
    128     function count($table, $where = "", $arrWhereVal = array()) { 
    129         if(strlen($where) <= 0) { 
    130             $sqlse = "SELECT COUNT(*) FROM $table"; 
    131         } else { 
    132             $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; 
    133         } 
    134         $sqlse = $this->dbFactory->sfChangeMySQL($sqlse); 
    135         return $this->getOne($sqlse, $arrWhereVal); 
     128    function count($table, $where = '', $arrWhereVal = array()) { 
     129        return $this->get('COUNT(*)', $table, $where, $arrWhereVal); 
     130    } 
     131 
     132    /** 
     133     * EXISTS文を実行する. 
     134     * 
     135     * @param string $table テーブル名 
     136     * @param string $where where句 
     137     * @param array $arrWhereVal プレースホルダ 
     138     * @return boolean 有無 
     139     */ 
     140    function exists($table, $where = '', $arrWhereVal = array()) { 
     141        $sql_inner = $this->getSql('*', $table, $where, $arrWhereVal); 
     142        $sql = "SELECT CASE WHEN EXISTS($sql_inner) THEN 1 ELSE 0 END"; 
     143        $res = $this->getOne($sql, $arrWhereVal); 
     144        return (bool)$res; 
    136145    } 
    137146 
     
    270279        } 
    271280 
    272         return $affected->fetchAll($fetchmode); 
     281        // MySQL での不具合対応のため、一旦変数に退避 
     282        $arrRet = $affected->fetchAll($fetchmode); 
     283 
     284        // PREPAREの解放 
     285        $sth->free(); 
     286 
     287        return $arrRet; 
    273288    } 
    274289 
     
    454469     * @param string $table テーブル名 
    455470     * @param array $sqlval array('カラム名' => '値',...)の連想配列 
     471     * @param array $arrSql array('カラム名' => 'SQL文',...)の連想配列 
     472     * @param array $arrSqlVal SQL文の中で使用するプレースホルダ配列 
    456473     * @return 
    457474     */ 
    458     function insert($table, $sqlval) { 
     475    function insert($table, $sqlval, $arrSql = array(), $arrSqlVal = array()) { 
    459476        $strcol = ''; 
    460477        $strval = ''; 
    461478        $find = false; 
     479        $arrVal = array(); 
    462480 
    463481        if(count($sqlval) <= 0 ) return false; 
     
    470488            } else { 
    471489                $strval .= '?,'; 
    472                 $arrval[] = $val; 
     490                $arrVal[] = $val; 
    473491            } 
    474492            $find = true; 
    475493        } 
     494 
     495        foreach($arrSql as $key => $val) { 
     496            $strcol .= $key . ','; 
     497            $strval .= $val . ','; 
     498        } 
     499 
     500        $arrVal = array_merge($arrVal, $arrSqlVal); 
     501 
    476502        if(!$find) { 
    477503            return false; 
     
    482508        $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; 
    483509        // INSERT文の実行 
    484         $ret = $this->query($sqlin, $arrval, false, null, MDB2_PREPARE_MANIP); 
     510        $ret = $this->query($sqlin, $arrVal, false, null, MDB2_PREPARE_MANIP); 
    485511 
    486512        return $ret; 
     
    609635        } 
    610636 
    611         return $affected->fetchOne(); 
     637        // MySQL での不具合対応のため、一旦変数に退避 
     638        $arrRet = $affected->fetchOne(); 
     639 
     640        // PREPAREの解放 
     641        $sth->free(); 
     642 
     643        return $arrRet; 
    612644    } 
    613645 
     
    637669        } 
    638670 
    639         return $affected->fetchRow($fetchmode); 
     671        // MySQL での不具合対応のため、一旦変数に退避 
     672        $arrRet = $affected->fetchRow($fetchmode); 
     673 
     674        // PREPAREの解放 
     675        $sth->free(); 
     676 
     677        return $arrRet; 
    640678    } 
    641679 
     
    663701        } 
    664702 
    665         return $affected->fetchCol(); 
     703        // MySQL での不具合対応のため、一旦変数に退避 
     704        $arrRet = $affected->fetchCol(); 
     705 
     706        // PREPAREの解放 
     707        $sth->free(); 
     708 
     709        return $arrRet; 
    666710    } 
    667711 
     
    744788        } 
    745789 
    746         //PREPAREの解放 
     790        // PREPAREの解放 
    747791        $sth->free(); 
    748792 
     
    9731017        } 
    9741018        $arrRet = $result->getColumnNames(); 
    975         //PREPAREの解放 
     1019        // PREPAREの解放 
    9761020        $sth->free(); 
    9771021 
Note: See TracChangeset for help on using the changeset viewer.