Changeset 14676 for branches/beta/data/class/SC_Query.php
- Timestamp:
- 2007/06/14 22:01:13 (19 years ago)
- File:
-
- 1 edited
-
branches/beta/data/class/SC_Query.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/beta/data/class/SC_Query.php
r337 r14676 1 1 <?php 2 /* 2 /** 3 3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. 4 4 * … … 6 6 */ 7 7 8 /** 9 * SC_Query¥¯¥é¥¹ 10 * 11 * @author LOCKON CO.,LTD. 12 * @access public 13 */ 8 14 class SC_Query { 9 var $option; 10 var $where; 11 var $conn; 12 var $groupby; 13 var $order; 14 15 // ¥³¥ó¥¹¥È¥é¥¯¥¿ 16 /* 17 $err_disp:¥¨¥é¡¼É½¼¨¤ò¹Ô¤¦¤« 18 $new¡§¿·µ¬¤ËÀܳ¤ò¹Ô¤¦¤« 19 */ 20 function SC_Query($dsn = "", $err_disp = true, $new = false) { 21 $this->conn = new SC_DBconn($dsn, $err_disp, $new); 22 $this->where = ""; 23 return $this->conn; 24 } 25 26 // ¥¨¥é¡¼È½Äê 27 function isError() { 28 if(PEAR::isError($this->conn->conn)) { 29 return true; 30 } 31 return false; 32 } 33 34 // COUNTʸ¤Î¼Â¹Ô 35 function count($table, $where = "", $arrval = array()) { 36 if(strlen($where) <= 0) { 37 $sqlse = "SELECT COUNT(*) FROM $table"; 38 } else { 39 $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; 40 } 41 // ¥«¥¦¥ó¥Èʸ¤Î¼Â¹Ô 42 $ret = $this->conn->getOne($sqlse, $arrval); 43 return $ret; 44 } 45 46 function select($col, $table, $where = "", $arrval = array()){ 47 $sqlse = $this->getsql($col, $table, $where); 48 $ret = $this->conn->getAll($sqlse, $arrval); 49 return $ret; 50 } 51 52 function getLastQuery($disp = true) { 53 $sql = $this->conn->conn->last_query; 54 if($disp) { 55 print($sql.";<br />\n"); 56 } 57 return $sql; 58 } 15 /**#@+ 16 * @access private 17 */ 18 19 /** 20 * SC_DBConn¥ª¥Ö¥¸¥§¥¯¥È 21 * @var SC_DBConn 22 */ 23 var $conn; 24 25 /** 26 * LIMIT,OFFSET ¶ç 27 * @var string 28 */ 29 var $option; 30 31 /** 32 * WHERE ¶ç 33 * @var string 34 */ 35 var $where; 36 37 /** 38 * GROUP BY ¶ç 39 * @var string 40 */ 41 var $groupby; 42 43 /** 44 * ORDER BY ¶ç 45 * @var string 46 */ 47 var $order; 48 49 /**#@-*/ 50 51 /** 52 * SC_Query¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿ 53 * 54 * @access public 55 * @param string $dsn DSN¾ðÊó 56 * @param boolean $err_disp ¥¨¥é¡¼É½¼¨¤ò¹Ô¤¦¤«¤É¤¦¤« 57 * @param boolean $new ¿·µ¬¤ËDBÀܳ¤ò¹Ô¤¦¤«¤É¤¦¤« 58 */ 59 function SC_Query($dsn = "", $err_disp = true, $new = false) { 60 $this->conn = new SC_DBconn($dsn, $err_disp, $new); 61 $this->where = ""; 62 $this->option = ""; 63 $this->groupby = ""; 64 return $this->conn; //? 65 } 66 67 /** 68 * DB¥¨¥é¡¼¤ÎȽÄê 69 * 70 * @access public 71 * @return boolean À®¸ù»þ¡§true ¼ºÇÔ»þ¡§false 72 */ 73 function isError() { 74 if(PEAR::isError($this->conn->conn)) { 75 return true; 76 } 77 return false; 78 } 79 80 /** 81 * ¥ª¥×¥·¥ç¥ó¤Î½é´ü²½ 82 * 83 * @access public 84 * @return void 85 */ 86 function clear(){ 87 $arrProperty = array_keys((get_object_vars($this))); 88 foreach ( $arrProperty as $property ) { 89 if ($property != 'conn') { 90 $this->$property = ''; 91 } 92 } 93 } 94 95 /** 96 * COUNTʸ¤Î¼Â¹Ô 97 * 98 * @access public 99 * @param string $table ¥Æ¡¼¥Ö¥ë̾ 100 * @param string $where WHERE¶ç 101 * @param array $arrval ¥×¥ì¡¼¥¹¥Û¥ë¥À¤ÎÇÛÎó 102 * @return string ¥ì¥³¡¼¥É·ï¿ô 103 */ 104 function count($table, $where = "", $arrval = array()) { 105 if(strlen($where) <= 0) { 106 $sqlse = "SELECT COUNT(*) FROM $table"; 107 } else { 108 $sqlse = "SELECT COUNT(*) FROM $table WHERE $where"; 109 } 110 // ¥«¥¦¥ó¥Èʸ¤Î¼Â¹Ô 111 $ret = $this->conn->getOne($sqlse, $arrval); 112 return $ret; 113 } 114 115 /** 116 * SELECTʸ¤Î¼Â¹Ô 117 * 118 * @access public 119 * @param string $col ¥«¥é¥à̾ 120 * @param string $table ¥Æ¡¼¥Ö¥ë̾ 121 * @param string $where WHERE¶ç 122 * @param array $arrval ¥×¥ì¡¼¥¹¥Û¥ë¥À¤ÎÇÛÎó 123 * @return array SELECTʸ¤Î¼Â¹Ô·ë²Ì 124 */ 125 function select($col, $table, $where = "", $arrval = array()){ 126 $sqlse = $this->getsql($col, $table, $where); 127 $ret = $this->conn->getAll($sqlse, $arrval); 128 return $ret; 129 } 130 131 /** 132 * ºÇ¸å¤Ë¼Â¹Ô¤·¤¿SQLʸ¤ò¼èÆÀ¤¹¤ë 133 * 134 * @access public 135 * @param boolean $disp SQLʸ¤òprint¤¹¤ë¤«¤É¤¦¤« 136 * @return string $disp==false¤Î¾ì¹ç¡§ºÇ¸å¤Ë¼Â¹Ô¤·¤¿SQLʸ¡¡$disp==true¤Î¾ì¹ç¡§¤Ê¤· 137 */ 138 function getLastQuery($disp = true) { 139 $sql = $this->conn->conn->last_query; 140 if($disp) { 141 print($sql.";<br />\n"); 142 } 143 return $sql; 144 } 59 145 60 146 function commit() { … … 105 191 } 106 192 107 function getsql($col, $table, $where) { 108 if($where != "") { 109 // °ú¿ô¤Î$where¤òÍ¥À褷¤Æ¼Â¹Ô¤¹¤ë¡£ 110 $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option; 111 } else { 112 if($this->where != "") { 113 $sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option; 114 } else { 115 $sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option; 116 } 117 } 118 return $sqlse; 119 } 120 121 function setoption($str) { 122 $this->option = $str; 123 } 124 125 function setlimitoffset($limit, $offset = 0, $return = false) { 126 if (is_numeric($limit) && is_numeric($offset)){ 127 128 $option.= " LIMIT " . $limit; 129 $option.= " OFFSET " . $offset; 130 131 if($return){ 132 return $option; 133 }else{ 134 $this->option.= $option; 135 } 136 } 137 } 138 139 function setgroupby($str) { 140 $this->groupby = "GROUP BY " . $str; 141 } 142 143 function andwhere($str) { 144 if($this->where != "") { 145 $this->where .= " AND " . $str; 146 } else { 147 $this->where = $str; 148 } 149 } 150 151 function orwhere($str) { 152 if($this->where != "") { 153 $this->where .= " OR " . $str; 154 } else { 155 $this->where = $str; 156 } 157 } 158 159 function setwhere($str) { 160 $this->where = $str; 161 } 162 163 function setorder($str) { 164 $this->order = "ORDER BY " . $str; 165 } 166 167 168 function setlimit($limit){ 169 if ( is_numeric($limit)){ 170 $this->option = " LIMIT " .$limit; 171 } 172 } 173 174 function setoffset($offset) { 175 if ( is_numeric($offset)){ 176 $this->offset = " OFFSET " .$offset; 177 } 178 } 179 180 181 // INSERTʸ¤ÎÀ¸À®¡¦¼Â¹Ô 182 // $table :¥Æ¡¼¥Ö¥ë̾ 183 // $sqlval :Îó̾ => ÃͤγÊǼ¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó 193 /** 194 * SELECTʸ¤ò¹½ÃÛ¤¹¤ë 195 * 196 * @access public 197 * @param string $col ¥«¥é¥à̾ 198 * @param string $table ¥Æ¡¼¥Ö¥ë̾ 199 * @param string $where WHERE¶ç 200 * @return string SQLʸ 201 */ 202 function getsql($col, $table, $where="") { 203 if($where != "") { 204 // °ú¿ô¤Î$where¤òÍ¥À褷¤Æ¼Â¹Ô¤¹¤ë¡£ 205 $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option; 206 } else { 207 if($this->where != "") { 208 $sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option; 209 } else { 210 $sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option; 211 } 212 } 213 return $sqlse; 214 } 215 216 /** 217 * WHERE,GROUPBY,ORDERBY°Ê³°¤Î¥ª¥×¥·¥ç¥Ê¥ë¤Ê¶ç¤ò¥»¥Ã¥È¤¹¤ë 218 * 219 * @access public 220 * @param string $str ¥ª¥×¥·¥ç¥ó¤Ë»ÈÍѤ¹¤ëʸ»úÎó 221 */ 222 function setoption($str) { 223 $this->option = $str; 224 } 225 226 /** 227 * LIMIT¶ç¡¢OFFSET¶ç¤ò¥»¥Ã¥È¤¹¤ë 228 * 229 * @access public 230 * @param mixed $limit LIMIT¤Î·ï¿ô 231 * @param mixed $offset OFFSET¤Î·ï¿ô 232 * @param string $return À¸À®¤·¤¿LIMIT,OFFSET¶ç¤òreturn¤¹¤ë¤«¤É¤¦¤« 233 * @return string À¸À®¤·¤¿LIMIT,OFFSET¶ç 234 */ 235 function setlimitoffset($limit, $offset = 0, $return = false) { 236 if (is_numeric($limit) && is_numeric($offset)){ 237 238 $option.= " LIMIT " . $limit; 239 $option.= " OFFSET " . $offset; 240 241 if($return){ 242 return $option; 243 }else{ 244 $this->option.= $option; 245 } 246 } 247 } 248 249 /** 250 * GROUP BY ¶ç¤ò¥»¥Ã¥È¤¹¤ë 251 * 252 * @access public 253 * @param string $str ¥«¥é¥à̾ 254 */ 255 function setgroupby($str) { 256 $this->groupby = "GROUP BY " . $str; 257 } 258 259 /** 260 * WHERE ¶ç¤ò¥»¥Ã¥È¤¹¤ë(AND) 261 * 262 * @access public 263 * @param string $str WHERE ¶ç 264 * @example $objQuery->andWhere('product_id = ?'); 265 */ 266 function andwhere($str) { 267 if($this->where != "") { 268 $this->where .= " AND " . $str; 269 } else { 270 $this->where = $str; 271 } 272 } 273 274 /** 275 * WHERE ¶ç¤ò¥»¥Ã¥È¤¹¤ë(OR) 276 * 277 * @access public 278 * @param string $str WHERE ¶ç 279 * @example $objQuery->orWhere('product_id = ?'); 280 */ 281 function orwhere($str) { 282 if($this->where != "") { 283 $this->where .= " OR " . $str; 284 } else { 285 $this->where = $str; 286 } 287 } 288 289 /** 290 * WHERE ¶ç¤ò¥»¥Ã¥È¤¹¤ë 291 * 292 * @access public 293 * @param string $str WHERE ¶ç 294 * @example $objQuery->setWhere('product_id = ?'); 295 */ 296 function setwhere($str) { 297 $this->where = $str; 298 } 299 300 /** 301 * ORDER BY ¶ç¤ò¥»¥Ã¥È¤¹¤ë 302 * 303 * @access public 304 * @param string $str ¥«¥é¥à̾ 305 * @example $objQuery->setorder("rank DESC"); 306 */ 307 function setorder($str) { 308 $this->order = "ORDER BY " . $str; 309 } 310 311 /** 312 * LIMIT ¶ç¤ò¥»¥Ã¥È¤¹¤ë 313 * 314 * @access public 315 * @param mixed $limit LIMIT¤Î·ï¿ô 316 * @example $objQuery->setlimit(50); 317 */ 318 function setlimit($limit){ 319 if ( is_numeric($limit)){ 320 $this->option = " LIMIT " .$limit; 321 } 322 } 323 324 /** 325 * OFFSET ¶ç¤ò¥»¥Ã¥È¤¹¤ë 326 * 327 * @access public 328 * @param mixed $offset OFFSET¤Î·ï¿ô 329 * @example $objQuery->setOffset(30); 330 */ 331 function setoffset($offset) { 332 if ( is_numeric($offset)){ 333 $this->offset = " OFFSET " .$offset; 334 } 335 } 336 337 /** 338 * INSERTʸ¤ò¼Â¹Ô¤¹¤ë 339 * 340 * @access public 341 * @param string $table ¥Æ¡¼¥Ö¥ë̾ 342 * @param array $sqlval (¥«¥é¥à̾ => ÃÍ)¤ÎÏ¢ÁÛÇÛÎó 343 * 344 * @return mixed $result DB_Error¥ª¥Ö¥¸¥§¥¯¥È(¼ºÇÔ»þ)¤Þ¤¿¤ÏDB_OK(À®¸ù»þ)¤Þ¤¿¤Ïfalse(¥«¥é¥à¤¬¸«¤Ä¤«¤é¤Ê¤¤) 345 */ 184 346 function insert($table, $sqlval) { 185 347 $strcol = ''; … … 218 380 } 219 381 220 // INSERTʸ¤ÎÀ¸À®¡¦¼Â¹Ô 221 // $table :¥Æ¡¼¥Ö¥ë̾ 222 // $sqlval :Îó̾ => ÃͤγÊǼ¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó 382 /** 383 * INSERTʸ¤ò¼Â¹Ô¤¹¤ë 384 * 385 * @access public 386 * @param string $table ¥Æ¡¼¥Ö¥ë̾ 387 * @param array $sqlval (¥«¥é¥à̾ => ÃÍ)¤ÎÏ¢ÁÛÇÛÎó 388 * 389 * @return mixed $result DB_Error¥ª¥Ö¥¸¥§¥¯¥È(¼ºÇÔ»þ)¤Þ¤¿¤ÏDB_OK(À®¸ù»þ)¤Þ¤¿¤Ïfalse(¥«¥é¥à¤¬¸«¤Ä¤«¤é¤Ê¤¤) 390 */ 223 391 function fast_insert($table, $sqlval) { 224 392 $strcol = ''; … … 248 416 $ret = $this->conn->query($sqlin); 249 417 250 return $ret; 418 return $ret; 251 419 } 252 420 … … 373 541 } 374 542 543 //»ØÄꤷ¤¿¥«¥é¥à¤Î°ìÈֺǸå¤Ë¥ì¥³¡¼¥É¤òÁÞÆþ 375 544 function nextval($table, $colname) { 376 545 $sql = ""; … … 379 548 $seqtable = $table . "_" . $colname . "_seq"; 380 549 $sql = "SELECT NEXTVAL('$seqtable')"; 550 $ret = $this->conn->getOne($sql); 381 551 }else if (DB_TYPE == "mysql") { 382 $sql = "SELECT last_insert_id();"; 383 } 384 $ret = $this->conn->getOne($sql); 552 $sql = "SELECT last_insert_id();"; 553 $ret = $this->conn->getOne($sql); 554 } 555 385 556 386 557 return $ret; … … 437 608 } 438 609 } 439 440 610 ?>
Note: See TracChangeset
for help on using the changeset viewer.
