| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 6 | * |
|---|
| 7 | * http://www.lockon.co.jp/ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or |
|---|
| 10 | * modify it under the terms of the GNU General Public License |
|---|
| 11 | * as published by the Free Software Foundation; either version 2 |
|---|
| 12 | * of the License, or (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * DBに依存した処理を抽象化するファクトリークラス. |
|---|
| 26 | * |
|---|
| 27 | * @package DB |
|---|
| 28 | * @author LOCKON CO.,LTD. |
|---|
| 29 | * @version $Id:SC_DB_DBFactory.php 15532 2007-08-31 14:39:46Z nanasess $ |
|---|
| 30 | */ |
|---|
| 31 | class SC_DB_DBFactory |
|---|
| 32 | { |
|---|
| 33 | /** |
|---|
| 34 | * DB_TYPE に応じた DBFactory インスタンスを生成する. |
|---|
| 35 | * |
|---|
| 36 | * @param string $db_type 任意のインスタンスを返したい場合は DB_TYPE 文字列を指定 |
|---|
| 37 | * @return SC_DB_DBFactory DBFactory インスタンス |
|---|
| 38 | */ |
|---|
| 39 | public function getInstance($db_type = DB_TYPE) |
|---|
| 40 | { |
|---|
| 41 | switch ($db_type) { |
|---|
| 42 | case 'mysql': |
|---|
| 43 | return new SC_DB_DBFactory_MYSQL(); |
|---|
| 44 | |
|---|
| 45 | case 'pgsql': |
|---|
| 46 | return new SC_DB_DBFactory_PGSQL(); |
|---|
| 47 | |
|---|
| 48 | default: |
|---|
| 49 | return new SC_DB_DBFactory(); |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * データソース名を取得する. |
|---|
| 55 | * |
|---|
| 56 | * 引数 $dsn が空でデータソースが定義済みの場合はDB接続パラメータの連想配列を返す |
|---|
| 57 | * DEFAULT_DSN が未定義の場合は void となる. |
|---|
| 58 | * $dsn が空ではない場合は, $dsn の値を返す. |
|---|
| 59 | * |
|---|
| 60 | * @param string $dsn データソース名 |
|---|
| 61 | * @return string データソース名またはDB接続パラメータの連想配列 |
|---|
| 62 | */ |
|---|
| 63 | public function getDSN($dsn = '') |
|---|
| 64 | { |
|---|
| 65 | if (empty($dsn)) { |
|---|
| 66 | if (defined('DEFAULT_DSN')) { |
|---|
| 67 | $dsn = array('phptype' => DB_TYPE, |
|---|
| 68 | 'username' => DB_USER, |
|---|
| 69 | 'password' => DB_PASSWORD, |
|---|
| 70 | 'protocol' => 'tcp', |
|---|
| 71 | 'hostspec' => DB_SERVER, |
|---|
| 72 | 'port' => DB_PORT, |
|---|
| 73 | 'database' => DB_NAME |
|---|
| 74 | ); |
|---|
| 75 | } else { |
|---|
| 76 | return ''; |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | return $dsn; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * DBのバージョンを取得する. |
|---|
| 85 | * |
|---|
| 86 | * @param string $dsn データソース名 |
|---|
| 87 | * @return string データベースのバージョン |
|---|
| 88 | */ |
|---|
| 89 | public function sfGetDBVersion($dsn = '') |
|---|
| 90 | { |
|---|
| 91 | return null; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * MySQL 用の SQL 文に変更する. |
|---|
| 96 | * |
|---|
| 97 | * @param string $sql SQL 文 |
|---|
| 98 | * @return string MySQL 用に置換した SQL 文 |
|---|
| 99 | */ |
|---|
| 100 | public function sfChangeMySQL($sql) |
|---|
| 101 | { |
|---|
| 102 | return null; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * 昨日の売上高・売上件数を算出する SQL を返す. |
|---|
| 107 | * |
|---|
| 108 | * @param string $method SUM または COUNT |
|---|
| 109 | * @return string 昨日の売上高・売上件数を算出する SQL |
|---|
| 110 | */ |
|---|
| 111 | public function getOrderYesterdaySql($method) |
|---|
| 112 | { |
|---|
| 113 | return null; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | /** |
|---|
| 117 | * 当月の売上高・売上件数を算出する SQL を返す. |
|---|
| 118 | * |
|---|
| 119 | * @param string $method SUM または COUNT |
|---|
| 120 | * @return string 当月の売上高・売上件数を算出する SQL |
|---|
| 121 | */ |
|---|
| 122 | public function getOrderMonthSql($method) |
|---|
| 123 | { |
|---|
| 124 | return null; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * 昨日のレビュー書き込み件数を算出する SQL を返す. |
|---|
| 129 | * |
|---|
| 130 | * @return string 昨日のレビュー書き込み件数を算出する SQL |
|---|
| 131 | */ |
|---|
| 132 | public function getReviewYesterdaySql() |
|---|
| 133 | { |
|---|
| 134 | return null; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | /** |
|---|
| 138 | * メール送信履歴の start_date の検索条件の SQL を返す. |
|---|
| 139 | * |
|---|
| 140 | * @return string 検索条件の SQL |
|---|
| 141 | */ |
|---|
| 142 | public function getSendHistoryWhereStartdateSql() |
|---|
| 143 | { |
|---|
| 144 | return null; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | * ダウンロード販売の検索条件の SQL を返す. |
|---|
| 149 | * |
|---|
| 150 | * @return string 検索条件の SQL |
|---|
| 151 | */ |
|---|
| 152 | public function getDownloadableDaysWhereSql() |
|---|
| 153 | { |
|---|
| 154 | return null; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | /** |
|---|
| 158 | * 文字列連結を行う. |
|---|
| 159 | * |
|---|
| 160 | * @param string[] $columns 連結を行うカラム名 |
|---|
| 161 | * @return string 連結後の SQL 文 |
|---|
| 162 | */ |
|---|
| 163 | public function concatColumn($columns) |
|---|
| 164 | { |
|---|
| 165 | return null; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | /** |
|---|
| 169 | * テーブルを検索する. |
|---|
| 170 | * |
|---|
| 171 | * 引数に部分一致するテーブル名を配列で返す. |
|---|
| 172 | * |
|---|
| 173 | * @deprecated SC_Query::listTables() を使用してください |
|---|
| 174 | * @param string $expression 検索文字列 |
|---|
| 175 | * @return array テーブル名の配列 |
|---|
| 176 | */ |
|---|
| 177 | public function findTableNames($expression = '') |
|---|
| 178 | { |
|---|
| 179 | return array(); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | /** |
|---|
| 183 | * インデックス作成の追加定義を取得する |
|---|
| 184 | * |
|---|
| 185 | * 引数に部分一致するテーブル名を配列で返す. |
|---|
| 186 | * |
|---|
| 187 | * @param string $table 対象テーブル名 |
|---|
| 188 | * @param string $name 対象カラム名 |
|---|
| 189 | * @return array インデックス設定情報配列 |
|---|
| 190 | */ |
|---|
| 191 | public function sfGetCreateIndexDefinition($table, $name, $definition) |
|---|
| 192 | { |
|---|
| 193 | return $definition; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | /** |
|---|
| 197 | * 各 DB に応じた SC_Query での初期化を行う |
|---|
| 198 | * |
|---|
| 199 | * @param SC_Query $objQuery SC_Query インスタンス |
|---|
| 200 | * @return void |
|---|
| 201 | */ |
|---|
| 202 | public function initObjQuery(SC_Query &$objQuery) |
|---|
| 203 | { |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | /** |
|---|
| 207 | * テーブル一覧を取得する |
|---|
| 208 | * |
|---|
| 209 | * @return array テーブル名の配列 |
|---|
| 210 | */ |
|---|
| 211 | public function listTables(SC_Query &$objQuery) |
|---|
| 212 | { |
|---|
| 213 | $objManager =& $objQuery->conn->loadModule('Manager'); |
|---|
| 214 | |
|---|
| 215 | return $objManager->listTables(); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | /** |
|---|
| 219 | * SQL 文に OFFSET, LIMIT を付加する。 |
|---|
| 220 | * |
|---|
| 221 | * @param string 元の SQL 文 |
|---|
| 222 | * @param integer LIMIT |
|---|
| 223 | * @param integer OFFSET |
|---|
| 224 | * @return string 付加後の SQL 文 |
|---|
| 225 | */ |
|---|
| 226 | function addLimitOffset($sql, $limit = 0, $offset = 0) |
|---|
| 227 | { |
|---|
| 228 | if ($limit != 0) { |
|---|
| 229 | $sql .= " LIMIT $limit"; |
|---|
| 230 | } |
|---|
| 231 | if (strlen($offset) === 0) { |
|---|
| 232 | $offset = 0; |
|---|
| 233 | } |
|---|
| 234 | $sql .= " OFFSET $offset"; |
|---|
| 235 | |
|---|
| 236 | return $sql; |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | /** |
|---|
| 240 | * 商品詳細の SQL を取得する. |
|---|
| 241 | * |
|---|
| 242 | * @param string $where_products_class 商品規格情報の WHERE 句 |
|---|
| 243 | * @return string 商品詳細の SQL |
|---|
| 244 | */ |
|---|
| 245 | public function alldtlSQL($where_products_class = '') |
|---|
| 246 | { |
|---|
| 247 | if (!SC_Utils_Ex::isBlank($where_products_class)) { |
|---|
| 248 | $where_products_class = 'AND (' . $where_products_class . ')'; |
|---|
| 249 | } |
|---|
| 250 | /* |
|---|
| 251 | * point_rate, deliv_fee は商品規格(dtb_products_class)ごとに保持しているが, |
|---|
| 252 | * 商品(dtb_products)ごとの設定なので MAX のみを取得する. |
|---|
| 253 | */ |
|---|
| 254 | $sql = <<< __EOS__ |
|---|
| 255 | ( |
|---|
| 256 | SELECT |
|---|
| 257 | dtb_products.* |
|---|
| 258 | ,T4.product_code_min |
|---|
| 259 | ,T4.product_code_max |
|---|
| 260 | ,T4.price01_min |
|---|
| 261 | ,T4.price01_max |
|---|
| 262 | ,T4.price02_min |
|---|
| 263 | ,T4.price02_max |
|---|
| 264 | ,T4.stock_min |
|---|
| 265 | ,T4.stock_max |
|---|
| 266 | ,T4.stock_unlimited_min |
|---|
| 267 | ,T4.stock_unlimited_max |
|---|
| 268 | ,T4.point_rate |
|---|
| 269 | ,T4.deliv_fee |
|---|
| 270 | ,dtb_maker.name AS maker_name |
|---|
| 271 | FROM dtb_products |
|---|
| 272 | INNER JOIN ( |
|---|
| 273 | SELECT product_id |
|---|
| 274 | ,MIN(product_code) AS product_code_min |
|---|
| 275 | ,MAX(product_code) AS product_code_max |
|---|
| 276 | ,MIN(price01) AS price01_min |
|---|
| 277 | ,MAX(price01) AS price01_max |
|---|
| 278 | ,MIN(price02) AS price02_min |
|---|
| 279 | ,MAX(price02) AS price02_max |
|---|
| 280 | ,MIN(stock) AS stock_min |
|---|
| 281 | ,MAX(stock) AS stock_max |
|---|
| 282 | ,MIN(stock_unlimited) AS stock_unlimited_min |
|---|
| 283 | ,MAX(stock_unlimited) AS stock_unlimited_max |
|---|
| 284 | ,MAX(point_rate) AS point_rate |
|---|
| 285 | ,MAX(deliv_fee) AS deliv_fee |
|---|
| 286 | FROM dtb_products_class |
|---|
| 287 | WHERE del_flg = 0 $where_products_class |
|---|
| 288 | GROUP BY product_id |
|---|
| 289 | ) AS T4 |
|---|
| 290 | ON dtb_products.product_id = T4.product_id |
|---|
| 291 | LEFT JOIN dtb_maker |
|---|
| 292 | ON dtb_products.maker_id = dtb_maker.maker_id |
|---|
| 293 | ) AS alldtl |
|---|
| 294 | __EOS__; |
|---|
| 295 | |
|---|
| 296 | return $sql; |
|---|
| 297 | } |
|---|
| 298 | } |
|---|