Ignore:
Timestamp:
2012/04/04 05:39:55 (12 years ago)
Author:
Seasoft
Message:

#1733 (SC_Query 問い合わせの FROM 句を省略可能に)
#1613 (typo修正・ソース整形・ソースコメントの改善)

File:
1 edited

Legend:

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

    r21677 r21710  
    150150     * SELECT文を実行する. 
    151151     * 
    152      * @param string $col カラム名. 複数カラムの場合はカンマ区切りで書く 
    153      * @param string $table テーブル名 
     152     * @param string $cols カラム名. 複数カラムの場合はカンマ区切りで書く 
     153     * @param string $from テーブル名 
    154154     * @param string $where WHERE句 
    155155     * @param array $arrWhereVal プレースホルダ 
     
    157157     * @return array|null 
    158158     */ 
    159     function select($col, $table, $where = '', $arrWhereVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 
    160         $sqlse = $this->getSql($col, $table, $where, $arrWhereVal); 
     159    function select($cols, $from = '', $where = '', $arrWhereVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 
     160        $sqlse = $this->getSql($cols, $from, $where, $arrWhereVal); 
    161161        return $this->getAll($sqlse, $arrWhereVal, $fetchmode); 
    162162    } 
     
    294294     * 
    295295     * クラス変数から WHERE 句を組み立てる場合、$arrWhereVal を経由してプレースホルダもクラス変数のもので上書きする。 
    296      * @param string $col SELECT 文に含めるカラム名 
    297      * @param string $table SELECT 文に含めるテーブル名 
     296     * @param string $cols SELECT 文に含めるカラム名 
     297     * @param string $from SELECT 文に含めるテーブル名 
    298298     * @param string $where SELECT 文に含める WHERE 句 
    299299     * @param mixed $arrWhereVal プレースホルダ(参照) 
    300300     * @return string 構築済みの SELECT 文 
    301301     */ 
    302     function getSql($col, $table, $where = '', &$arrWhereVal = null) { 
    303         $sqlse = "SELECT $col FROM $table"; 
     302    function getSql($cols, $from = '', $where = '', &$arrWhereVal = null) { 
     303        $dbFactory = SC_DB_DBFactory_Ex::getInstance(); 
     304 
     305        $sqlse = "SELECT $cols"; 
     306 
     307        if (strlen($from) === 0) { 
     308            $sqlse .= ' ' . $dbFactory->getDummyFromClauseSql(); 
     309        } else { 
     310            $sqlse .= " FROM $from"; 
     311        } 
    304312 
    305313        // 引数の$whereを優先する。 
     
    617625     * @return mixed SQL の実行結果 
    618626     */ 
    619     function get($col, $table, $where = '', $arrWhereVal = array()) { 
     627    function get($col, $table = '', $where = '', $arrWhereVal = array()) { 
    620628        $sqlse = $this->getSql($col, $table, $where, $arrWhereVal); 
    621629        // SQL文の実行 
     
    664672     * @return array array('カラム名' => '値', ...)の連想配列 
    665673     */ 
    666     function getRow($col, $table, $where = '', $arrWhereVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 
     674    function getRow($col, $table = '', $where = '', $arrWhereVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 
    667675 
    668676        $sql = $this->getSql($col, $table, $where, $arrWhereVal); 
     
    697705     * @return array SQL の実行結果の配列 
    698706     */ 
    699     function getCol($col, $table, $where = '', $arrWhereVal = array()) { 
     707    function getCol($col, $table = '', $where = '', $arrWhereVal = array()) { 
    700708        $sql = $this->getSql($col, $table, $where, $arrWhereVal); 
    701709        $sql = $this->dbFactory->sfChangeMySQL($sql); 
Note: See TracChangeset for help on using the changeset viewer.