Changeset 18773 for branches/version-2_5-dev/data/class/SC_Query.php
- Timestamp:
- 2010/08/03 20:13:05 (14 years ago)
- bzr:base-revision:
- ohkouchi@loop-az.jp-20100803084717-9sbbuk4o59x5sio4
- bzr:committer:
- Kentaro Ohkouchi <ohkouchi@loop-az.jp>
- bzr:file-ids:
data/class/SC_Query.php 15078@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2Fclass%2FSC_Query.php
data/class/pages/products/LC_Page_Products_List.php 15154@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2Fclass%2Fpages%2Fproducts%2FLC_Page_Products_List.php
data/include/module.inc 15078@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2Finclude%2Fmodule.inc
data/require_classes.php 18500@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Fversion-2_4-dev%2Fdata%2Frequire_classes.php
test/class/SC_Query_Test.php sc_query_test.php-20100803024127-ljzonih8f5jpan9o-1- bzr:mapping-version:
- v4
- bzr:repository-uuid:
- 1e3b908f-19a9-db11-a64c-001125224ba8
- bzr:revision-id:
- ohkouchi@loop-az.jp-20100803111301-u8ph4za35y4il0dh
- bzr:revno:
- 2256
- bzr:revprop:branch-nick:
- branches/version-2_5-dev
- bzr:root:
- branches/version-2_5-dev
- bzr:text-parents:
data/class/SC_Query.php ohkouchi@loop-az.jp-20100614082857-g3n9wn9zakpc7a0m
data/include/module.inc svn-v4:1e3b908f-19a9-db11-a64c-001125224ba8:branches/comu-ver2:17672
data/require_classes.php ohkouchi@loop-az.jp-20100623032937-dhwktuevjyk0jv13
test/class/SC_Query_Test.php ohkouchi@loop-az.jp-20100803024346-cpwzialqa7f40fo9- bzr:timestamp:
- 2010-08-03 20:13:01.371999979 +0900
- bzr:user-agent:
- bzr2.1.2+bzr-svn1.0.2
- svn:original-date:
- 2010-08-03T11:13:01.372000Z
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/class/SC_Query.php
r18701 r18773 22 22 */ 23 23 24 require_once(realpath(dirname(__FILE__)) . "/../module/MDB2.php"); 25 24 26 /** 25 27 * SQLの構築・実行を行う 28 * 29 * TODO エラーハンドリング, ロギング方法を見直す 26 30 * 27 31 * @author LOCKON CO.,LTD. … … 44 48 */ 45 49 function SC_Query($dsn = "", $err_disp = true, $new = false) { 46 $this->conn = new SC_DBconn($dsn, $err_disp, $new); 50 51 if ($dsn == "") { 52 $dsn = DEFAULT_DSN; 53 } 54 55 // Debugモード指定 56 $options['debug'] = PEAR_DB_DEBUG; 57 // 持続的接続オプション 58 $options['persistent'] = PEAR_DB_PERSISTENT; 59 60 if ($new) { 61 $this->conn = MDB2::connect($dsn, $options); 62 } else { 63 $this->conn = MDB2::singleton($dsn, $options); 64 } 65 66 $this->conn->setCharset(CHAR_CODE); 67 $this->conn->setFetchMode(MDB2_FETCHMODE_ASSOC); 68 $this->dbFactory = SC_DB_DBFactory_Ex::getInstance(); 47 69 $this->where = ""; 48 70 } … … 54 76 */ 55 77 function isError() { 56 if(PEAR::isError($this->conn ->conn)) {78 if(PEAR::isError($this->conn)) { 57 79 return true; 58 80 } … … 74 96 $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; 75 97 } 76 // カウント文の実行 77 $ret = $this->conn->getOne($sqlse, $arrval); 78 return $ret; 98 $sqlse = $this->dbFactory->sfChangeMySQL($sqlse); 99 return $this->getOne($sqlse, $arrval); 79 100 } 80 101 … … 89 110 * @return array|null 90 111 */ 91 function select($col, $table, $where = "", $arrval = array(), $fetchmode = DB_FETCHMODE_ASSOC) {112 function select($col, $table, $where = "", $arrval = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 92 113 $sqlse = $this->getSql($col, $table, $where); 93 $ret = $this->conn->getAll($sqlse, $arrval, $fetchmode); 94 return $ret; 114 return $this->getAll($sqlse, $arrval, $fetchmode); 95 115 } 96 116 97 117 /** 98 118 * 直前に実行されたSQL文を取得する. 99 * SC_DBconn::getLastQuery() を利用.100 119 * 101 120 * @param boolean $disp trueの場合、画面出力を行う. … … 103 122 */ 104 123 function getLastQuery($disp = true) { 105 return $this->conn->getLastQuery($disp); 124 $sql = $this->conn->last_query; 125 if($disp) { 126 print($sql.";<br />\n"); 127 } 128 return $sql; 106 129 } 107 130 108 131 function commit() { 109 $this->conn-> query("COMMIT");132 $this->conn->commit(); 110 133 } 111 134 112 135 function begin() { 113 $this->conn-> query("BEGIN");136 $this->conn->beginTransaction(); 114 137 } 115 138 116 139 function rollback() { 117 $this->conn-> query("ROLLBACK");140 $this->conn->rollback(); 118 141 } 119 142 120 143 function exec($str, $arrval = array()) { 121 $this->conn->query($str, $arrval); 144 // FIXME MDB2::exec() の実装であるべき 145 $this->query($str, $arrval); 122 146 } 123 147 … … 130 154 * @return array データを含む2次元配列。失敗した場合に 0 または DB_Error オブジェクトを返します。 131 155 */ 132 function getAll($sql, $arrval = array(), $fetchmode = DB_FETCHMODE_ASSOC) { 133 $ret = $this->conn->getAll($sql, $arrval, $fetchmode); 134 return $ret; 156 function getAll($sql, $arrval = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 157 158 $sql = $this->dbFactory->sfChangeMySQL($sql); 159 160 $sth = $this->conn->prepare($sql); 161 $affected = $sth->execute($arrval); 162 163 if (PEAR::isError($affected)) { 164 trigger_error($affected->getMessage(), E_USER_ERROR); 165 } 166 167 return $affected->fetchAll($fetchmode); 135 168 } 136 169 … … 154 187 } 155 188 189 // TODO MDB2::setLimit() を使用する 156 190 function setLimitOffset($limit, $offset = 0, $return = false) { 157 191 if (is_numeric($limit) && is_numeric($offset)){ … … 250 284 $sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")"; 251 285 // INSERT文の実行 252 $ret = $this-> conn->query($sqlin, $arrval);286 $ret = $this->query($sqlin, $arrval); 253 287 254 288 return $ret; … … 306 340 307 341 // UPDATE文の実行 308 return $this-> conn->query($sqlup, $arrVal);342 return $this->query($sqlup, $arrVal); 309 343 } 310 344 … … 330 364 331 365 function getOne($sql, $arrval = array()) { 332 // SQL文の実行 333 $ret = $this->conn->getOne($sql, $arrval); 334 return $ret; 366 367 $sql = $this->dbFactory->sfChangeMySQL($sql); 368 369 $sth = $this->conn->prepare($sql); 370 $affected = $sth->execute($arrval); 371 372 if (PEAR::isError($affected)) { 373 trigger_error($affected->getMessage(), E_USER_ERROR); 374 } 375 376 return $affected->fetchOne(); 335 377 } 336 378 … … 345 387 * @return array array('カラム名' => '値', ...)の連想配列 346 388 */ 347 function getRow($table, $col, $where = "", $arrVal = array(), $fetchmode = DB_FETCHMODE_ASSOC) { 348 $sqlse = $this->getSql($col, $table, $where); 349 // SQL文の実行 350 return $this->conn->getRow($sqlse, $arrVal ,$fetchmode); 389 function getRow($table, $col, $where = "", $arrVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 390 391 $sql = $this->getSql($col, $table, $where); 392 $sql = $this->dbFactory->sfChangeMySQL($sql); 393 394 $sth = $this->conn->prepare($sql); 395 $affected = $sth->execute($arrVal); 396 397 if (PEAR::isError($affected)) { 398 trigger_error($affected->getMessage(), E_USER_ERROR); 399 } 400 401 return $affected->fetchRow($fetchmode); 351 402 } 352 403 353 404 // 1列取得 354 405 function getCol($table, $col, $where = "", $arrval = array()) { 355 $sqlse = $this->getSql($col, $table, $where); 356 // SQL文の実行 357 return $this->conn->getCol($sqlse, 0, $arrval); 406 $sql = $this->getSql($col, $table, $where); 407 $sql = $this->dbFactory->sfChangeMySQL($sql); 408 409 $sth = $this->conn->prepare($sql); 410 $affected = $sth->execute($arrval); 411 412 if (PEAR::isError($affected)) { 413 trigger_error($affected->getMessage(), E_USER_ERROR); 414 } 415 416 return $affected->fetchCol($col); 358 417 } 359 418 … … 372 431 $sqlde = "DELETE FROM $table WHERE $where"; 373 432 } 374 $ret = $this-> conn->query($sqlde, $arrval);433 $ret = $this->query($sqlde, $arrval); 375 434 return $ret; 376 435 } … … 385 444 $sql = "SELECT last_insert_id();"; 386 445 } 387 $ret = $this-> conn->getOne($sql);446 $ret = $this->getOne($sql); 388 447 389 448 return $ret; … … 398 457 $sql = "SELECT last_insert_id();"; 399 458 } 400 $ret = $this-> conn->getOne($sql);459 $ret = $this->getOne($sql); 401 460 402 461 return $ret; … … 408 467 $seqtable = $table . "_" . $colname . "_seq"; 409 468 $sql = "SELECT SETVAL('$seqtable', $data)"; 410 $ret = $this-> conn->getOne($sql);469 $ret = $this->getOne($sql); 411 470 }else if (DB_TYPE == "mysql") { 412 471 $sql = "ALTER TABLE $table AUTO_INCREMENT=$data"; 413 $ret = $this->conn->query($sql); 414 } 415 416 return $ret; 417 } 418 419 function query($n ,$arr = "", $ignore_err = false){ 420 $result = $this->conn->query($n, $arr, $ignore_err); 472 $ret = $this->query($sql); 473 } 474 475 return $ret; 476 } 477 478 // XXX 更新系には exec() を使用するべき 479 function query($n ,$arr = array(), $ignore_err = false){ 480 481 $n = $this->dbFactory->sfChangeMySQL($n); 482 483 $sth = $this->conn->prepare($n); 484 $result = $sth->execute($arr); 485 486 if (PEAR::isError($result)) { 487 trigger_error($result->getMessage(), E_USER_ERROR); 488 } 489 421 490 return $result; 422 491 } … … 437 506 438 507 // 値をカウントアップしておく 439 $this-> conn->query("ALTER TABLE $table_name AUTO_INCREMENT=?" , $auto_inc_no + 1);508 $this->query("ALTER TABLE $table_name AUTO_INCREMENT=?" , $auto_inc_no + 1); 440 509 441 510 // 解除する
Note: See TracChangeset
for help on using the changeset viewer.