| 1 | #!/usr/local/bin/php -q |
|---|
| 2 | <?php |
|---|
| 3 | /* |
|---|
| 4 | * EC-CUBE データ生成スクリプト |
|---|
| 5 | * |
|---|
| 6 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 7 | * |
|---|
| 8 | * http://www.lockon.co.jp/ |
|---|
| 9 | * |
|---|
| 10 | * This program is free software; you can redistribute it and/or |
|---|
| 11 | * modify it under the terms of the GNU General Public License |
|---|
| 12 | * as published by the Free Software Foundation; either version 2 |
|---|
| 13 | * of the License, or (at your option) any later version. |
|---|
| 14 | * |
|---|
| 15 | * This program is distributed in the hope that it will be useful, |
|---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | * GNU General Public License for more details. |
|---|
| 19 | * |
|---|
| 20 | * You should have received a copy of the GNU General Public License |
|---|
| 21 | * along with this program; if not, write to the Free Software |
|---|
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 23 | * |
|---|
| 24 | * @auther Kentaro Ohkouchi |
|---|
| 25 | * @version $Id$ |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | // {{{ requires |
|---|
| 29 | set_include_path(".:" . realpath(dirname(__FILE__) . "/data/module")); |
|---|
| 30 | require_once("MDB2.php"); |
|---|
| 31 | |
|---|
| 32 | // }}} |
|---|
| 33 | // {{{ constants |
|---|
| 34 | |
|---|
| 35 | /** データベース種別 */ |
|---|
| 36 | define("DB_TYPE", "pgsql"); |
|---|
| 37 | /** DBホスト */ |
|---|
| 38 | define("DB_SERVER", "localhost"); |
|---|
| 39 | /** DBポート */ |
|---|
| 40 | define("DB_PORT", "5432"); |
|---|
| 41 | /** DB名 */ |
|---|
| 42 | define("DB_NAME", "eccube_db"); |
|---|
| 43 | /** DBユーザー */ |
|---|
| 44 | define("DB_USER", "eccube_db_user"); |
|---|
| 45 | /** DBパスワード */ |
|---|
| 46 | define("DB_PASSWORD", "password"); |
|---|
| 47 | |
|---|
| 48 | /** データソース名 */ |
|---|
| 49 | define ("DEFAULT_DSN", |
|---|
| 50 | DB_TYPE . "://" . DB_USER . ":" . DB_PASSWORD . "@" |
|---|
| 51 | . DB_SERVER . ":" .DB_PORT . "/" . DB_NAME); |
|---|
| 52 | |
|---|
| 53 | /** 大カテゴリの生成数 */ |
|---|
| 54 | define("TOP_CATEGORIES_VOLUME", 5); |
|---|
| 55 | |
|---|
| 56 | /** 中カテゴリの生成数 */ |
|---|
| 57 | define("MIDDLE_CATEGORIES_VOLUME", 2); |
|---|
| 58 | |
|---|
| 59 | /** 小カテゴリの生成数 */ |
|---|
| 60 | define("SMALL_CATEGORIES_VOLUME", 3); |
|---|
| 61 | |
|---|
| 62 | /** 規格1の生成数 */ |
|---|
| 63 | define("CLASSCATEGORY1_VOLUME", 10); |
|---|
| 64 | |
|---|
| 65 | /** 規格2の生成数 */ |
|---|
| 66 | define("CLASSCATEGORY2_VOLUME", 10); |
|---|
| 67 | |
|---|
| 68 | /** 商品の生成数 */ |
|---|
| 69 | define("PRODUCTS_VOLUME", 1000); |
|---|
| 70 | |
|---|
| 71 | // }}} |
|---|
| 72 | // {{{ Logic |
|---|
| 73 | |
|---|
| 74 | $objData = new CreateEcCubeData(); |
|---|
| 75 | $start = microtime(true); |
|---|
| 76 | $objData->objQuery->begin(); |
|---|
| 77 | |
|---|
| 78 | // カテゴリ生成 |
|---|
| 79 | $objData->createCategories(); |
|---|
| 80 | // 規格生成 |
|---|
| 81 | $objData->createClassData(); |
|---|
| 82 | // 商品生成 |
|---|
| 83 | $objData->createProducts(); |
|---|
| 84 | // 商品と規格の関連づけ |
|---|
| 85 | $objData->relateClass(); |
|---|
| 86 | // 商品とカテゴリの関連づけ |
|---|
| 87 | $objData->relateProductsCategories(); |
|---|
| 88 | //$objData->objQuery->rollback(); |
|---|
| 89 | $objData->objQuery->commit(); |
|---|
| 90 | $end = microtime(true); |
|---|
| 91 | print("データの生成が完了しました!\n"); |
|---|
| 92 | printf("所要時間 %f 秒\n", $end - $start); |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | // }}} |
|---|
| 96 | // {{{ classes |
|---|
| 97 | |
|---|
| 98 | /** |
|---|
| 99 | * EC-CUBE のデータを生成する |
|---|
| 100 | */ |
|---|
| 101 | class CreateEcCubeData { |
|---|
| 102 | |
|---|
| 103 | /** SC_Query インスタンス */ |
|---|
| 104 | var $objQuery; |
|---|
| 105 | |
|---|
| 106 | /** 大カテゴリID の配列 */ |
|---|
| 107 | var $arrCategory1 = array(); |
|---|
| 108 | |
|---|
| 109 | /** 中カテゴリID の配列 */ |
|---|
| 110 | var $arrCategory2 = array(); |
|---|
| 111 | |
|---|
| 112 | /** 小カテゴリID の配列 */ |
|---|
| 113 | var $arrCategory3 = array(); |
|---|
| 114 | |
|---|
| 115 | /** 規格1 */ |
|---|
| 116 | var $arrClassCategory_id1 = array(); |
|---|
| 117 | |
|---|
| 118 | /** 規格2 */ |
|---|
| 119 | var $arrClassCategory_id2 = array(); |
|---|
| 120 | |
|---|
| 121 | /** |
|---|
| 122 | * コンストラクタ. |
|---|
| 123 | */ |
|---|
| 124 | function CreateEcCubeData() { |
|---|
| 125 | $this->objQuery = new SC_Query(); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | /** |
|---|
| 129 | * カテゴリを生成する. |
|---|
| 130 | * |
|---|
| 131 | * 以下のように, ツリー状のカテゴリを生成する |
|---|
| 132 | * |
|---|
| 133 | * 大カテゴリ -- 中カテゴリ -- 小カテゴリ |
|---|
| 134 | * | |- 小カテゴリ |
|---|
| 135 | * | |- 小カテゴリ |
|---|
| 136 | * | |
|---|
| 137 | * |- 中カテゴリ -- 小カテゴリ |
|---|
| 138 | * |- 小カテゴリ |
|---|
| 139 | * |- 小カテゴリ |
|---|
| 140 | * @return void |
|---|
| 141 | */ |
|---|
| 142 | function createCategories() { |
|---|
| 143 | |
|---|
| 144 | print("カテゴリを生成しています...\n"); |
|---|
| 145 | |
|---|
| 146 | $count = 0; |
|---|
| 147 | |
|---|
| 148 | // 全カテゴリ共通の値 |
|---|
| 149 | $sqlval['creator_id'] = 2; |
|---|
| 150 | $sqlval['create_date'] = "now()"; |
|---|
| 151 | $sqlval['update_date'] = "now()"; |
|---|
| 152 | $sqlval['del_flg'] = (string) "0"; |
|---|
| 153 | |
|---|
| 154 | // 大カテゴリを生成 |
|---|
| 155 | for ($i = 0; $i < TOP_CATEGORIES_VOLUME; $i++) { |
|---|
| 156 | $sqlval['category_name'] = sprintf("Category%d00", $i); |
|---|
| 157 | $sqlval['parent_category_id'] = (string) "0"; |
|---|
| 158 | $sqlval['level'] = 1; |
|---|
| 159 | $sqlval['rank'] = $this->lfGetTotalCategoryrank() - $count; |
|---|
| 160 | $sqlval['category_id'] = $this->objQuery->nextVal("dtb_category_category_id"); |
|---|
| 161 | |
|---|
| 162 | $this->objQuery->insert("dtb_category", $sqlval); |
|---|
| 163 | $this->arrCategory1[] = $sqlval['category_id']; |
|---|
| 164 | $count++; |
|---|
| 165 | print("."); |
|---|
| 166 | |
|---|
| 167 | // 中カテゴリを生成 |
|---|
| 168 | for ($j = 0; $j < MIDDLE_CATEGORIES_VOLUME; $j++) { |
|---|
| 169 | $sqlval['category_name'] = sprintf("Category%d%d0", $i, |
|---|
| 170 | $j + MIDDLE_CATEGORIES_VOLUME); |
|---|
| 171 | $sqlval['parent_category_id'] = (string) $sqlval['category_id']; |
|---|
| 172 | $sqlval['level'] = 2; |
|---|
| 173 | $sqlval['rank'] = $this->lfGetTotalCategoryrank() - $count; |
|---|
| 174 | $sqlval['category_id'] = $this->objQuery->nextVal("dtb_category_category_id"); |
|---|
| 175 | |
|---|
| 176 | $this->objQuery->insert("dtb_category", $sqlval); |
|---|
| 177 | $this->arrCategory2[] = $sqlval['category_id']; |
|---|
| 178 | $count++; |
|---|
| 179 | print("."); |
|---|
| 180 | |
|---|
| 181 | // 小カテゴリを生成 |
|---|
| 182 | for ($k = 0; $k < SMALL_CATEGORIES_VOLUME; $k++) { |
|---|
| 183 | $sqlval['category_name'] = sprintf("Category%d%d%d", |
|---|
| 184 | $i, $j, |
|---|
| 185 | $k + SMALL_CATEGORIES_VOLUME); |
|---|
| 186 | $sqlval['parent_category_id'] = (string) $sqlval['category_id']; |
|---|
| 187 | $sqlval['level'] = 3; |
|---|
| 188 | $sqlval['rank'] = $this->lfGetTotalCategoryrank() - $count; |
|---|
| 189 | $sqlval['category_id'] = $this->objQuery->nextVal("dtb_category_category_id"); |
|---|
| 190 | |
|---|
| 191 | $this->objQuery->insert("dtb_category", $sqlval); |
|---|
| 192 | $this->arrCategory3[] = $sqlval['category_id']; |
|---|
| 193 | $count++; |
|---|
| 194 | print("."); |
|---|
| 195 | } |
|---|
| 196 | } |
|---|
| 197 | } |
|---|
| 198 | print("\n"); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | /** |
|---|
| 202 | * 規格を生成する. |
|---|
| 203 | * |
|---|
| 204 | * @return void |
|---|
| 205 | */ |
|---|
| 206 | function createClassData() { |
|---|
| 207 | // 規格データ生成 |
|---|
| 208 | print("規格データを生成しています...\n"); |
|---|
| 209 | $this->createClass("Size"); |
|---|
| 210 | $this->createClass("Color"); |
|---|
| 211 | print("\n"); |
|---|
| 212 | |
|---|
| 213 | // 規格分類データ生成 |
|---|
| 214 | print("規格分類データを生成しています...\n"); |
|---|
| 215 | |
|---|
| 216 | // 規格1 |
|---|
| 217 | for ($i = 0; $i < CLASSCATEGORY1_VOLUME; $i++) { |
|---|
| 218 | $this->createClassCategory($this->arrSize[$i], |
|---|
| 219 | $this->arrclass_id[0], "size"); |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | // 規格2 |
|---|
| 223 | for ($i = 0; $i < CLASSCATEGORY2_VOLUME; $i++) { |
|---|
| 224 | $this->createClassCategory($this->arrSize[$i], |
|---|
| 225 | $this->arrclass_id[1], "color"); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | print("\n"); |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | /** |
|---|
| 232 | * 商品と規格の関連づけを行う. |
|---|
| 233 | * |
|---|
| 234 | * @return void |
|---|
| 235 | */ |
|---|
| 236 | function relateClass() { |
|---|
| 237 | |
|---|
| 238 | print("商品と規格の関連づけを行います...\n"); |
|---|
| 239 | |
|---|
| 240 | foreach ($this->arrProduct_id as $product_id) { |
|---|
| 241 | $this->createProductsClass($product_id); |
|---|
| 242 | } |
|---|
| 243 | print("\n"); |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | /** |
|---|
| 247 | * 商品を生成する. |
|---|
| 248 | * |
|---|
| 249 | * @return void |
|---|
| 250 | */ |
|---|
| 251 | function createProducts() { |
|---|
| 252 | |
|---|
| 253 | print("商品を生成しています...\n"); |
|---|
| 254 | for ($i = 0; $i < PRODUCTS_VOLUME; $i++) { |
|---|
| 255 | $sqlval['product_id'] = $this->objQuery->nextval("dtb_products_product_id"); |
|---|
| 256 | $sqlval['name'] = sprintf("商品%d", $i); |
|---|
| 257 | $sqlval['status'] = 1; |
|---|
| 258 | $sqlval['comment3'] = "コメント"; |
|---|
| 259 | $sqlval['main_list_comment'] = "コメント"; |
|---|
| 260 | $sqlval['main_list_image'] = "08311201_44f65122ee5fe.jpg"; |
|---|
| 261 | $sqlval['main_comment'] = "コメント"; |
|---|
| 262 | $sqlval['main_image'] = "08311202_44f6515906a41.jpg"; |
|---|
| 263 | $sqlval['main_large_image'] = "08311203_44f651959bcb5.jpg"; |
|---|
| 264 | $sqlval['sub_comment1'] = "コメント"; |
|---|
| 265 | $sqlval['del_flg'] = (string) "0"; |
|---|
| 266 | $sqlval['creator_id'] = 2; |
|---|
| 267 | $sqlval['create_date'] = "now()"; |
|---|
| 268 | $sqlval['update_date'] = "now()"; |
|---|
| 269 | $sqlval['deliv_date_id'] = 2; |
|---|
| 270 | $this->objQuery->insert("dtb_products", $sqlval); |
|---|
| 271 | |
|---|
| 272 | $this->arrProduct_id[] = $sqlval['product_id']; |
|---|
| 273 | print("*"); |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | /** |
|---|
| 278 | * 規格を生成する. |
|---|
| 279 | * |
|---|
| 280 | * @param $class_name string 規格名 |
|---|
| 281 | * @return void |
|---|
| 282 | */ |
|---|
| 283 | function createClass($class_name) { |
|---|
| 284 | // class_idを取得 |
|---|
| 285 | $sqlval['class_id'] = $this->objQuery->nextVal("dtb_class_class_id"); |
|---|
| 286 | $sqlval['name'] = $class_name; |
|---|
| 287 | $sqlval['status'] = null; |
|---|
| 288 | $sqlval['rank'] = "~(SELECT CASE |
|---|
| 289 | WHEN max(rank) + 1 IS NULL THEN 1 |
|---|
| 290 | ELSE max(rank) + 1 |
|---|
| 291 | END |
|---|
| 292 | FROM dtb_class |
|---|
| 293 | WHERE del_flg = 0),"; |
|---|
| 294 | $sqlval['creator_id'] = 2; |
|---|
| 295 | $sqlval['update_date'] = "now()"; |
|---|
| 296 | $sqlval['del_flg'] = (string) "0"; |
|---|
| 297 | $this->objQuery->insert("dtb_class", $sqlval); |
|---|
| 298 | |
|---|
| 299 | $this->arrclass_id[] = $sqlval['class_id']; |
|---|
| 300 | print("+"); |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | /** |
|---|
| 304 | * 規格分類を生成する. |
|---|
| 305 | * |
|---|
| 306 | * @param $classcategory_name string 規格名 |
|---|
| 307 | * @return void |
|---|
| 308 | */ |
|---|
| 309 | function createClassCategory($classcategory_name, $class_id, $class_name) { |
|---|
| 310 | $sqlval['classcategory_id'] = $this->objQuery->nextVal("dtb_classcategory_classcategory_id"); |
|---|
| 311 | $sqlval['name'] = $classcategory_name; |
|---|
| 312 | $sqlval['class_id'] = $class_id; |
|---|
| 313 | $sqlval['status'] = null; |
|---|
| 314 | $sqlval['rank'] = sprintf("~(SELECT CASE |
|---|
| 315 | WHEN max(rank) + 1 IS NULL THEN 1 |
|---|
| 316 | ELSE max(rank) + 1 |
|---|
| 317 | END |
|---|
| 318 | FROM dtb_classcategory |
|---|
| 319 | WHERE del_flg = 0 |
|---|
| 320 | AND class_id = %d),", $class_id); |
|---|
| 321 | $sqlval['creator_id'] = 2; |
|---|
| 322 | $sqlval['create_date'] = "now()"; |
|---|
| 323 | $sqlval['update_date'] = "now()"; |
|---|
| 324 | $sqlval['del_flg'] = (string) "0"; |
|---|
| 325 | |
|---|
| 326 | $this->objQuery->insert("dtb_classcategory", $sqlval); |
|---|
| 327 | |
|---|
| 328 | switch ($class_name) { |
|---|
| 329 | case "size": |
|---|
| 330 | $this->arrClassCategory_id1[] = $sqlval['classcategory_id']; |
|---|
| 331 | break; |
|---|
| 332 | |
|---|
| 333 | case "color": |
|---|
| 334 | $this->arrClassCategory_id2[] = $sqlval['classcategory_id']; |
|---|
| 335 | break; |
|---|
| 336 | default: |
|---|
| 337 | } |
|---|
| 338 | print("+"); |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | /** |
|---|
| 342 | * 商品規格を生成する. |
|---|
| 343 | * |
|---|
| 344 | * @param integer $product_id 商品ID |
|---|
| 345 | * @return void |
|---|
| 346 | */ |
|---|
| 347 | function createProductsClass($product_id) { |
|---|
| 348 | |
|---|
| 349 | printf("商品ID %d の商品規格を生成しています...\n", $product_id); |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | $sqlval['product_id'] = $product_id; |
|---|
| 353 | $sqlval['stock_unlimited'] = 1; |
|---|
| 354 | $sqlval['price01'] = 1000; |
|---|
| 355 | $sqlval['price02'] = 2000; |
|---|
| 356 | $sqlval['creator_id'] = 2; |
|---|
| 357 | $sqlval['create_date'] = "now()"; |
|---|
| 358 | $sqlval['update_date'] = "now()"; |
|---|
| 359 | $sqlval['del_flg'] = 0; |
|---|
| 360 | |
|---|
| 361 | $count = 0; |
|---|
| 362 | foreach ($this->arrClassCategory_id1 as $classCategory_id1) { |
|---|
| 363 | $c1['classcategory_id'] = $classCategory_id1; |
|---|
| 364 | $c1['class_combination_id'] = $this->objQuery->nextVal('dtb_class_combination_class_combination_id'); |
|---|
| 365 | $c1['level'] = 1; |
|---|
| 366 | $this->objQuery->insert("dtb_class_combination", $c1); |
|---|
| 367 | |
|---|
| 368 | foreach ($this->arrClassCategory_id2 as $classCategory_id2) { |
|---|
| 369 | $c2['classcategory_id'] = $classCategory_id2; |
|---|
| 370 | $c2['class_combination_id'] = $this->objQuery->nextVal('dtb_class_combination_class_combination_id'); |
|---|
| 371 | $c2['parent_class_combination_id'] = $c1['class_combination_id']; |
|---|
| 372 | $c2['level'] = 2; |
|---|
| 373 | $this->objQuery->insert("dtb_class_combination", $c2); |
|---|
| 374 | |
|---|
| 375 | $sqlval['product_class_id'] = |
|---|
| 376 | $this->objQuery->nextVal('dtb_products_class_product_class_id'); |
|---|
| 377 | $sqlval['product_code'] = sprintf("商品コード%d", $count); |
|---|
| 378 | |
|---|
| 379 | $sqlval['class_combination_id'] = $c2['class_combination_id']; |
|---|
| 380 | $this->objQuery->insert("dtb_products_class", $sqlval); |
|---|
| 381 | |
|---|
| 382 | $count++; |
|---|
| 383 | print("#"); |
|---|
| 384 | } |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | // 規格無し用 |
|---|
| 388 | $sqlval['product_class_id'] = $this->objQuery->nextVal('dtb_products_class_product_class_id'); |
|---|
| 389 | $sqlval['class_combination_id'] = null; |
|---|
| 390 | $sqlval['del_flg'] = 1; |
|---|
| 391 | $this->objQuery->insert("dtb_products_class", $sqlval); |
|---|
| 392 | |
|---|
| 393 | print("\n"); |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | /** |
|---|
| 397 | * 商品とカテゴリの関連づけを行う. |
|---|
| 398 | * |
|---|
| 399 | * @return void |
|---|
| 400 | */ |
|---|
| 401 | function relateProductsCategories() { |
|---|
| 402 | |
|---|
| 403 | print("商品とカテゴリの関連づけを行います...\n"); |
|---|
| 404 | $this->createProductsCategories($this->arrCategory1, "大カテゴリ"); |
|---|
| 405 | $this->createProductsCategories($this->arrCategory2, "中カテゴリ"); |
|---|
| 406 | $this->createProductsCategories($this->arrCategory3, "小カテゴリ"); |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | /** |
|---|
| 410 | * 商品カテゴリを生成する. |
|---|
| 411 | * |
|---|
| 412 | * @param array $arrCategory_id カテゴリID の配列 |
|---|
| 413 | * @return void |
|---|
| 414 | */ |
|---|
| 415 | function createProductsCategories($arrCategory_id, $category_name) { |
|---|
| 416 | |
|---|
| 417 | $count = 0; |
|---|
| 418 | printf("%s の商品カテゴリを生成しています...\n", $category_name); |
|---|
| 419 | foreach ($arrCategory_id as $category_id) { |
|---|
| 420 | $sqlval['category_id'] = $category_id; |
|---|
| 421 | |
|---|
| 422 | foreach($this->arrProduct_id as $product_id) { |
|---|
| 423 | $sqlval['product_id'] = $product_id; |
|---|
| 424 | $sqlval['rank'] = $count; |
|---|
| 425 | |
|---|
| 426 | $this->objQuery->insert("dtb_product_categories", $sqlval); |
|---|
| 427 | $count++; |
|---|
| 428 | print("$"); |
|---|
| 429 | } |
|---|
| 430 | } |
|---|
| 431 | print("\n"); |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | /** 規格1 */ |
|---|
| 435 | var $arrSize = array("m11(29cm)" |
|---|
| 436 | ,"m10 1/2(28.5cm)" |
|---|
| 437 | ,"m10(28cm)" |
|---|
| 438 | ,"m9 1/2(27.5cm)" |
|---|
| 439 | ,"m9(27cm)" |
|---|
| 440 | ,"m8 1/2(26.5cm)" |
|---|
| 441 | ,"m8(26cm)" |
|---|
| 442 | ,"43" |
|---|
| 443 | ,"42" |
|---|
| 444 | ,"41" |
|---|
| 445 | ,"43(27.0cm?27.5cm)" |
|---|
| 446 | ,"42(26.5cm?27.0cm)" |
|---|
| 447 | ,"37(ladies 23.5?24cm)" |
|---|
| 448 | ,"42(約27.5cm)" |
|---|
| 449 | ,"41(約26.5cm)" |
|---|
| 450 | ,"W36" |
|---|
| 451 | ,"W34" |
|---|
| 452 | ,"W32" |
|---|
| 453 | ,"43" |
|---|
| 454 | ,"42" |
|---|
| 455 | ,"41" |
|---|
| 456 | ,"m11" |
|---|
| 457 | ,"m10" |
|---|
| 458 | ,"m9.5" |
|---|
| 459 | ,"m9" |
|---|
| 460 | ,"m8" |
|---|
| 461 | ,"FREE" |
|---|
| 462 | ,"XS" |
|---|
| 463 | ,"S" |
|---|
| 464 | ,"M" |
|---|
| 465 | ,"L" |
|---|
| 466 | ,"XL" |
|---|
| 467 | ,"25-27" |
|---|
| 468 | ,"27-29" |
|---|
| 469 | ,"W28" |
|---|
| 470 | ,"W29" |
|---|
| 471 | ,"W30" |
|---|
| 472 | ,"W31" |
|---|
| 473 | ,"W32" |
|---|
| 474 | ,"W33" |
|---|
| 475 | ,"W34" |
|---|
| 476 | ,"W35" |
|---|
| 477 | ,"W36" |
|---|
| 478 | ,"4" |
|---|
| 479 | ,"6" |
|---|
| 480 | ,"8" |
|---|
| 481 | ,"10" |
|---|
| 482 | ,"12" |
|---|
| 483 | ,"10cm" |
|---|
| 484 | ,"12cm" |
|---|
| 485 | ,"14cm" |
|---|
| 486 | ,"16cm" |
|---|
| 487 | ,"18cm" |
|---|
| 488 | ,"20cm" |
|---|
| 489 | ,"22cm" |
|---|
| 490 | ,"24cm" |
|---|
| 491 | ,"26cm" |
|---|
| 492 | ,"28cm" |
|---|
| 493 | ,"30cm" |
|---|
| 494 | ,"32cm" |
|---|
| 495 | ,"34cm" |
|---|
| 496 | ,"36cm" |
|---|
| 497 | ,"38cm" |
|---|
| 498 | ,"40cm" |
|---|
| 499 | ,"10g" |
|---|
| 500 | ,"20g" |
|---|
| 501 | ,"30g" |
|---|
| 502 | ,"40g" |
|---|
| 503 | ,"50g" |
|---|
| 504 | ,"60g" |
|---|
| 505 | ,"70g" |
|---|
| 506 | ,"80g" |
|---|
| 507 | ,"90g" |
|---|
| 508 | ,"100g" |
|---|
| 509 | ,"110g" |
|---|
| 510 | ,"120g" |
|---|
| 511 | ,"130g" |
|---|
| 512 | ,"140g" |
|---|
| 513 | ,"150g" |
|---|
| 514 | ,"160g" |
|---|
| 515 | ,"170g" |
|---|
| 516 | ,"180g" |
|---|
| 517 | ,"190g" |
|---|
| 518 | ,"200g" |
|---|
| 519 | ,"8inch" |
|---|
| 520 | ,"10inch" |
|---|
| 521 | ,"12inch" |
|---|
| 522 | ,"14inch" |
|---|
| 523 | ,"16inch" |
|---|
| 524 | ,"18inch" |
|---|
| 525 | ,"20inch" |
|---|
| 526 | ,"22inch" |
|---|
| 527 | ,"24inch" |
|---|
| 528 | ,"26inch" |
|---|
| 529 | ,"28inch" |
|---|
| 530 | ,"30inch" |
|---|
| 531 | ,"32inch" |
|---|
| 532 | ,"34inch" |
|---|
| 533 | ,"36inch" |
|---|
| 534 | ,"38inch" |
|---|
| 535 | ); |
|---|
| 536 | |
|---|
| 537 | /** 規格2 */ |
|---|
| 538 | var $arrColor = array("white" |
|---|
| 539 | ,"whitesmoke" |
|---|
| 540 | ,"snow" |
|---|
| 541 | ,"ghostwhite" |
|---|
| 542 | ,"mintcream" |
|---|
| 543 | ,"azure" |
|---|
| 544 | ,"ivory" |
|---|
| 545 | ,"floralwhite" |
|---|
| 546 | ,"aliceblue" |
|---|
| 547 | ,"lavenderblush" |
|---|
| 548 | ,"seashell" |
|---|
| 549 | ,"honeydew" |
|---|
| 550 | ,"lightyellow" |
|---|
| 551 | ,"oldlace" |
|---|
| 552 | ,"cornsilk" |
|---|
| 553 | ,"linen" |
|---|
| 554 | ,"lemonchiffon" |
|---|
| 555 | ,"lavender" |
|---|
| 556 | ,"beige" |
|---|
| 557 | ,"lightgoldenrodyellow" |
|---|
| 558 | ,"mistyrose" |
|---|
| 559 | ,"papayawhip" |
|---|
| 560 | ,"antiquewhite" |
|---|
| 561 | ,"lightcyan" |
|---|
| 562 | ,"cyan" |
|---|
| 563 | ,"aqua" |
|---|
| 564 | ,"darkcyan" |
|---|
| 565 | ,"teal" |
|---|
| 566 | ,"darkslategray" |
|---|
| 567 | ,"turquoise" |
|---|
| 568 | ,"paleturquoise" |
|---|
| 569 | ,"mediumturquoise" |
|---|
| 570 | ,"aquamarine" |
|---|
| 571 | ,"gainsboro" |
|---|
| 572 | ,"lightgray" |
|---|
| 573 | ,"silver" |
|---|
| 574 | ,"darkgray" |
|---|
| 575 | ,"gray" |
|---|
| 576 | ,"dimgray" |
|---|
| 577 | ,"black" |
|---|
| 578 | ,"powderblue" |
|---|
| 579 | ,"lightblue" |
|---|
| 580 | ,"lightskyblue" |
|---|
| 581 | ,"skyblue" |
|---|
| 582 | ,"darkturquoise" |
|---|
| 583 | ,"deepskyblue" |
|---|
| 584 | ,"dodgerblue" |
|---|
| 585 | ,"royalblue" |
|---|
| 586 | ,"cornflowerblue" |
|---|
| 587 | ,"cadetblue" |
|---|
| 588 | ,"lightsteelblue" |
|---|
| 589 | ,"steelblue" |
|---|
| 590 | ,"lightslategray" |
|---|
| 591 | ,"slategray" |
|---|
| 592 | ,"blue" |
|---|
| 593 | ,"mediumblue" |
|---|
| 594 | ,"darkblue" |
|---|
| 595 | ,"navy" |
|---|
| 596 | ,"midnightblue" |
|---|
| 597 | ,"lightsalmon" |
|---|
| 598 | ,"darksalmon" |
|---|
| 599 | ,"salmon" |
|---|
| 600 | ,"tomato" |
|---|
| 601 | ,"lightcoral" |
|---|
| 602 | ,"coral" |
|---|
| 603 | ,"crimson" |
|---|
| 604 | ,"red" |
|---|
| 605 | ,"mediumorchid" |
|---|
| 606 | ,"mediumpurple" |
|---|
| 607 | ,"mediumslateblue" |
|---|
| 608 | ,"slateblue" |
|---|
| 609 | ,"blueviolet" |
|---|
| 610 | ,"darkviolet" |
|---|
| 611 | ,"darkorchid" |
|---|
| 612 | ,"darkslateblue" |
|---|
| 613 | ,"darkorchid" |
|---|
| 614 | ,"thistle" |
|---|
| 615 | ,"plum" |
|---|
| 616 | ,"violet" |
|---|
| 617 | ,"magenta" |
|---|
| 618 | ,"fuchsia" |
|---|
| 619 | ,"darkmagenta" |
|---|
| 620 | ,"purple" |
|---|
| 621 | ,"palegreen" |
|---|
| 622 | ,"lightgreen" |
|---|
| 623 | ,"lime" |
|---|
| 624 | ,"limegreen" |
|---|
| 625 | ,"forestgreen" |
|---|
| 626 | ,"green" |
|---|
| 627 | ,"darkgreen" |
|---|
| 628 | ,"greenyellow" |
|---|
| 629 | ,"chartreuse" |
|---|
| 630 | ,"lawngreen" |
|---|
| 631 | ,"yellowgreen" |
|---|
| 632 | ,"olivedrab" |
|---|
| 633 | ,"darkolivegreen" |
|---|
| 634 | ,"mediumaquamarine" |
|---|
| 635 | ,"mediumspringgreen" |
|---|
| 636 | ,"springgreen" |
|---|
| 637 | ,"darkseagreen" |
|---|
| 638 | ); |
|---|
| 639 | |
|---|
| 640 | /** |
|---|
| 641 | * 総カテゴリー数を計算し、dtb_categoryに代入するrankに使う |
|---|
| 642 | */ |
|---|
| 643 | function lfGetTotalCategoryrank(){ |
|---|
| 644 | $TotalCategoryrank = (TOP_CATEGORIES_VOLUME * MIDDLE_CATEGORIES_VOLUME * SMALL_CATEGORIES_VOLUME) + (MIDDLE_CATEGORIES_VOLUME * TOP_CATEGORIES_VOLUME) + TOP_CATEGORIES_VOLUME; |
|---|
| 645 | return $TotalCategoryrank; |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | } |
|---|
| 649 | /* |
|---|
| 650 | * This file is part of EC-CUBE |
|---|
| 651 | * |
|---|
| 652 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 653 | * |
|---|
| 654 | * http://www.lockon.co.jp/ |
|---|
| 655 | * |
|---|
| 656 | * This program is free software; you can redistribute it and/or |
|---|
| 657 | * modify it under the terms of the GNU General Public License |
|---|
| 658 | * as published by the Free Software Foundation; either version 2 |
|---|
| 659 | * of the License, or (at your option) any later version. |
|---|
| 660 | * |
|---|
| 661 | * This program is distributed in the hope that it will be useful, |
|---|
| 662 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 663 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 664 | * GNU General Public License for more details. |
|---|
| 665 | * |
|---|
| 666 | * You should have received a copy of the GNU General Public License |
|---|
| 667 | * along with this program; if not, write to the Free Software |
|---|
| 668 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 669 | */ |
|---|
| 670 | |
|---|
| 671 | /** |
|---|
| 672 | * SQLの構築・実行を行う |
|---|
| 673 | * |
|---|
| 674 | * TODO エラーハンドリング, ロギング方法を見直す |
|---|
| 675 | * |
|---|
| 676 | * @author LOCKON CO.,LTD. |
|---|
| 677 | * @version $Id$ |
|---|
| 678 | */ |
|---|
| 679 | class SC_Query { |
|---|
| 680 | |
|---|
| 681 | var $instance; |
|---|
| 682 | var $option; |
|---|
| 683 | var $where; |
|---|
| 684 | var $conn; |
|---|
| 685 | var $groupby; |
|---|
| 686 | var $order; |
|---|
| 687 | var $force_run; |
|---|
| 688 | |
|---|
| 689 | /** |
|---|
| 690 | * コンストラクタ. |
|---|
| 691 | * |
|---|
| 692 | * @param string $dsn データソース名 |
|---|
| 693 | * @param boolean $force_run エラーが発生しても処理を続行する場合 true |
|---|
| 694 | * @param boolean $new 新規に接続を行うかどうか |
|---|
| 695 | */ |
|---|
| 696 | function SC_Query($dsn = "", $force_run = false, $new = false) { |
|---|
| 697 | |
|---|
| 698 | if ($dsn == "") { |
|---|
| 699 | $dsn = DEFAULT_DSN; |
|---|
| 700 | } |
|---|
| 701 | |
|---|
| 702 | // Debugモード指定 |
|---|
| 703 | $options['debug'] = PEAR_DB_DEBUG; |
|---|
| 704 | // 持続的接続オプション |
|---|
| 705 | $options['persistent'] = PEAR_DB_PERSISTENT; |
|---|
| 706 | |
|---|
| 707 | if ($new) { |
|---|
| 708 | $this->conn = MDB2::connect($dsn, $options); |
|---|
| 709 | } else { |
|---|
| 710 | $this->conn = MDB2::singleton($dsn, $options); |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | if (!PEAR::isError($this->conn)) { |
|---|
| 714 | $this->conn->setCharset(CHAR_CODE); |
|---|
| 715 | $this->conn->setFetchMode(MDB2_FETCHMODE_ASSOC); |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | $this->force_run = $force_run; |
|---|
| 719 | $this->where = ""; |
|---|
| 720 | $this->order = ""; |
|---|
| 721 | $this->groupby = ""; |
|---|
| 722 | $this->option = ""; |
|---|
| 723 | } |
|---|
| 724 | |
|---|
| 725 | /** |
|---|
| 726 | * シングルトンの SC_Query インスタンスを取得する. |
|---|
| 727 | * |
|---|
| 728 | * @param string $dsn データソース名 |
|---|
| 729 | * @param boolean $force_run エラーが発生しても処理を続行する場合 true |
|---|
| 730 | * @param boolean $new 新規に接続を行うかどうか |
|---|
| 731 | * @return SC_Query シングルトンの SC_Query インスタンス |
|---|
| 732 | */ |
|---|
| 733 | function getSingletonInstance($dsn = "", $force_run = false, $new = false) { |
|---|
| 734 | if (is_null($this->instance)) { |
|---|
| 735 | $this->instance =& new SC_Query($dsn = "", $force_run, $new); |
|---|
| 736 | } |
|---|
| 737 | $this->instance->where = ""; |
|---|
| 738 | $this->instance->order = ""; |
|---|
| 739 | $this->instance->groupby = ""; |
|---|
| 740 | $this->instance->option = ""; |
|---|
| 741 | return $this->instance; |
|---|
| 742 | } |
|---|
| 743 | |
|---|
| 744 | /** |
|---|
| 745 | * エラー判定を行う. |
|---|
| 746 | * |
|---|
| 747 | * @deprecated PEAR::isError() を使用して下さい |
|---|
| 748 | * @return boolean |
|---|
| 749 | */ |
|---|
| 750 | function isError() { |
|---|
| 751 | if(PEAR::isError($this->conn)) { |
|---|
| 752 | return true; |
|---|
| 753 | } |
|---|
| 754 | return false; |
|---|
| 755 | } |
|---|
| 756 | |
|---|
| 757 | /** |
|---|
| 758 | * COUNT文を実行する. |
|---|
| 759 | * |
|---|
| 760 | * @param string $table テーブル名 |
|---|
| 761 | * @param string $where where句 |
|---|
| 762 | * @param array $arrval プレースホルダ |
|---|
| 763 | * @return integer 件数 |
|---|
| 764 | */ |
|---|
| 765 | function count($table, $where = "", $arrval = array()) { |
|---|
| 766 | if(strlen($where) <= 0) { |
|---|
| 767 | $sqlse = "SELECT COUNT(*) FROM $table"; |
|---|
| 768 | } else { |
|---|
| 769 | $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; |
|---|
| 770 | } |
|---|
| 771 | return $this->getOne($sqlse, $arrval); |
|---|
| 772 | } |
|---|
| 773 | |
|---|
| 774 | /** |
|---|
| 775 | * SELECT文を実行する. |
|---|
| 776 | * |
|---|
| 777 | * @param string $col カラム名. 複数カラムの場合はカンマ区切りで書く |
|---|
| 778 | * @param string $table テーブル名 |
|---|
| 779 | * @param string $where WHERE句 |
|---|
| 780 | * @param array $arrval プレースホルダ |
|---|
| 781 | * @param integer $fetchmode 使用するフェッチモード。デフォルトは MDB2_FETCHMODE_ASSOC。 |
|---|
| 782 | * @return array|null |
|---|
| 783 | */ |
|---|
| 784 | function select($col, $table, $where = "", $arrval = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { |
|---|
| 785 | $sqlse = $this->getSql($col, $table, $where); |
|---|
| 786 | return $this->getAll($sqlse, $arrval, $fetchmode); |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | /** |
|---|
| 790 | * 直前に実行されたSQL文を取得する. |
|---|
| 791 | * |
|---|
| 792 | * @param boolean $disp trueの場合、画面出力を行う. |
|---|
| 793 | * @return string SQL文 |
|---|
| 794 | */ |
|---|
| 795 | function getLastQuery($disp = true) { |
|---|
| 796 | $sql = $this->conn->last_query; |
|---|
| 797 | if($disp) { |
|---|
| 798 | print($sql.";<br />\n"); |
|---|
| 799 | } |
|---|
| 800 | return $sql; |
|---|
| 801 | } |
|---|
| 802 | |
|---|
| 803 | /** |
|---|
| 804 | * トランザクションをコミットする. |
|---|
| 805 | * |
|---|
| 806 | * @return MDB2_OK 成功した場合は MDB2_OK; |
|---|
| 807 | * 失敗した場合は PEAR::Error オブジェクト |
|---|
| 808 | */ |
|---|
| 809 | function commit() { |
|---|
| 810 | return $this->conn->commit(); |
|---|
| 811 | } |
|---|
| 812 | |
|---|
| 813 | /** |
|---|
| 814 | * トランザクションを開始する. |
|---|
| 815 | * |
|---|
| 816 | * @return MDB2_OK 成功した場合は MDB2_OK; |
|---|
| 817 | * 失敗した場合は PEAR::Error オブジェクト |
|---|
| 818 | */ |
|---|
| 819 | function begin() { |
|---|
| 820 | return $this->conn->beginTransaction(); |
|---|
| 821 | } |
|---|
| 822 | |
|---|
| 823 | /** |
|---|
| 824 | * トランザクションをロールバックする. |
|---|
| 825 | * |
|---|
| 826 | * @return MDB2_OK 成功した場合は MDB2_OK; |
|---|
| 827 | * 失敗した場合は PEAR::Error オブジェクト |
|---|
| 828 | */ |
|---|
| 829 | function rollback() { |
|---|
| 830 | return $this->conn->rollback(); |
|---|
| 831 | } |
|---|
| 832 | |
|---|
| 833 | /** |
|---|
| 834 | * トランザクションが開始されているかチェックする. |
|---|
| 835 | * |
|---|
| 836 | * @return boolean トランザクションが開始されている場合 true |
|---|
| 837 | */ |
|---|
| 838 | function inTransaction() { |
|---|
| 839 | return $this->conn->inTransaction(); |
|---|
| 840 | } |
|---|
| 841 | |
|---|
| 842 | /** |
|---|
| 843 | * 更新系の SQL を実行する. |
|---|
| 844 | * |
|---|
| 845 | * この関数は SC_Query::query() のエイリアスです. |
|---|
| 846 | * |
|---|
| 847 | * FIXME MDB2::exec() の実装であるべき |
|---|
| 848 | */ |
|---|
| 849 | function exec($str, $arrval = array()) { |
|---|
| 850 | return $this->query($str, $arrval); |
|---|
| 851 | } |
|---|
| 852 | |
|---|
| 853 | /** |
|---|
| 854 | * クエリを実行し、全ての行を返す |
|---|
| 855 | * |
|---|
| 856 | * @param string $sql SQL クエリ |
|---|
| 857 | * @param array $arrVal プリペアドステートメントの実行時に使用される配列。配列の要素数は、クエリ内のプレースホルダの数と同じでなければなりません。 |
|---|
| 858 | * @param integer $fetchmode 使用するフェッチモード。デフォルトは DB_FETCHMODE_ASSOC。 |
|---|
| 859 | * @return array データを含む2次元配列。失敗した場合に 0 または DB_Error オブジェクトを返します。 |
|---|
| 860 | */ |
|---|
| 861 | function getAll($sql, $arrval = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { |
|---|
| 862 | |
|---|
| 863 | $sth =& $this->prepare($sql); |
|---|
| 864 | if (PEAR::isError($sth) && $this->force_run) { |
|---|
| 865 | return; |
|---|
| 866 | } |
|---|
| 867 | |
|---|
| 868 | $affected =& $this->execute($sth, $arrval); |
|---|
| 869 | if (PEAR::isError($affected) && $this->force_run) { |
|---|
| 870 | return; |
|---|
| 871 | } |
|---|
| 872 | |
|---|
| 873 | return $affected->fetchAll($fetchmode); |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| 876 | /** |
|---|
| 877 | * 構築した SELECT 文を取得する. |
|---|
| 878 | * |
|---|
| 879 | * @param string $col SELECT 文に含めるカラム名 |
|---|
| 880 | * @param string $table SELECT 文に含めるテーブル名 |
|---|
| 881 | * @param string $where SELECT 文に含める WHERE 句 |
|---|
| 882 | * @return string 構築済みの SELECT 文 |
|---|
| 883 | */ |
|---|
| 884 | function getSql($col, $table, $where = '') { |
|---|
| 885 | $sqlse = "SELECT $col FROM $table"; |
|---|
| 886 | |
|---|
| 887 | // 引数の$whereを優先する。 |
|---|
| 888 | if (strlen($where) >= 1) { |
|---|
| 889 | $sqlse .= " WHERE $where"; |
|---|
| 890 | } elseif (strlen($this->where) >= 1) { |
|---|
| 891 | $sqlse .= " WHERE " . $this->where; |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | $sqlse .= ' ' . $this->groupby . ' ' . $this->order . ' ' . $this->option; |
|---|
| 895 | |
|---|
| 896 | return $sqlse; |
|---|
| 897 | } |
|---|
| 898 | |
|---|
| 899 | /** |
|---|
| 900 | * SELECT 文の末尾に付与する SQL を設定する. |
|---|
| 901 | * |
|---|
| 902 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 903 | * |
|---|
| 904 | * @param string $str 付与する SQL 文 |
|---|
| 905 | * @return SC_Query 自分自身のインスタンス |
|---|
| 906 | */ |
|---|
| 907 | function setOption($str) { |
|---|
| 908 | $this->option = $str; |
|---|
| 909 | return $this; |
|---|
| 910 | } |
|---|
| 911 | |
|---|
| 912 | /** |
|---|
| 913 | * SELECT 文に付与する LIMIT, OFFSET 句を設定する. |
|---|
| 914 | * |
|---|
| 915 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 916 | * TODO MDB2::setLimit() を使用する |
|---|
| 917 | * |
|---|
| 918 | * @param integer $limit LIMIT 句に付与する値 |
|---|
| 919 | * @param integer $offset OFFSET 句に付与する値 |
|---|
| 920 | * @return SC_Query 自分自身のインスタンス |
|---|
| 921 | */ |
|---|
| 922 | function setLimitOffset($limit, $offset = 0) { |
|---|
| 923 | if (is_numeric($limit) && is_numeric($offset)){ |
|---|
| 924 | |
|---|
| 925 | $option = " LIMIT " . $limit; |
|---|
| 926 | $option.= " OFFSET " . $offset; |
|---|
| 927 | $this->option .= $option; |
|---|
| 928 | } |
|---|
| 929 | return $this; |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | /** |
|---|
| 933 | * SELECT 文に付与する GROUP BY 句を設定する. |
|---|
| 934 | * |
|---|
| 935 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 936 | * |
|---|
| 937 | * @param string $str GROUP BY 句に付与する文字列 |
|---|
| 938 | * @return SC_Query 自分自身のインスタンス |
|---|
| 939 | */ |
|---|
| 940 | function setGroupBy($str) { |
|---|
| 941 | if (strlen($str) == 0) { |
|---|
| 942 | $this->groupby = ''; |
|---|
| 943 | } else { |
|---|
| 944 | $this->groupby = "GROUP BY " . $str; |
|---|
| 945 | } |
|---|
| 946 | return $this; |
|---|
| 947 | } |
|---|
| 948 | |
|---|
| 949 | /** |
|---|
| 950 | * SELECT 文の WHERE 句に付与する AND 条件を設定する. |
|---|
| 951 | * |
|---|
| 952 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 953 | * |
|---|
| 954 | * @param string $str WHERE 句に付与する AND 条件の文字列 |
|---|
| 955 | * @return SC_Query 自分自身のインスタンス |
|---|
| 956 | */ |
|---|
| 957 | function andWhere($str) { |
|---|
| 958 | if($this->where != "") { |
|---|
| 959 | $this->where .= " AND " . $str; |
|---|
| 960 | } else { |
|---|
| 961 | $this->where = $str; |
|---|
| 962 | } |
|---|
| 963 | return $this; |
|---|
| 964 | } |
|---|
| 965 | |
|---|
| 966 | /** |
|---|
| 967 | * SELECT 文の WHERE 句に付与する OR 条件を設定する. |
|---|
| 968 | * |
|---|
| 969 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 970 | * |
|---|
| 971 | * @param string $str WHERE 句に付与する OR 条件の文字列 |
|---|
| 972 | * @return SC_Query 自分自身のインスタンス |
|---|
| 973 | */ |
|---|
| 974 | function orWhere($str) { |
|---|
| 975 | if($this->where != "") { |
|---|
| 976 | $this->where .= " OR " . $str; |
|---|
| 977 | } else { |
|---|
| 978 | $this->where = $str; |
|---|
| 979 | } |
|---|
| 980 | return $this; |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | /** |
|---|
| 984 | * SELECT 文に付与する WHERE 句を設定する. |
|---|
| 985 | * |
|---|
| 986 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 987 | * |
|---|
| 988 | * @param string $str WHERE 句に付与する文字列 |
|---|
| 989 | * @return SC_Query 自分自身のインスタンス |
|---|
| 990 | */ |
|---|
| 991 | function setWhere($str) { |
|---|
| 992 | $this->where = $str; |
|---|
| 993 | return $this; |
|---|
| 994 | } |
|---|
| 995 | |
|---|
| 996 | /** |
|---|
| 997 | * SELECT 文に付与する ORDER BY 句を設定する. |
|---|
| 998 | * |
|---|
| 999 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 1000 | * |
|---|
| 1001 | * @param string $str ORDER BY 句に付与する文字列 |
|---|
| 1002 | * @return SC_Query 自分自身のインスタンス |
|---|
| 1003 | */ |
|---|
| 1004 | function setOrder($str) { |
|---|
| 1005 | if (strlen($str) == 0) { |
|---|
| 1006 | $this->order = ''; |
|---|
| 1007 | } else { |
|---|
| 1008 | $this->order = "ORDER BY " . $str; |
|---|
| 1009 | } |
|---|
| 1010 | return $this; |
|---|
| 1011 | } |
|---|
| 1012 | |
|---|
| 1013 | /** |
|---|
| 1014 | * SELECT 文に付与する LIMIT 句を設定する. |
|---|
| 1015 | * |
|---|
| 1016 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 1017 | * |
|---|
| 1018 | * @param integer $limit LIMIT 句に設定する値 |
|---|
| 1019 | * @return SC_Query 自分自身のインスタンス |
|---|
| 1020 | */ |
|---|
| 1021 | function setLimit($limit){ |
|---|
| 1022 | if ( is_numeric($limit)){ |
|---|
| 1023 | $this->option = " LIMIT " .$limit; |
|---|
| 1024 | } |
|---|
| 1025 | return $this; |
|---|
| 1026 | } |
|---|
| 1027 | |
|---|
| 1028 | /** |
|---|
| 1029 | * SELECT 文に付与する OFFSET 句を設定する. |
|---|
| 1030 | * |
|---|
| 1031 | * この関数で設定した値は SC_Query::getSql() で使用されます. |
|---|
| 1032 | * |
|---|
| 1033 | * @param integer $offset LIMIT 句に設定する値 |
|---|
| 1034 | * @return SC_Query 自分自身のインスタンス |
|---|
| 1035 | */ |
|---|
| 1036 | function setOffset($offset) { |
|---|
| 1037 | if ( is_numeric($offset)){ |
|---|
| 1038 | $this->offset = " OFFSET " .$offset; |
|---|
| 1039 | } |
|---|
| 1040 | return $this; |
|---|
| 1041 | } |
|---|
| 1042 | |
|---|
| 1043 | /** |
|---|
| 1044 | * INSERT文を実行する. |
|---|
| 1045 | * |
|---|
| 1046 | * @param string $table テーブル名 |
|---|
| 1047 | * @param array $sqlval array('カラム名' => '値',...)の連想配列 |
|---|
| 1048 | * @return |
|---|
| 1049 | */ |
|---|
| 1050 | function insert($table, $sqlval) { |
|---|
| 1051 | $strcol = ''; |
|---|
| 1052 | $strval = ''; |
|---|
| 1053 | $find = false; |
|---|
| 1054 | |
|---|
| 1055 | if(count($sqlval) <= 0 ) return false; |
|---|
| 1056 | |
|---|
| 1057 | foreach ($sqlval as $key => $val) { |
|---|
| 1058 | $strcol .= $key . ','; |
|---|
| 1059 | if(eregi("^Now\(\)$", $val)) { |
|---|
| 1060 | $strval .= 'Now(),'; |
|---|
| 1061 | } else if(ereg("^~", $val)) { |
|---|
| 1062 | $strval .= ereg_replace("^~", "", $val); |
|---|
| 1063 | } else { |
|---|
| 1064 | $strval .= '?,'; |
|---|
| 1065 | $arrval[] = $val; |
|---|
| 1066 | } |
|---|
| 1067 | $find = true; |
|---|
| 1068 | } |
|---|
| 1069 | if(!$find) { |
|---|
| 1070 | return false; |
|---|
| 1071 | } |
|---|
| 1072 | // 文末の","を削除 |
|---|
| 1073 | $strcol = ereg_replace(",$","",$strcol); |
|---|
| 1074 | // 文末の","を削除 |
|---|
| 1075 | $strval = ereg_replace(",$","",$strval); |
|---|
| 1076 | $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; |
|---|
| 1077 | // INSERT文の実行 |
|---|
| 1078 | $ret = $this->query($sqlin, $arrval); |
|---|
| 1079 | |
|---|
| 1080 | return $ret; |
|---|
| 1081 | } |
|---|
| 1082 | |
|---|
| 1083 | /** |
|---|
| 1084 | * UPDATE文を実行する. |
|---|
| 1085 | * |
|---|
| 1086 | * @param string $table テーブル名 |
|---|
| 1087 | * @param array $sqlval array('カラム名' => '値',...)の連想配列 |
|---|
| 1088 | * @param string $where WHERE句 |
|---|
| 1089 | * @param array $arrValIn WHERE句用のプレースホルダ配列 (従来は追加カラム用も兼ねていた) |
|---|
| 1090 | * @param array $arrRawSql 追加カラム |
|---|
| 1091 | * @param array $arrRawSqlVal 追加カラム用のプレースホルダ配列 |
|---|
| 1092 | * @return |
|---|
| 1093 | */ |
|---|
| 1094 | function update($table, $sqlval, $where = "", $arrValIn = array(), $arrRawSql = array(), $arrRawSqlVal = array()) { |
|---|
| 1095 | $arrCol = array(); |
|---|
| 1096 | $arrVal = array(); |
|---|
| 1097 | $find = false; |
|---|
| 1098 | foreach ($sqlval as $key => $val) { |
|---|
| 1099 | if (eregi("^Now\(\)$", $val)) { |
|---|
| 1100 | $arrCol[] = $key . '= Now()'; |
|---|
| 1101 | } else { |
|---|
| 1102 | $arrCol[] = $key . '= ?'; |
|---|
| 1103 | $arrVal[] = $val; |
|---|
| 1104 | } |
|---|
| 1105 | $find = true; |
|---|
| 1106 | } |
|---|
| 1107 | |
|---|
| 1108 | if ($arrRawSql != "") { |
|---|
| 1109 | foreach($arrRawSql as $key => $val) { |
|---|
| 1110 | $arrCol[] = "$key = $val"; |
|---|
| 1111 | } |
|---|
| 1112 | } |
|---|
| 1113 | |
|---|
| 1114 | $arrVal = array_merge($arrVal, $arrRawSqlVal); |
|---|
| 1115 | |
|---|
| 1116 | if (empty($arrCol)) { |
|---|
| 1117 | return false; |
|---|
| 1118 | } |
|---|
| 1119 | |
|---|
| 1120 | // 文末の","を削除 |
|---|
| 1121 | $strcol = implode(', ', $arrCol); |
|---|
| 1122 | |
|---|
| 1123 | if (is_array($arrValIn)) { // 旧版との互換用 |
|---|
| 1124 | // プレースホルダー用に配列を追加 |
|---|
| 1125 | $arrVal = array_merge($arrVal, $arrValIn); |
|---|
| 1126 | } |
|---|
| 1127 | |
|---|
| 1128 | $sqlup = "UPDATE $table SET $strcol"; |
|---|
| 1129 | if (strlen($where) >= 1) { |
|---|
| 1130 | $sqlup .= " WHERE $where"; |
|---|
| 1131 | } |
|---|
| 1132 | |
|---|
| 1133 | // UPDATE文の実行 |
|---|
| 1134 | return $this->query($sqlup, $arrVal); |
|---|
| 1135 | } |
|---|
| 1136 | |
|---|
| 1137 | /** |
|---|
| 1138 | * MAX文を実行する. |
|---|
| 1139 | * |
|---|
| 1140 | * @param string $table テーブル名 |
|---|
| 1141 | * @param string $col カラム名 |
|---|
| 1142 | * @param string $where 付与する WHERE 句 |
|---|
| 1143 | * @param array $arrval ブレースホルダに挿入する値 |
|---|
| 1144 | * @return integer MAX文の実行結果 |
|---|
| 1145 | */ |
|---|
| 1146 | function max($table, $col, $where = "", $arrval = array()) { |
|---|
| 1147 | $ret = $this->get($table, "MAX($col)", $where, $arrval); |
|---|
| 1148 | return $ret; |
|---|
| 1149 | } |
|---|
| 1150 | |
|---|
| 1151 | /** |
|---|
| 1152 | * MIN文を実行する. |
|---|
| 1153 | * |
|---|
| 1154 | * @param string $table テーブル名 |
|---|
| 1155 | * @param string $col カラム名 |
|---|
| 1156 | * @param string $where 付与する WHERE 句 |
|---|
| 1157 | * @param array $arrval ブレースホルダに挿入する値 |
|---|
| 1158 | * @return integer MIN文の実行結果 |
|---|
| 1159 | */ |
|---|
| 1160 | function min($table, $col, $where = "", $arrval = array()) { |
|---|
| 1161 | $ret = $this->get($table, "MIN($col)", $where, $arrval); |
|---|
| 1162 | return $ret; |
|---|
| 1163 | } |
|---|
| 1164 | |
|---|
| 1165 | /** |
|---|
| 1166 | * SQL を構築して, 特定のカラムの値を取得する. |
|---|
| 1167 | * |
|---|
| 1168 | * @param string $table テーブル名 |
|---|
| 1169 | * @param string $col カラム名 |
|---|
| 1170 | * @param string $where 付与する WHERE 句 |
|---|
| 1171 | * @param array $arrval ブレースホルダに挿入する値 |
|---|
| 1172 | * @return mixed SQL の実行結果 |
|---|
| 1173 | */ |
|---|
| 1174 | function get($table, $col, $where = "", $arrval = array()) { |
|---|
| 1175 | $sqlse = $this->getSql($col, $table, $where); |
|---|
| 1176 | // SQL文の実行 |
|---|
| 1177 | $ret = $this->getOne($sqlse, $arrval); |
|---|
| 1178 | return $ret; |
|---|
| 1179 | } |
|---|
| 1180 | |
|---|
| 1181 | /** |
|---|
| 1182 | * SQL を指定して, 特定のカラムの値を取得する. |
|---|
| 1183 | * |
|---|
| 1184 | * @param string $sql 実行する SQL |
|---|
| 1185 | * @param array $arrval ブレースホルダに挿入する値 |
|---|
| 1186 | * @return mixed SQL の実行結果 |
|---|
| 1187 | */ |
|---|
| 1188 | function getOne($sql, $arrval = array()) { |
|---|
| 1189 | |
|---|
| 1190 | $sth =& $this->prepare($sql); |
|---|
| 1191 | if (PEAR::isError($sth) && $this->force_run) { |
|---|
| 1192 | return; |
|---|
| 1193 | } |
|---|
| 1194 | |
|---|
| 1195 | $affected =& $this->execute($sth, $arrval); |
|---|
| 1196 | if (PEAR::isError($affected) && $this->force_run) { |
|---|
| 1197 | return; |
|---|
| 1198 | } |
|---|
| 1199 | |
|---|
| 1200 | return $affected->fetchOne(); |
|---|
| 1201 | } |
|---|
| 1202 | |
|---|
| 1203 | /** |
|---|
| 1204 | * 一行をカラム名をキーとした連想配列として取得 |
|---|
| 1205 | * |
|---|
| 1206 | * @param string $table テーブル名 |
|---|
| 1207 | * @param string $col カラム名 |
|---|
| 1208 | * @param string $where WHERE句 |
|---|
| 1209 | * @param array $arrVal プレースホルダ配列 |
|---|
| 1210 | * @param integer $fetchmode 使用するフェッチモード。デフォルトは MDB2_FETCHMODE_ASSOC。 |
|---|
| 1211 | * @return array array('カラム名' => '値', ...)の連想配列 |
|---|
| 1212 | */ |
|---|
| 1213 | function getRow($table, $col, $where = "", $arrVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { |
|---|
| 1214 | |
|---|
| 1215 | $sql = $this->getSql($col, $table, $where); |
|---|
| 1216 | |
|---|
| 1217 | $sth =& $this->prepare($sql); |
|---|
| 1218 | if (PEAR::isError($sth) && $this->force_run) { |
|---|
| 1219 | return; |
|---|
| 1220 | } |
|---|
| 1221 | |
|---|
| 1222 | $affected =& $this->execute($sth, $arrVal); |
|---|
| 1223 | if (PEAR::isError($affected) && $this->force_run) { |
|---|
| 1224 | return; |
|---|
| 1225 | } |
|---|
| 1226 | |
|---|
| 1227 | return $affected->fetchRow($fetchmode); |
|---|
| 1228 | } |
|---|
| 1229 | |
|---|
| 1230 | /** |
|---|
| 1231 | * SELECT 文の実行結果を 1行のみ取得する. |
|---|
| 1232 | * |
|---|
| 1233 | * @param string $table テーブル名 |
|---|
| 1234 | * @param string $col カラム名 |
|---|
| 1235 | * @param string $where 付与する WHERE 句 |
|---|
| 1236 | * @param array $arrval ブレースホルダに挿入する値 |
|---|
| 1237 | * @return array SQL の実行結果の配列 |
|---|
| 1238 | */ |
|---|
| 1239 | function getCol($table, $col, $where = "", $arrval = array()) { |
|---|
| 1240 | $sql = $this->getSql($col, $table, $where); |
|---|
| 1241 | |
|---|
| 1242 | $sth =& $this->prepare($sql); |
|---|
| 1243 | if (PEAR::isError($sth) && $this->force_run) { |
|---|
| 1244 | return; |
|---|
| 1245 | } |
|---|
| 1246 | |
|---|
| 1247 | $affected =& $this->execute($sth, $arrval); |
|---|
| 1248 | if (PEAR::isError($affected) && $this->force_run) { |
|---|
| 1249 | return; |
|---|
| 1250 | } |
|---|
| 1251 | |
|---|
| 1252 | return $affected->fetchCol($col); |
|---|
| 1253 | } |
|---|
| 1254 | |
|---|
| 1255 | /** |
|---|
| 1256 | * レコードの削除 |
|---|
| 1257 | * |
|---|
| 1258 | * @param string $table テーブル名 |
|---|
| 1259 | * @param string $where WHERE句 |
|---|
| 1260 | * @param array $arrval プレースホルダ |
|---|
| 1261 | * @return |
|---|
| 1262 | */ |
|---|
| 1263 | function delete($table, $where = "", $arrval = array()) { |
|---|
| 1264 | if(strlen($where) <= 0) { |
|---|
| 1265 | $sqlde = "DELETE FROM $table"; |
|---|
| 1266 | } else { |
|---|
| 1267 | $sqlde = "DELETE FROM $table WHERE $where"; |
|---|
| 1268 | } |
|---|
| 1269 | $ret = $this->query($sqlde, $arrval); |
|---|
| 1270 | return $ret; |
|---|
| 1271 | } |
|---|
| 1272 | |
|---|
| 1273 | /** |
|---|
| 1274 | * 次のシーケンス値を取得する. |
|---|
| 1275 | * |
|---|
| 1276 | * @param string $seq_name 取得するシーケンス名 |
|---|
| 1277 | * @param integer 次のシーケンス値 |
|---|
| 1278 | */ |
|---|
| 1279 | function nextVal($seq_name) { |
|---|
| 1280 | return $this->conn->nextID($seq_name); |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | /** |
|---|
| 1284 | * 現在のシーケンス値を取得する. |
|---|
| 1285 | * |
|---|
| 1286 | * @param string $seq_name 取得するシーケンス名 |
|---|
| 1287 | * @return integer 現在のシーケンス値 |
|---|
| 1288 | */ |
|---|
| 1289 | function currVal($seq_name) { |
|---|
| 1290 | return $this->conn->currID($seq_name); |
|---|
| 1291 | } |
|---|
| 1292 | |
|---|
| 1293 | /** |
|---|
| 1294 | * シーケンス値を設定する. |
|---|
| 1295 | * |
|---|
| 1296 | * @param string $seq_name シーケンス名 |
|---|
| 1297 | * @param integer $start 設定するシーケンス値 |
|---|
| 1298 | * @return MDB2_OK |
|---|
| 1299 | */ |
|---|
| 1300 | function setVal($seq_name, $start) { |
|---|
| 1301 | $this->conn->loadModule('Manager'); |
|---|
| 1302 | // XXX エラーハンドリングを行う |
|---|
| 1303 | $this->conn->dropSequence($seq_name); |
|---|
| 1304 | return $this->conn->createSequence($seq_name, $start); |
|---|
| 1305 | } |
|---|
| 1306 | |
|---|
| 1307 | /** |
|---|
| 1308 | * SQL を実行する. |
|---|
| 1309 | * |
|---|
| 1310 | * XXX 更新系には exec() を使用するべき |
|---|
| 1311 | * |
|---|
| 1312 | * @param string $n 実行する SQL 文 |
|---|
| 1313 | * @param array $arrval ブレースホルダに挿入する値 |
|---|
| 1314 | * @return array SQL の実行結果の配列 |
|---|
| 1315 | */ |
|---|
| 1316 | function query($n ,$arr = array(), $ignore_err = false){ |
|---|
| 1317 | |
|---|
| 1318 | $sth =& $this->prepare($n); |
|---|
| 1319 | if (PEAR::isError($sth) && $this->force_run) { |
|---|
| 1320 | return; |
|---|
| 1321 | } |
|---|
| 1322 | |
|---|
| 1323 | $result = $this->execute($sth, $arr); |
|---|
| 1324 | if (PEAR::isError($result) && $this->force_run) { |
|---|
| 1325 | return; |
|---|
| 1326 | } |
|---|
| 1327 | |
|---|
| 1328 | return $result; |
|---|
| 1329 | } |
|---|
| 1330 | |
|---|
| 1331 | /** |
|---|
| 1332 | * シーケンスの一覧を取得する. |
|---|
| 1333 | * |
|---|
| 1334 | * @return array シーケンス名の配列 |
|---|
| 1335 | */ |
|---|
| 1336 | function listSequences() { |
|---|
| 1337 | $this->conn->loadModule('Manager'); |
|---|
| 1338 | return $this->conn->listSequences(); |
|---|
| 1339 | } |
|---|
| 1340 | |
|---|
| 1341 | /** |
|---|
| 1342 | * テーブル一覧を取得する. |
|---|
| 1343 | * |
|---|
| 1344 | * @return array テーブル名の配列 |
|---|
| 1345 | */ |
|---|
| 1346 | function listTables() { |
|---|
| 1347 | $this->conn->loadModule('Manager'); |
|---|
| 1348 | return $this->conn->listTables(); |
|---|
| 1349 | } |
|---|
| 1350 | |
|---|
| 1351 | /** |
|---|
| 1352 | * テーブルのカラム一覧を取得する. |
|---|
| 1353 | * |
|---|
| 1354 | * @param string $table テーブル名 |
|---|
| 1355 | * @return array 指定のテーブルのカラム名の配列 |
|---|
| 1356 | */ |
|---|
| 1357 | function listTableFields($table) { |
|---|
| 1358 | $this->conn->loadModule('Manager'); |
|---|
| 1359 | return $this->conn->listTableFields($table); |
|---|
| 1360 | } |
|---|
| 1361 | |
|---|
| 1362 | /** |
|---|
| 1363 | * テーブルのインデックス一覧を取得する. |
|---|
| 1364 | * |
|---|
| 1365 | * @param string $table テーブル名 |
|---|
| 1366 | * @return array 指定のテーブルのインデックス一覧 |
|---|
| 1367 | */ |
|---|
| 1368 | function listTableIndexes($table) { |
|---|
| 1369 | $this->conn->loadModule('Manager'); |
|---|
| 1370 | return $this->conn->listTableIndexes($table); |
|---|
| 1371 | } |
|---|
| 1372 | |
|---|
| 1373 | /** |
|---|
| 1374 | * 値を適切にクォートする. |
|---|
| 1375 | * |
|---|
| 1376 | * TODO MDB2 に対応するための暫定的な措置. |
|---|
| 1377 | * ブレースホルダが使用できない実装があるため. |
|---|
| 1378 | * 本来であれば, MDB2::prepare() を適切に使用するべき |
|---|
| 1379 | * |
|---|
| 1380 | * @see MDB2::quote() |
|---|
| 1381 | * @param string $val クォートを行う文字列 |
|---|
| 1382 | * @return string クォートされた文字列 |
|---|
| 1383 | */ |
|---|
| 1384 | function quote($val) { |
|---|
| 1385 | return $this->conn->quote($val); |
|---|
| 1386 | } |
|---|
| 1387 | |
|---|
| 1388 | /** |
|---|
| 1389 | * プリペアドステートメントを構築する. |
|---|
| 1390 | * |
|---|
| 1391 | * @access private |
|---|
| 1392 | * @param string $sql プリペアドステートメントを構築する SQL |
|---|
| 1393 | * @return MDB2_Statement_Common プリペアドステートメントインスタンス |
|---|
| 1394 | */ |
|---|
| 1395 | function prepare($sql) { |
|---|
| 1396 | $sth =& $this->conn->prepare($sql); |
|---|
| 1397 | if (PEAR::isError($sth)) { |
|---|
| 1398 | if (!$this->force_run) { |
|---|
| 1399 | trigger_error($this->traceError($sth, $sql), E_USER_ERROR); |
|---|
| 1400 | } else { |
|---|
| 1401 | error_log($this->traceError($sth, $sql), 3, LOG_PATH); |
|---|
| 1402 | } |
|---|
| 1403 | } |
|---|
| 1404 | return $sth; |
|---|
| 1405 | } |
|---|
| 1406 | |
|---|
| 1407 | /** |
|---|
| 1408 | * プリペアドクエリを実行する. |
|---|
| 1409 | * |
|---|
| 1410 | * @access private |
|---|
| 1411 | * @param MDB2_Statement_Common プリペアドステートメントインスタンス |
|---|
| 1412 | * @param array $arrVal ブレースホルダに挿入する配列 |
|---|
| 1413 | * @return MDB2_Result 結果セットのインスタンス |
|---|
| 1414 | */ |
|---|
| 1415 | function execute(&$sth, $arrVal = array()) { |
|---|
| 1416 | $affected =& $sth->execute($arrVal); |
|---|
| 1417 | if (PEAR::isError($affected)) { |
|---|
| 1418 | if (!$this->force_run) { |
|---|
| 1419 | trigger_error($this->traceError($affected), E_USER_ERROR); |
|---|
| 1420 | } else { |
|---|
| 1421 | error_log($this->traceError($affected), 3, LOG_PATH); |
|---|
| 1422 | } |
|---|
| 1423 | } |
|---|
| 1424 | return $affected; |
|---|
| 1425 | } |
|---|
| 1426 | |
|---|
| 1427 | /** |
|---|
| 1428 | * エラーの内容をトレースする. |
|---|
| 1429 | * |
|---|
| 1430 | * @access private |
|---|
| 1431 | * @param PEAR::Error $error PEAR::Error インスタンス |
|---|
| 1432 | * @param string $sql エラーの発生した SQL 文 |
|---|
| 1433 | * @return string トレースしたエラー文字列 |
|---|
| 1434 | */ |
|---|
| 1435 | function traceError($error, $sql = "") { |
|---|
| 1436 | $scheme = ''; |
|---|
| 1437 | if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { |
|---|
| 1438 | $scheme = "http://"; |
|---|
| 1439 | } else { |
|---|
| 1440 | $scheme = "https://"; |
|---|
| 1441 | } |
|---|
| 1442 | |
|---|
| 1443 | $err = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n\n" |
|---|
| 1444 | . "SERVER_ADDR: " . $_SERVER['SERVER_ADDR'] . "\n" |
|---|
| 1445 | . "REMOTE_ADDR: " . $_SERVER['REMOTE_ADDR'] . "\n" |
|---|
| 1446 | . "USER_AGENT: " . $_SERVER['HTTP_USER_AGENT'] . "\n\n" |
|---|
| 1447 | . "SQL: " . $sql . "\n\n" |
|---|
| 1448 | . $error->getMessage() . "\n\n" |
|---|
| 1449 | . $error->getUserInfo() . "\n\n"; |
|---|
| 1450 | |
|---|
| 1451 | $rev = array_reverse($error->getBackTrace()); |
|---|
| 1452 | |
|---|
| 1453 | foreach($rev as $val) { |
|---|
| 1454 | if($val['class'] != "") { |
|---|
| 1455 | $detail = $val['class'] . "->" . $val['function']; |
|---|
| 1456 | } else { |
|---|
| 1457 | $detail = $val['function']; |
|---|
| 1458 | } |
|---|
| 1459 | $err .= $val['file'] . " " . $val['line'] . ":" . $detail . "\n"; |
|---|
| 1460 | } |
|---|
| 1461 | return $err; |
|---|
| 1462 | } |
|---|
| 1463 | } |
|---|
| 1464 | |
|---|
| 1465 | ?> |
|---|