Ignore:
Timestamp:
2007/08/08 16:04:43 (17 years ago)
Author:
nanasess
Message:

リファクタリング

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/data/class/helper/SC_Helper_DB.php

    r15224 r15237  
    2525     */ 
    2626    function sfGetDBVersion($dsn = "") { 
    27         if($dsn == "") { 
    28             if(defined('DEFAULT_DSN')) { 
    29                 $dsn = DEFAULT_DSN; 
    30             } else { 
    31                 return; 
    32             } 
    33         } 
    34  
    35         $objQuery = new SC_Query($dsn, true, true); 
    36         list($db_type) = split(":", $dsn); 
    37         if($db_type == 'mysql') { 
    38             $val = $objQuery->getOne("select version()"); 
    39             $version = "MySQL " . $val; 
    40         } 
    41         if($db_type == 'pgsql') { 
    42             $val = $objQuery->getOne("select version()"); 
    43             $arrLine = split(" " , $val); 
    44             $version = $arrLine[0] . " " . $arrLine[1]; 
    45         } 
    46         return $version; 
     27        $dbFactory = SC_DB_DBFactory::getInstance(); 
     28        return $dbFactory->sfGetDBVersion($dsn); 
    4729    } 
    4830 
     
    5537     */ 
    5638    function sfTabaleExists($table_name, $dsn = "") { 
    57         if($dsn == "") { 
    58             if(defined('DEFAULT_DSN')) { 
    59                 $dsn = DEFAULT_DSN; 
    60             } else { 
    61                 return; 
    62             } 
    63         } 
     39        $dbFactory = SC_DB_DBFactory::getInstance(); 
     40        $dsn = $dbFactory->getDSN($dsn); 
    6441 
    6542        $objQuery = new SC_Query($dsn, true, true); 
     
    6744        if(!$objQuery->isError()) { 
    6845            list($db_type) = split(":", $dsn); 
    69             // postgresqlとmysqlとで処理を分ける 
    70             if ($db_type == "pgsql") { 
    71                 $sql = "SELECT 
    72                             relname 
    73                         FROM 
    74                             pg_class 
    75                         WHERE 
    76                             (relkind = 'r' OR relkind = 'v') AND 
    77                             relname = ? 
    78                         GROUP BY 
    79                             relname"; 
    80                 $arrRet = $objQuery->getAll($sql, array($table_name)); 
    81                 if(count($arrRet) > 0) { 
    82                     return true; 
    83                 } 
    84             }else if ($db_type == "mysql") { 
    85                 $sql = "SHOW TABLE STATUS LIKE ?"; 
    86                 $arrRet = $objQuery->getAll($sql, array($table_name)); 
    87                 if(count($arrRet) > 0) { 
    88                     return true; 
    89                 } 
     46            $sql = $dbFactory->getTableExistsSql(); 
     47            $arrRet = $objQuery->getAll($sql, array($table_name)); 
     48            if(count($arrRet) > 0) { 
     49                return true; 
    9050            } 
    9151        } 
     
    11070     */ 
    11171    function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) { 
    112         if($dsn == "") { 
    113             if(defined('DEFAULT_DSN')) { 
    114                 $dsn = DEFAULT_DSN; 
    115             } else { 
    116                 return; 
    117             } 
    118         } 
     72        $dbFactory = SC_DB_DBFactory::getInstance(); 
     73        $dsn = $dbFactory->getDSN($dsn); 
    11974 
    12075        // テーブルが無ければエラー 
    121         if(!sfTabaleExists($table_name, $dsn)) return false; 
     76        if(!$this->sfTabaleExists($table_name, $dsn)) return false; 
    12277 
    12378        $objQuery = new SC_Query($dsn, true, true); 
     
    12782 
    12883            // カラムリストを取得 
    129             $arrRet = sfGetColumnList($table_name, $objQuery, $db_type); 
     84            $arrRet = $dbFactory->sfGetColumnList($table_name); 
    13085            if(count($arrRet) > 0) { 
    13186                if(in_array($col_name, $arrRet)){ 
     
    14095            return true; 
    14196        } 
    142  
    14397        return false; 
    14498    } 
     
    162116     */ 
    163117    function sfIndexExists($table_name, $col_name, $index_name, $length = "", $dsn = "", $add = false) { 
    164         if($dsn == "") { 
    165             if(defined('DEFAULT_DSN')) { 
    166                 $dsn = DEFAULT_DSN; 
    167             } else { 
    168                 return; 
    169             } 
    170         } 
     118        $dbFactory = SC_DB_DBFactory::getInstance(); 
     119        $dsn = $dbFactory->getDSN($dsn); 
    171120 
    172121        // テーブルが無ければエラー 
    173         if(!sfTabaleExists($table_name, $dsn)) return false; 
     122        if (!$this->sfTabaleExists($table_name, $dsn)) return false; 
    174123 
    175124        $objQuery = new SC_Query($dsn, true, true); 
    176         // 正常に接続されている場合 
    177         if(!$objQuery->isError()) { 
    178             list($db_type) = split(":", $dsn); 
    179             switch($db_type) { 
    180             case 'pgsql': 
    181                 // インデックスの存在確認 
    182                 $arrRet = $objQuery->getAll("SELECT relname FROM pg_class WHERE relname = ?", array($index_name)); 
    183                 break; 
    184             case 'mysql': 
    185                 // インデックスの存在確認 
    186                 $arrRet = $objQuery->getAll("SHOW INDEX FROM ? WHERE Key_name = ?", array($table_name, $index_name)); 
    187                 break; 
    188             default: 
    189                 return false; 
    190             } 
    191             // すでにインデックスが存在する場合 
    192             if(count($arrRet) > 0) { 
    193                 return true; 
    194             } 
     125        $arrRet = $dbFactory->getTableIndex($index_name, $table_name); 
     126 
     127        // すでにインデックスが存在する場合 
     128        if(count($arrRet) > 0) { 
     129            return true; 
    195130        } 
    196131 
    197132        // インデックスを作成する 
    198133        if($add){ 
    199             switch($db_type) { 
    200             case 'pgsql': 
    201                 $objQuery->query("CREATE INDEX ? ON ? (?)", array($index_name, $table_name, $col_name)); 
    202                 break; 
    203             case 'mysql': 
    204                 $objQuery->query("CREATE INDEX ? ON ? (?(?))", array($index_name, $table_name, $col_name, $length)); 
    205                 break; 
    206             default: 
    207                 return false; 
    208             } 
     134            $dbFactory->createTableIndex($index_name, $table_name, $col_name, $length()); 
    209135            return true; 
    210136        } 
     
    224150     */ 
    225151    function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) { 
    226         if($dsn == "") { 
    227             if(defined('DEFAULT_DSN')) { 
    228                 $dsn = DEFAULT_DSN; 
    229             } else { 
    230                 return; 
    231             } 
    232         } 
     152        $dbFactory = SC_DB_DBFactory::getInstance(); 
     153        $dsn = $dbFactory->getDSN($dsn); 
     154 
    233155        $objQuery = new SC_Query($dsn, true, true); 
    234156        $count = $objQuery->count($table_name, $where, $arrval); 
     
    282204    function sfTotalCart($objPage, $objCartSess, $arrInfo) { 
    283205        // 規格名一覧 
    284         $arrClassName = SC_Utils::sfGetIDValueList("dtb_class", "class_id", "name"); 
     206        $arrClassName = SC_Utils_Ex::sfGetIDValueList("dtb_class", "class_id", "name"); 
    285207        // 規格分類名一覧 
    286         $arrClassCatName = SC_Utils::sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); 
     208        $arrClassCatName = SC_Utils_Ex::sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); 
    287209 
    288210        $objPage->tpl_total_pretax = 0;     // 費用合計(税込み) 
Note: See TracChangeset for help on using the changeset viewer.