Changeset 21514 for branches/version-2_12-dev/data/class/SC_SelectSql.php
- Timestamp:
- 2012/02/15 19:56:17 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/SC_SelectSql.php
r21481 r21514 37 37 38 38 //-- コンストラクタ。 39 function SC_SelectSql($array = "") {39 function SC_SelectSql($array = '') { 40 40 if (is_array($array)) { 41 41 $this->arrSql = $array; … … 44 44 45 45 //-- SQL分生成 46 function getSql($mode = "") {47 $this->sql = $this->select . " ". $this->where ." ". $this->group ." ";46 function getSql($mode = '') { 47 $this->sql = $this->select .' '. $this->where .' '. $this->group ." "; 48 48 49 49 // $mode == 1 は limit & offset無し … … 51 51 $this->sql .= $this->order; 52 52 } elseif ($mode != 1) { 53 $this->sql .= $this->order . " " .$this->limit ." ". $this->offset;53 $this->sql .= $this->order . ' ' .$this->limit .' '. $this->offset; 54 54 } 55 55 … … 59 59 // 検索用 60 60 function addSearchStr($val) { 61 $return = "%" .$val. "%";61 $return = '%' .$val. '%'; 62 62 return $return; 63 63 } … … 68 68 // ある単位のみ検索($from = $to) 69 69 if ($from == $to) { 70 $this->setWhere($column . " = ?");70 $this->setWhere($column .' = ?'); 71 71 $return = array($from); 72 72 // ~$toまで検索 73 73 } elseif (strlen($from) == 0 && strlen($to) > 0) { 74 $this->setWhere($column . " <= ? ");74 $this->setWhere($column .' <= ? '); 75 75 $return = array($to); 76 76 // ~$from以上を検索 77 77 } elseif (strlen($from) > 0 && strlen($to) == 0) { 78 $this->setWhere($column . " >= ? ");78 $this->setWhere($column .' >= ? '); 79 79 $return = array($from); 80 80 // $from~$toの検索 81 81 } else { 82 $this->setWhere($column . " BETWEEN ? AND ?");82 $this->setWhere($column .' BETWEEN ? AND ?'); 83 83 $return = array($from, $to); 84 84 } … … 91 91 92 92 // 開始期間の構築 93 $date1 = $from_year . "/" . $from_month . "/". $from_day;93 $date1 = $from_year . '/' . $from_month . '/' . $from_day; 94 94 95 95 // 終了期間の構築 … … 102 102 103 103 // 開始期間だけ指定の場合 104 if (($from_year != "") && ($from_month != "") && ($from_day != "") && ($to_year == "") && ($to_month == "") && ($to_day == "")) {104 if (($from_year != '') && ($from_month != '') && ($from_day != "") && ($to_year == "") && ($to_month == "") && ($to_day == "")) { 105 105 $this->setWhere($column .' >= ?'); 106 106 $return[] = $date1; … … 108 108 109 109 // 開始~終了 110 if( ($from_year != "") && ($from_month != "") && ($from_day != "") &&111 ($to_year != "") && ($to_month != "") && ($to_day != "")) {110 if( ($from_year != '') && ($from_month != '') && ($from_day != "") && 111 ($to_year != '') && ($to_month != '') && ($to_day != "")) { 112 112 $this->setWhere($column . ' >= ? AND ' . $column . ' < date(?)'); 113 113 $return[] = $date1; … … 116 116 117 117 // 終了期間だけ指定の場合 118 if (($from_year == "") && ($from_month == "") && ($from_day == "") && ($to_year != "") && ($to_month != "") && ($to_day != "")) {118 if (($from_year == '') && ($from_month == '') && ($from_day == "") && ($to_year != "") && ($to_month != "") && ($to_day != "")) { 119 119 $this->setWhere($column . ' < date(?)'); 120 120 $return[] = $date2; … … 130 130 131 131 if (count($arr) > 1) { 132 if(! is_null($data)) $item .= $ItemStr . " = ? OR ";132 if(! is_null($data)) $item .= $ItemStr . ' = ? OR '; 133 133 } else { 134 if(! is_null($data)) $item = $ItemStr . " = ?";134 if(! is_null($data)) $item = $ItemStr . ' = ?'; 135 135 } 136 136 $return[] = $data; 137 137 } 138 138 139 if( count($arr) > 1) $item = "(" . rtrim($item, " OR ") . ")";139 if( count($arr) > 1) $item = '(' . rtrim($item, ' OR ') . ")"; 140 140 $this->setWhere($item); 141 141 return $return; … … 149 149 if ($arr) { 150 150 foreach ($arr as $data) { 151 if ($data != "不明") {151 if ($data != '不明') { 152 152 $item .= " OR ${ItemStr} = ?"; 153 153 $return[] = $data; … … 194 194 } 195 195 196 $statement = "(" . rtrim($statement, " OR ") . ")";196 $statement = '(' . rtrim($statement, ' OR ') . ")"; 197 197 198 198 if ($this->where) { 199 199 200 $this->where .= " AND ". $statement;200 $this->where .= ' AND ' . $statement; 201 201 202 202 } else { 203 203 204 $this->where = "WHERE ". $statement;204 $this->where = 'WHERE ' . $statement; 205 205 } 206 206 } 207 207 208 208 function setWhere($where) { 209 if ($where != "") {209 if ($where != '') { 210 210 if ($this->where) { 211 211 212 $this->where .= " AND ". $where;212 $this->where .= ' AND ' . $where; 213 213 214 214 } else { 215 215 216 $this->where = "WHERE ". $where;216 $this->where = 'WHERE ' . $where; 217 217 } 218 218 } … … 221 221 function setOrder($order) { 222 222 223 $this->order = "ORDER BY ". $order;223 $this->order = 'ORDER BY ' . $order; 224 224 225 225 } … … 227 227 function setGroup($group) { 228 228 229 $this->group = "GROUP BY ". $group;229 $this->group = 'GROUP BY ' . $group; 230 230 231 231 } … … 235 235 if (is_numeric($limit) and is_numeric($offset)) { 236 236 237 $this->limit = " LIMIT ".$limit;238 $this->offset = " OFFSET ".$offset;237 $this->limit = ' LIMIT ' .$limit; 238 $this->offset = ' OFFSET ' .$offset; 239 239 } 240 240 } 241 241 242 242 function clearSql() { 243 $this->select = "";244 $this->where = "";245 $this->group = "";246 $this->order = "";247 $this->limit = "";248 $this->offset = "";243 $this->select = ''; 244 $this->where = ''; 245 $this->group = ''; 246 $this->order = ''; 247 $this->limit = ''; 248 $this->offset = ''; 249 249 } 250 250
Note: See TracChangeset
for help on using the changeset viewer.