- Timestamp:
- 2007/08/08 16:04:43 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/helper/SC_Helper_DB.php
r15224 r15237 25 25 */ 26 26 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); 47 29 } 48 30 … … 55 37 */ 56 38 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); 64 41 65 42 $objQuery = new SC_Query($dsn, true, true); … … 67 44 if(!$objQuery->isError()) { 68 45 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; 90 50 } 91 51 } … … 110 70 */ 111 71 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); 119 74 120 75 // テーブルが無ければエラー 121 if(! sfTabaleExists($table_name, $dsn)) return false;76 if(!$this->sfTabaleExists($table_name, $dsn)) return false; 122 77 123 78 $objQuery = new SC_Query($dsn, true, true); … … 127 82 128 83 // カラムリストを取得 129 $arrRet = sfGetColumnList($table_name, $objQuery, $db_type);84 $arrRet = $dbFactory->sfGetColumnList($table_name); 130 85 if(count($arrRet) > 0) { 131 86 if(in_array($col_name, $arrRet)){ … … 140 95 return true; 141 96 } 142 143 97 return false; 144 98 } … … 162 116 */ 163 117 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); 171 120 172 121 // テーブルが無ければエラー 173 if (!sfTabaleExists($table_name, $dsn)) return false;122 if (!$this->sfTabaleExists($table_name, $dsn)) return false; 174 123 175 124 $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; 195 130 } 196 131 197 132 // インデックスを作成する 198 133 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()); 209 135 return true; 210 136 } … … 224 150 */ 225 151 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 233 155 $objQuery = new SC_Query($dsn, true, true); 234 156 $count = $objQuery->count($table_name, $where, $arrval); … … 282 204 function sfTotalCart($objPage, $objCartSess, $arrInfo) { 283 205 // 規格名一覧 284 $arrClassName = SC_Utils ::sfGetIDValueList("dtb_class", "class_id", "name");206 $arrClassName = SC_Utils_Ex::sfGetIDValueList("dtb_class", "class_id", "name"); 285 207 // 規格分類名一覧 286 $arrClassCatName = SC_Utils ::sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");208 $arrClassCatName = SC_Utils_Ex::sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); 287 209 288 210 $objPage->tpl_total_pretax = 0; // 費用合計(税込み)
Note: See TracChangeset
for help on using the changeset viewer.