Changeset 21446 for branches/version-2_12-dev/data/class/SC_SelectSql.php
- Timestamp:
- 2012/02/06 21:38:41 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/SC_SelectSql.php
r21445 r21446 44 44 45 45 //-- SQL分生成 46 function getSql( 46 function getSql($mode = ""){ 47 47 $this->sql = $this->select ." ". $this->where ." ". $this->group ." "; 48 48 … … 68 68 // ある単位のみ検索($from = $to) 69 69 if ($from == $to) { 70 $this->setWhere( 70 $this->setWhere($column ." = ?"); 71 71 $return = array($from); 72 72 // ~$toまで検索 73 73 } elseif (strlen($from) == 0 && strlen($to) > 0) { 74 $this->setWhere( 74 $this->setWhere($column ." <= ? "); 75 75 $return = array($to); 76 76 // ~$from以上を検索 77 77 } elseif (strlen($from) > 0 && strlen($to) == 0) { 78 $this->setWhere( 78 $this->setWhere($column ." >= ? "); 79 79 $return = array($from); 80 80 // $from~$toの検索 81 81 } else { 82 $this->setWhere( 82 $this->setWhere($column ." BETWEEN ? AND ?"); 83 83 $return = array($from, $to); 84 84 } … … 102 102 103 103 // 開始期間だけ指定の場合 104 if (( $from_year != "") && ( $from_month != "") && ( $from_day != "") && ( $to_year == "") && ( $to_month == "") && ($to_day == "")) {105 $this->setWhere( 104 if (($from_year != "") && ($from_month != "") && ($from_day != "") && ($to_year == "") && ($to_month == "") && ($to_day == "")) { 105 $this->setWhere($column .' >= ?'); 106 106 $return[] = $date1; 107 107 } 108 108 109 109 // 開始~終了 110 if( ( $from_year != "") && ( $from_month != "") && ($from_day != "") &&111 ( $to_year != "") && ( $to_month != "") && ($to_day != "")) {112 $this->setWhere( 110 if( ($from_year != "") && ($from_month != "") && ($from_day != "") && 111 ($to_year != "") && ($to_month != "") && ($to_day != "")) { 112 $this->setWhere($column . ' >= ? AND ' . $column . ' < date(?)'); 113 113 $return[] = $date1; 114 114 $return[] = $date2; … … 116 116 117 117 // 終了期間だけ指定の場合 118 if (( $from_year == "") && ( $from_month == "") && ( $from_day == "") && ( $to_year != "") && ( $to_month != "") && ($to_day != "")) {119 $this->setWhere( 118 if (($from_year == "") && ($from_month == "") && ($from_day == "") && ($to_year != "") && ($to_month != "") && ($to_day != "")) { 119 $this->setWhere($column . ' < date(?)'); 120 120 $return[] = $date2; 121 121 } … … 125 125 126 126 // checkboxなどで同一カラム内で単一、もしくは複数選択肢が有る場合 例: AND ( sex = xxx OR sex = xxx OR sex = xxx) AND ... 127 function setItemTerm( 127 function setItemTerm($arr, $ItemStr) { 128 128 129 129 foreach ($arr as $data) { 130 130 131 if (count( 132 if( ! is_null($data)) $item .= $ItemStr . " = ? OR ";131 if (count($arr) > 1) { 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 ") . ")";140 $this->setWhere( 139 if( count($arr) > 1) $item = "(" . rtrim($item, " OR ") . ")"; 140 $this->setWhere($item); 141 141 return $return; 142 142 } 143 143 144 144 // NULL値が必要な場合 145 function setItemTermWithNull( 145 function setItemTermWithNull($arr, $ItemStr) { 146 146 147 147 $item = " ${ItemStr} IS NULL "; … … 156 156 } 157 157 158 $item = "( 159 $this->setWhere( 158 $item = "(${item}) "; 159 $this->setWhere($item); 160 160 return $return; 161 161 } 162 162 // NULLもしくは''で検索する場合 163 function setItemTermWithNullAndSpace( 163 function setItemTermWithNullAndSpace($arr, $ItemStr) { 164 164 $count = count($arr); 165 165 $item = " ${ItemStr} IS NULL OR ${ItemStr} = '' "; … … 173 173 } 174 174 } 175 $item = "( 176 $this->setWhere( 175 $item = "(${item}) "; 176 $this->setWhere($item); 177 177 return $return; 178 178 } … … 181 181 182 182 配列の構造例 183 if ( $_POST['show_site1']) $arrShowsite_1 = array('column' => "show_site1",183 if ($_POST['show_site1']) $arrShowsite_1 = array('column' => "show_site1", 184 184 'value' => $_POST['show_site1']); 185 185 186 186 */ 187 function setWhereByOR( 188 189 $count = count( 187 function setWhereByOR($arrWhere){ 188 189 $count = count($arrWhere); 190 190 191 191 for ($i = 0; $i < $count; $i++) { 192 192 193 if( isset( 194 } 195 196 $statement = "( " . rtrim($statement, " OR ") . ")";193 if( isset($arrWhere[$i]['value'])) $statement .= $arrWhere[$i]['column'] ." = " . SC_Utils_Ex::sfQuoteSmart($arrWhere[$i]['value']) ." OR " ; 194 } 195 196 $statement = "(" . rtrim($statement, " OR ") . ")"; 197 197 198 198 if ($this->where) { … … 225 225 } 226 226 227 function setGroup( 227 function setGroup($group) { 228 228 229 229 $this->group = "GROUP BY " . $group; … … 231 231 } 232 232 233 function setLimitOffset( 233 function setLimitOffset($limit, $offset){ 234 234 235 235 if (is_numeric($limit) and is_numeric($offset)) {
Note: See TracChangeset
for help on using the changeset viewer.