Index: /temp/test-xoops.ec-cube.net/html/class/SC_Query.php
===================================================================
--- /temp/test-xoops.ec-cube.net/html/class/SC_Query.php	(revision 1091)
+++ /temp/test-xoops.ec-cube.net/html/class/SC_Query.php	(revision 1091)
@@ -0,0 +1,375 @@
+<?php
+class SC_Query {
+	var $option;
+	var $where;
+	var $conn;
+	
+	// ¥³¥ó¥¹¥È¥é¥¯¥¿
+	function SC_Query($dsn = "", $new_con = false) {
+		$this->conn = new SC_DBconn($dsn, $new_con);
+		$this->where = "";
+		return $this->conn;	
+	}
+	
+	// COUNTÊ¸¤Î¼Â¹Ô
+	function count($table, $where = "", $arrval = array()) {
+		if(strlen($where) <= 0) {
+			$sqlse = "SELECT COUNT(*) FROM $table";
+		} else {
+			$sqlse = "SELECT COUNT(*) FROM $table WHERE $where";
+		}
+		// ¥«¥¦¥ó¥ÈÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->getOne($sqlse, $arrval);
+
+		return $ret;
+	}
+	
+	function select($col, $table, $where = "", $arrval = array()){
+		$sqlse = $this->getsql($col, $table, $where);
+		$ret = $this->conn->getAll($sqlse, $arrval);
+		return $ret;
+	}
+		
+	function getLastQuery($disp = false) {
+		$sql = $this->conn->conn->last_query;
+		if($disp) { 
+			print($sql.";<br />\n");
+		}
+		return $sql;
+	}
+		
+	function commit() {
+		$this->conn->query("COMMIT");
+	}
+	
+	function begin() {
+		$this->conn->query("BEGIN");
+	}
+	
+	function rollback() {
+		$this->conn->query("ROLLBACK");
+	}
+	
+	function exec($str, $arrval = array()) {
+		$this->conn->query($str, $arrval);
+	}
+	
+	function autoselect($col, $table, $arrwhere = array(), $arrcon = array()) {
+		$strw = "";			
+		$find = false;
+		foreach ($arrwhere as $key => $val) {
+			if(strlen($val) > 0) {
+				if(strlen($strw) <= 0) {
+					$strw .= $key ." LIKE ?";
+				} else if(strlen($arrcon[$key]) > 0) {
+					$strw .= " ". $arrcon[$key]. " " . $key ." LIKE ?";
+				} else {
+					$strw .= " AND " . $key ." LIKE ?";
+				}
+				
+				$arrval[] = $val;
+			}
+		}
+		
+		if(strlen($strw) > 0) {
+			$sqlse = "SELECT $col FROM $table WHERE $strw ".$this->option;
+		} else {
+			$sqlse = "SELECT $col FROM $table ".$this->option;
+		}
+		$ret = $this->conn->getAll($sqlse, $arrval);
+		return $ret;
+	}
+	
+	function getall($sql, $arrval = array()) {
+		$ret = $this->conn->getAll($sql, $arrval);
+		return $ret;
+	}
+
+	function getsql($col, $table, $where) {
+		if($where != "") {
+			// °ú¿ô¤Î$where¤òÍ¥Àè¤·¤Æ¼Â¹Ô¤¹¤ë¡£
+			$sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option;
+		} else {
+			if($this->where != "") {
+					$sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option;
+				} else {
+					$sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option;
+			}
+		}
+		return $sqlse;
+	}
+			
+	function setoption($str) {
+		$this->option = $str;
+	}
+	
+	function setlimitoffset($limit, $offset) {
+		if (is_numeric($limit) && is_numeric($offset)){
+			$this->option.= " LIMIT " . $limit;
+			$this->option.= " OFFSET " . $offset;
+		}
+	}
+	
+	function setgroupby($str) {
+		$this->groupby = "GROUP BY " . $str;
+	}
+	
+	function andwhere($str) {
+		if($this->where != "") {
+			$this->where .= " AND " . $str;
+		} else {
+			$this->where = $str;
+		}
+	}
+	
+	function orwhere($str) {
+		if($this->where != "") {
+			$this->where .= " OR " . $str;
+		} else {
+			$this->where = $str;
+		}
+	}
+		
+	function setwhere($str) {
+		$this->where = $str;
+	}
+	
+	function setorder($str) {
+		$this->order = "ORDER BY " . $str;
+	}
+	
+		
+	function setlimit($limit){
+		if ( is_numeric($limit)){
+			$this->option = " LIMIT " .$limit;
+		}	
+	}
+	
+	function setoffset($offset) {
+		if ( is_numeric($offset)){
+			$this->offset = " OFFSET " .$offset;
+		}	
+	}
+	
+	
+	// INSERTÊ¸¤ÎÀ¸À®¡¦¼Â¹Ô
+	// $table	:¥Æ¡¼¥Ö¥ëÌ¾
+	// $sqlval	:ÎóÌ¾ => ÃÍ¤Î³ÊÇ¼¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó
+	function insert($table, $sqlval, $addcol = "") {
+		$strcol = '';
+		$strval = '';
+		$find = false;
+		foreach ($sqlval as $key => $val) {
+				$strcol .= $key . ',';
+				if(eregi("^Now\(\)$", $val)) {
+					$strval .= 'Now(),';
+				} else {
+					$strval .= '?,';
+					if($val != ""){
+						$arrval[] = $val;
+					} else {
+						$arrval[] = NULL;
+					}
+				}
+				$find = true;
+		}
+		if(!$find) {
+			return false;
+		}
+		
+		if($addcol != "") {
+			foreach($addcol as $key => $val) {
+				$strcol .= $key . ',';
+				$strval .= $val . ',';
+			}
+		}
+		
+		// Ê¸Ëö¤Î","¤òºï½ü
+		$strcol = ereg_replace(",$","",$strcol);
+		// Ê¸Ëö¤Î","¤òºï½ü
+		$strval = ereg_replace(",$","",$strval);
+		$sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")";
+		
+		// INSERTÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->query($sqlin, $arrval);
+		
+		return $ret;		
+	}
+	
+		// INSERTÊ¸¤ÎÀ¸À®¡¦¼Â¹Ô
+	// $table	:¥Æ¡¼¥Ö¥ëÌ¾
+	// $sqlval	:ÎóÌ¾ => ÃÍ¤Î³ÊÇ¼¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó
+	function fast_insert($table, $sqlval) {
+		$strcol = '';
+		$strval = '';
+		$find = false;
+		
+		foreach ($sqlval as $key => $val) {
+				$strcol .= $key . ',';
+				if($val != ""){
+					$eval = pg_escape_string($val);
+					$strval .= "'$eval',";
+				} else {
+					$strval .= "NULL,";
+				}
+				$find = true;
+		}
+		if(!$find) {
+			return false;
+		}
+		// Ê¸Ëö¤Î","¤òºï½ü
+		$strcol = ereg_replace(",$","",$strcol);
+		// Ê¸Ëö¤Î","¤òºï½ü
+		$strval = ereg_replace(",$","",$strval);
+		$sqlin = "INSERT INTO $table(" . $strcol. ") VALUES (" . $strval . ")";
+		
+		// INSERTÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->query($sqlin);
+		
+		return $ret;		
+	}
+	
+	
+	// UPDATEÊ¸¤ÎÀ¸À®¡¦¼Â¹Ô
+	// $table	:¥Æ¡¼¥Ö¥ëÌ¾
+	// $sqlval	:ÎóÌ¾ => ÃÍ¤Î³ÊÇ¼¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó
+	// $where	:WHEREÊ¸»úÎó
+	function update($table, $sqlval, $where = "", $arradd = "", $addcol = "") {
+		$strcol = '';
+		$strval = '';
+		$find = false;
+		foreach ($sqlval as $key => $val) {
+			if(eregi("^Now\(\)$", $val)) {
+				$strcol .= $key . '= Now(),';
+			} else {
+				$strcol .= $key . '= ?,';
+				if($val != ""){
+					$arrval[] = $val;
+				} else {
+					$arrval[] = NULL;
+				}
+			}
+			$find = true;
+		}
+		if(!$find) {
+			return false;
+		}
+		
+		if($addcol != "") {
+			foreach($addcol as $key => $val) {
+				$strcol .= "$key = $val,";
+			}
+		}
+				
+		// Ê¸Ëö¤Î","¤òºï½ü
+		$strcol = ereg_replace(",$","",$strcol);
+		// Ê¸Ëö¤Î","¤òºï½ü
+		$strval = ereg_replace(",$","",$strval);
+		
+		if($where != "") {
+			$sqlup = "UPDATE $table SET $strcol WHERE $where";
+		} else {
+			$sqlup = "UPDATE $table SET $strcol";
+		}
+		
+		if(is_array($arradd)) {
+			// ¥×¥ì¡¼¥¹¥Û¥ë¥À¡¼ÍÑ¤ËÇÛÎó¤òÄÉ²Ã
+			foreach($arradd as $val) {
+				$arrval[] = $val;
+			}
+		}
+		
+		// INSERTÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->query($sqlup, $arrval);
+		return $ret;		
+	}
+
+	// MAXÊ¸¤Î¼Â¹Ô
+	function max($table, $col, $where = "", $arrval = array()) {
+		if(strlen($where) <= 0) {
+			$sqlse = "SELECT MAX($col) FROM $table";
+		} else {
+			$sqlse = "SELECT MAX($col) FROM $table WHERE $where";
+		}
+		// MAXÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->getOne($sqlse, $arrval);
+		return $ret;
+	}
+	
+	// MINÊ¸¤Î¼Â¹Ô
+	function min($table, $col, $where = "", $arrval = array()) {
+		if(strlen($where) <= 0) {
+			$sqlse = "SELECT MIN($col) FROM $table";
+		} else {
+			$sqlse = "SELECT MIN($col) FROM $table WHERE $where";
+		}
+		// MINÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->getOne($sqlse, $arrval);
+		return $ret;
+	}
+	
+	// ÆÃÄê¤Î¥«¥é¥à¤ÎÃÍ¤ò¼èÆÀ
+	function get($table, $col, $where = "", $arrval = array()) {
+		if(strlen($where) <= 0) {
+			$sqlse = "SELECT $col FROM $table";
+		} else {
+			$sqlse = "SELECT $col FROM $table WHERE $where";
+		}
+		// SQLÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->getOne($sqlse, $arrval);
+		return $ret;
+	}
+	
+	function getone($sql, $arrval = array()) {
+		// SQLÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->getOne($sql, $arrval);
+		return $ret;
+	}
+		
+	// °ì¹Ô¤ò¼èÆÀ
+	function getrow($table, $col, $where = "", $arrval = array()) {
+		if(strlen($where) <= 0) {
+			$sqlse = "SELECT $col FROM $table";
+		} else {
+			$sqlse = "SELECT $col FROM $table WHERE $where";
+		}
+		// SQLÊ¸¤Î¼Â¹Ô
+		$ret = $this->conn->getRow($sqlse, $arrval);
+		return $ret;
+	}
+		
+	// ¥ì¥³¡¼¥É¤Îºï½ü
+	function delete($table, $where = "", $arrval = array()) {
+		if(strlen($where) <= 0) {
+			$sqlde = "DELETE FROM $table";
+		} else {
+			$sqlde = "DELETE FROM $table WHERE $where";
+		}
+		$ret = $this->conn->query($sqlde, $arrval);
+		return $ret;
+	}
+	
+	function nextval($table, $colname) {
+		$seqtable = $table . "_" . $colname . "_seq";
+		$ret = $this->conn->getOne("SELECT NEXTVAL('$seqtable')");
+		return $ret;
+	}
+	
+	//»ØÄê¤·¤¿¥Æ¡¼¥Ö¥ë¤Î¥«¥é¥à°ìÍ÷¤ò¼èÆÀ
+	function getColList($table) {
+		$col = "attname";
+		$from = "pg_class, pg_attribute";
+		$where = "relname = '" . $table . "' AND relfilenode = attrelid AND attnum > 0";
+		$orderby = "attnum";
+		$sql = "SELECT " . $col . " FROM " . $from . " WHERE " . $where . " ORDER BY " . $orderby;
+		$arrRet = $this->conn->getAll($sql);
+		$max = count($arrRet);
+		for($i = 0; $i < $max; $i++) {
+			foreach($arrRet[$i] as $val) {
+				$arrList["attname"][] = $val;
+			}
+		}
+		return $arrList["attname"];
+	}
+}
+?>
