| 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
| 5 | * Copyright(c) 2000-2013 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 mixed 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 mixed $dsn データソース名 |
---|
| 61 | * @return mixed データソース名または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 | { return null; } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * MySQL 用の SQL 文に変更する. |
---|
| 94 | * |
---|
| 95 | * @param string $sql SQL 文 |
---|
| 96 | * @return string MySQL 用に置換した SQL 文 |
---|
| 97 | */ |
---|
| 98 | public function sfChangeMySQL($sql) |
---|
| 99 | { return null; } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * 昨日の売上高・売上件数を算出する SQL を返す. |
---|
| 103 | * |
---|
| 104 | * @param string $method SUM または COUNT |
---|
| 105 | * @return string 昨日の売上高・売上件数を算出する SQL |
---|
| 106 | */ |
---|
| 107 | public function getOrderYesterdaySql($method) |
---|
| 108 | { return null; } |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | * 当月の売上高・売上件数を算出する SQL を返す. |
---|
| 112 | * |
---|
| 113 | * @param string $method SUM または COUNT |
---|
| 114 | * @return string 当月の売上高・売上件数を算出する SQL |
---|
| 115 | */ |
---|
| 116 | public function getOrderMonthSql($method) |
---|
| 117 | { return null; } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * 昨日のレビュー書き込み件数を算出する SQL を返す. |
---|
| 121 | * |
---|
| 122 | * @return string 昨日のレビュー書き込み件数を算出する SQL |
---|
| 123 | */ |
---|
| 124 | public function getReviewYesterdaySql() |
---|
| 125 | { return null; } |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | * メール送信履歴の start_date の検索条件の SQL を返す. |
---|
| 129 | * |
---|
| 130 | * @return string 検索条件の SQL |
---|
| 131 | */ |
---|
| 132 | public function getSendHistoryWhereStartdateSql() |
---|
| 133 | { return null; } |
---|
| 134 | |
---|
| 135 | /** |
---|
| 136 | * ダウンロード販売の検索条件の SQL を返す. |
---|
| 137 | * |
---|
| 138 | * @return string 検索条件の SQL |
---|
| 139 | */ |
---|
| 140 | public function getDownloadableDaysWhereSql() |
---|
| 141 | { return null; } |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | * 文字列連結を行う. |
---|
| 145 | * |
---|
| 146 | * @param array $columns 連結を行うカラム名 |
---|
| 147 | * @return string 連結後の SQL 文 |
---|
| 148 | */ |
---|
| 149 | public function concatColumn($columns) |
---|
| 150 | { return null; } |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | * テーブルを検索する. |
---|
| 154 | * |
---|
| 155 | * 引数に部分一致するテーブル名を配列で返す. |
---|
| 156 | * |
---|
| 157 | * @deprecated SC_Query::listTables() を使用してください |
---|
| 158 | * @param string $expression 検索文字列 |
---|
| 159 | * @return array テーブル名の配列 |
---|
| 160 | */ |
---|
| 161 | public function findTableNames($expression = '') |
---|
| 162 | { return array(); } |
---|
| 163 | |
---|
| 164 | /** |
---|
| 165 | * インデックス作成の追加定義を取得する |
---|
| 166 | * |
---|
| 167 | * 引数に部分一致するテーブル名を配列で返す. |
---|
| 168 | * |
---|
| 169 | * @param string $table 対象テーブル名 |
---|
| 170 | * @param string $name 対象カラム名 |
---|
| 171 | * @return array インデックス設定情報配列 |
---|
| 172 | */ |
---|
| 173 | public function sfGetCreateIndexDefinition($table, $name, $definition) |
---|
| 174 | { return $definition; } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | * 各 DB に応じた SC_Query での初期化を行う |
---|
| 178 | * |
---|
| 179 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
| 180 | * @return void |
---|
| 181 | */ |
---|
| 182 | public function initObjQuery(SC_Query &$objQuery) |
---|
| 183 | { |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /** |
---|
| 187 | * テーブル一覧を取得する |
---|
| 188 | * |
---|
| 189 | * @return array テーブル名の配列 |
---|
| 190 | */ |
---|
| 191 | public function listTables(SC_Query &$objQuery) |
---|
| 192 | { |
---|
| 193 | $objManager =& $objQuery->conn->loadModule('Manager'); |
---|
| 194 | |
---|
| 195 | return $objManager->listTables(); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /** |
---|
| 199 | * SQL 文に OFFSET, LIMIT を付加する。 |
---|
| 200 | * |
---|
| 201 | * @param string 元の SQL 文 |
---|
| 202 | * @param integer LIMIT |
---|
| 203 | * @param integer OFFSET |
---|
| 204 | * @return string 付加後の SQL 文 |
---|
| 205 | */ |
---|
| 206 | function addLimitOffset($sql, $limit = 0, $offset = 0) |
---|
| 207 | { |
---|
| 208 | if ($limit != 0) { |
---|
| 209 | $sql .= " LIMIT $limit"; |
---|
| 210 | } |
---|
| 211 | if (strlen($offset) === 0) { |
---|
| 212 | $offset = 0; |
---|
| 213 | } |
---|
| 214 | $sql .= " OFFSET $offset"; |
---|
| 215 | |
---|
| 216 | return $sql; |
---|
| 217 | } |
---|
| 218 | } |
---|