clear_querys(); $this -> clear_counts(); } //clear querys function clear_querys() { $this -> query_str = ""; $this -> query_where = ""; $this -> query_orderby = ""; $this -> query_groupby = ""; $this -> query_table = ""; $this -> query_field = ""; $this -> query_value = ""; } //clear counts function clear_counts() { $this -> currentFieldnum = 0; $this -> currentRownum = 0; } //make query function make( $_mode = "select"){ $ret_code = false; $this -> errorMessage = ""; switch ($_mode){ case "select"; if ($this -> query_field != "" ) { if ($this -> query_table != "" ) { $ret_code = true; $this -> query_str = "select ".$this ->query_field; $this -> query_str = $this -> query_str." from ".$this -> query_table; if ($this -> query_where != "" ) { $this -> query_str = $this -> query_str." where ".$this -> query_where; }; if ($this -> query_groupby != "" ) { $this -> query_str = $this -> query_str." group by ".$this -> query_groupby; }; if ($this -> query_orderby != "" ) { $this -> query_str = $this -> query_str." order by ".$this -> query_orderby; }; }; }; break; case "insert"; if ($this -> query_table != "" ) { if ($this -> query_value != "" ) { $ret_code = true; $this -> query_str = "insert into ".$this -> query_table; if ($this -> query_field != "" ) { $this -> query_str = $this -> query_str."(".$this -> query_field.")";}; $this -> query_str = $this -> query_str." values (".$this -> query_value.")"; }; }; break; case "update"; if ($this -> query_table != "" ) { if ($this -> query_value != "" ) { if ($this -> query_where != "" ) { $ret_code = true; $this -> query_str = "update ".$this -> query_table; $this -> query_str = $this -> query_str." set ".$this -> query_value; $this -> query_str = $this -> query_str." where ".$this -> query_where; }; }; }; break; case "delete"; if ($this -> query_table != "" ) { if ($this -> query_where != "" ) { $ret_code = true; $this -> query_str = "delete from ".$this -> query_table; $this -> query_str = $this -> query_str." where ".$this -> query_where; }; }; break; default; $this -> errorMessage = "対応していないmodeです.(select : insert : update : delete)"; } return $ret_code; } // execute query function exec( $_mode = "select"){ $ret_code = $this -> make($_mode); if ($ret_code) $ret_code = $this -> execute($this -> query_str); return $ret_code; } //(sub function) add querystr function _add(&$_pstr,$_note,$_mode){ if ($_mode == "new") $_pstr = ""; elseif($_pstr != "" ) $_pstr = $_pstr." ".$_mode." "; $_pstr = $_pstr.$_note; return true; } //add querystr function add( $_note = "",$_type = "select" , $_mode = "and"){ $ret_code = false; $this -> errorMessage = ""; // check mode switch($_mode){ case "and"; break; case "or"; break; case ","; break; case "new"; break; default; $this -> errorMessage = "指定できないmodeです.(and : or : , : new)"; return $ret_code; } if ($_note == ""){ $this -> errorMessage = "追加するクエリーがありません."; return $ret_code; } switch($_type){ case "select"; case "field"; $ret_code = $this->_add($this->query_field,$_note,$_mode); break; case "from"; case "into"; case "table"; $ret_code = $this->_add($this->query_table,$_note,$_mode); break; case "where"; $ret_code = $this->_add($this->query_where,$_note,$_mode); break; case "orderby"; $ret_code = $this->_add($this->query_orderby,$_note,$_mode); break; case "groupby"; $ret_code = $this->_add($this->query_groupby,$_note,$_mode); break; case "values"; case "set"; case "value"; // 旧クラスとの互換性のため $ret_code = $this->_add($this->query_value,$_note,$_mode); break; default; $this -> errorMessage = "指定できないtypeです.(select : from : where : orderby : groupby : table : values : set : field : into)"; } return $ret_code; } //get fieldnames function getfieldname() { if ($this -> currentFieldnum >= $this -> colcount) { $this -> currentFieldnum = 0; return false; } else { //$s = pg_fieldname($this -> queryresult,$this -> currentFieldnum); // - PHP4.2.0 $s = pg_field_name($this -> queryresult,$this -> currentFieldnum); // PHP4.2.0 - ++$this -> currentFieldnum; return $s; }; } //get rows function getrow() { if ($this -> currentRownum >= $this -> rowcount) { $this -> currentRownum = 0; return false; } else { $s = pg_fetch_row($this -> queryresult, $this -> currentRownum); ++$this -> currentRownum; return $s; }; } } ?>