load('db', null); /** * PostgreSQL Database Abstraction Layer * * This framework is a function wrapper for PostgresQL functions so we can have * better error reporting and query reporting. * * @author Blue Static * @copyright Copyright ©2002 - [#]year[#], Blue Static * @version $Revision$ * @package ISSO * */ class DB_PostgreSQL extends DB_Abstract { /** * Command mapping list * @var array * @access private */ var $commands = array( 'pconnect' => '$this->command_pg_pconnect', 'connect' => '$this->command_pg_connect', 'query' => 'pg_query', 'error_num' => '$this->command_error_num', 'error_str' => '$this->command_error_str', 'escape_string' => '$this->command_pg_escape_string', 'escape_binary' => 'pg_escape_bytea', 'unescape_binary' => 'pg_unescape_bytea', 'fetch_assoc' => 'pg_fetch_assoc', 'fetch_row' => 'pg_fetch_row', 'fetch_object' => 'pg_fetch_object', 'free_result' => 'pg_free_result', 'insert_id' => '%link', // how do we support this...? 'num_rows' => 'pg_num_rows', 'affected_rows' => 'pg_affected_rows' ); /** * Port number to connect to * @var integer * @access private */ var $port = 5432; // ################################################################### /** * Constructor */ function __construct(&$registry) { parent::__construct($registry); } // ################################################################### /** * (PHP 4) Constructor */ function DB_PostgreSQL(&$registry) { $this->__construct($registry); } // ################################################################### /** * Sets the PGSQL port number * * @access public * * @param integer The port number */ function setPort($port) { $this->port = $port; } // ################################################################### /** * Gets the currently-set port number * * @access public * * @return integer The port number */ function getPort() { return $this->port; } // ################################################################### /** * Wrapper: pg_connect * * @access protected * * @param string Server name * @param string User name * @param string Password * @param string Database * * @return integer DB-Link */ function command_pg_connect($server, $user, $password, $database) { return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'"); } // ################################################################### /** * Wrapper: pg_pconnect * * @access protected * * @param string Server name * @param string User name * @param string Password * @param string Database * * @return integer DB-Link */ function command_pg_pconnect($server, $user, $password, $database) { return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'"); } // ################################################################### /** * Wrapper: pg_escape_string * * @access protected * * @param integer DB-Link (unused) * @param string Raw string * * @return string Escaped string */ function command_pg_escape_string($link, $string) { return pg_escape_string($string); } // ################################################################### /** * Wrapper/no support: error string * * @access protected * * @param integer DB-Link * * @return string Error string */ function command_error_str($link) { if ($this->result) { return pg_result_error($this->result); } return pg_last_error($link); } // ################################################################### /** * Not supported: error numbers * * @access protected * * @param integer DB-Link * * @return integer Returns -1 always */ function command_error_num($link) { return -1; } // ################################################################### /** * Overload: insert_id * * @access public * * @param string Table name * @param string Auto-up field * * @return integer Insert ID */ function insert_id($table, $field) { $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq"); return $temp['last_value']; } // ################################################################### /** * Starts a database transaction * * @access public */ function transaction_start() { $this->query("BEGIN"); } // ################################################################### /** * Saves current transaction steps as a savepoint * * @access public * * @param string Named savepoint */ function transaction_savepoint($name) { $this->query("SAVEPOINT $name"); } // ################################################################### /** * Reverts a transaction back to a given savepoint * * @access public * * @param string Named savepoint */ function transaction_rollback($name = null) { $this->query("ROLLBACK" . ($name != null ? " TO $name" : "")); } // ################################################################### /** * Commits a database transaction * * @access public */ function transaction_commit() { $this->query("COMMIT"); } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>