Changeset 18590 for branches/comu-ver2
- Timestamp:
- 2010/03/02 16:12:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/comu-ver2/data/class/SC_Query.php
r18487 r18590 122 122 } 123 123 124 function autoselect($col, $table, $arrwhere = array(), $arrcon = array()) {125 $strw = "";126 $find = false;127 foreach ($arrwhere as $key => $val) {128 if(strlen($val) > 0) {129 if(strlen($strw) <= 0) {130 $strw .= $key ." LIKE ?";131 } else if(strlen($arrcon[$key]) > 0) {132 $strw .= " ". $arrcon[$key]. " " . $key ." LIKE ?";133 } else {134 $strw .= " AND " . $key ." LIKE ?";135 }136 137 $arrval[] = $val;138 }139 }140 141 if(strlen($strw) > 0) {142 $sqlse = "SELECT $col FROM $table WHERE $strw ".$this->option;143 } else {144 $sqlse = "SELECT $col FROM $table ".$this->option;145 }146 $ret = $this->conn->getAll($sqlse, $arrval);147 return $ret;148 }149 150 124 /** 151 125 * クエリを実行し、全ての行を返す … … 161 135 } 162 136 163 function getsql($col, $table, $where) { 164 if($where != "") { 165 // 引数の$whereを優先して実行する。 166 $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option; 167 } else { 168 if($this->where != "") { 169 $sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option; 170 } else { 171 $sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option; 172 } 173 } 137 function getsql($col, $table, $where = '') { 138 $sqlse = "SELECT $col FROM $table"; 139 140 // 引数の$whereを優先する。 141 if (strlen($where) >= 1) { 142 $sqlse .= " WHERE $where"; 143 } elseif (strlen($this->where) >= 1) { 144 $where = $this->where; 145 } 146 147 $sqlse .= ' ' . $this->groupby . ' ' . $this->order . ' ' . $this->option; 148 174 149 return $sqlse; 175 150 } … … 336 311 // MAX文の実行 337 312 function max($table, $col, $where = "", $arrval = array()) { 338 if(strlen($where) <= 0) { 339 $sqlse = "SELECT MAX($col) FROM $table"; 340 } else { 341 $sqlse = "SELECT MAX($col) FROM $table WHERE $where"; 342 } 343 // MAX文の実行 344 $ret = $this->conn->getOne($sqlse, $arrval); 313 $ret = $this->get($table, "MAX($col)", $where); 345 314 return $ret; 346 315 } … … 348 317 // MIN文の実行 349 318 function min($table, $col, $where = "", $arrval = array()) { 350 if(strlen($where) <= 0) { 351 $sqlse = "SELECT MIN($col) FROM $table"; 352 } else { 353 $sqlse = "SELECT MIN($col) FROM $table WHERE $where"; 354 } 355 // MIN文の実行 356 $ret = $this->conn->getOne($sqlse, $arrval); 319 $ret = $this->get($table, "MIN($col)", $where); 357 320 return $ret; 358 321 } … … 360 323 // 特定のカラムの値を取得 361 324 function get($table, $col, $where = "", $arrval = array()) { 362 if(strlen($where) <= 0) { 363 $sqlse = "SELECT $col FROM $table"; 364 } else { 365 $sqlse = "SELECT $col FROM $table WHERE $where"; 366 } 325 $sqlse = $this->getsql($col, $table, $where); 367 326 // SQL文の実行 368 $ret = $this-> conn->getOne($sqlse, $arrval);327 $ret = $this->getone($sqlse, $arrval); 369 328 return $ret; 370 329 } … … 374 333 $ret = $this->conn->getOne($sql, $arrval); 375 334 return $ret; 376 377 335 } 378 336 … … 388 346 */ 389 347 function getRow($table, $col, $where = "", $arrVal = array(), $fetchmode = DB_FETCHMODE_ASSOC) { 390 $sqlse = "SELECT $col FROM $table"; 391 392 if (strlen($where) >= 1) { 393 $sqlse .= " WHERE $where"; 394 } 348 $sqlse = $this->getsql($col, $table, $where); 395 349 // SQL文の実行 396 350 return $this->conn->getRow($sqlse, $arrVal ,$fetchmode); … … 399 353 // 1列取得 400 354 function getCol($table, $col, $where = "", $arrval = array()) { 401 if (strlen($where) <= 0) { 402 $sqlse = "SELECT $col FROM $table"; 403 } else { 404 $sqlse = "SELECT $col FROM $table WHERE $where"; 405 } 355 $sqlse = $this->getsql($col, $table, $where); 406 356 // SQL文の実行 407 357 return $this->conn->getCol($sqlse, 0, $arrval);
Note: See TracChangeset
for help on using the changeset viewer.