Update version.php to 3.3.0
[isso.git] / DbPostgreSql.php
index 8a0e8e561da939b2d7aa1d1fb4f8203d5b9fbfeb..59929a88c53b3ebcca440ef052ef081d417c74bd 100644 (file)
@@ -2,11 +2,11 @@
 /*=====================================================================*\
 || ###################################################################
 || # Blue Static ISSO Framework
-|| # Copyright ©2002-[#]year[#] Blue Static
+|| # Copyright (c)2005-2009 Blue Static
 || #
 || # This program is free software; you can redistribute it and/or modify
 || # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| # the Free Software Foundation; version 2 of the License.
 || #
 || # This program is distributed in the hope that it will be useful, but
 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 \*=====================================================================*/
 
 /**
-* PostgreSQL Database Layer (DbPostgreSql.php)
-*
-* @package     ISSO
-*/
+ * PostgreSQL Database Layer (DbPostgreSql.php)
+ *
+ * @package    ISSO
+ */
 
-require_once('ISSO/Db.php');
+require_once(ISSO . '/Db.php');
 
 /**
-* PostgreSQL Database 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
-* 
-*/
+ * PostgreSQL Database 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 (c)2005 - 2009, Blue Static
+ * @package            ISSO
+ * 
+ */
 class BSDbPostgreSql extends BSDb
 {
        /**
-       * Port number to connect to
-       * @var  integer
-       */
+        * Port number to connect to
+        * @var integer
+        */
        private $port = 5432;
        
-       // ###################################################################
        /**
-       * Sets the port number for the connection
-       *
-       * @param        integer Port number
-       */
+        * Sets the port number for the connection
+        *
+        * @param       integer Port number
+        */
        public function setPort($port)
        {
                $this->port = $port;
        }
 
-       // ###################################################################
        /**
-       * Wrapper: pg_connect
-       */
+        * Wrapper: pg_connect
+        */
        protected function _connect($server, $user, $password, $database)
        {
                return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
        }
        
-       // ###################################################################
        /**
-       * Wrapper: pg_pconnect
-       */
-       protected function _pConnect($server, $user, $password, $database)
-       {
-               return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
-       }
-       
-       // ###################################################################
-       /**
-       * Wrapper: pg_escape_string
-       */
+        * Wrapper: pg_escape_string
+        */
        protected function _escapeString()
        {
                return pg_escape_string($string);
        }
        
-       // ###################################################################
        /**
-       * Wrapper/no support: error string
-       */
+        * Wrapper/no support: error string
+        */
        protected function _errorString()
        {
                if ($this->result)
@@ -99,151 +85,129 @@ class BSDbPostgreSql extends BSDb
                return pg_last_error($this->dblink);
        }
        
-       // ###################################################################
        /**
-       * Not supported: error numbers
-       */
+        * Not supported: error numbers
+        */
        protected function _errorNumber()
        {
                return -1;
        }
        
-       // ###################################################################
        /**
-       * Overload: insertId
-       */
+        * Overload: insertId
+        */
        public function insertId($table, $field)
        {
-               $temp = $this->queryFirst("SELECT last_value FROM {$table}_{$field}_seq");
-               return $temp['last_value'];
+               return $this->queryFirst("SELECT last_value FROM {$table}_{$field}_seq")->fetchObject()->last_value;
        }
        
        protected function _insertId()
-       {
-               // we never get here
-       }
-       
-       // ###################################################################
-       /**
-       * Wrapper: pg_fetch_assoc
-       */
-       protected function _fetchAssocArray($result)
-       {
-               return pg_fetch_assoc($result);
-       }
+       {}
        
-       // ###################################################################
        /**
-       * Wrapper: pg_fetch_row
-       */
-       protected function _fetchRowArray($result)
+        * Wrapper: pg_affected_rows
+        */
+       protected function _affectedRows($result)
        {
-               return pg_fetch_row($result);
+               return pg_affected_rows($result);
        }
        
-       // ###################################################################
        /**
-       * Wrapper: pg_fetch_object
-       */
-       public function _fetchObject($result)
+        * Starts a database transaction
+        */
+       public function begin()
        {
-               return pg_fetch_object($result);
+               $this->query("BEGIN");
        }
-       
-       // ###################################################################
+
        /**
-       * Wrapper: pg_free_result
-       */
-       protected function _freeResult($result)
+        * Reverts a transaction back to a given savepoint
+        */
+       public function rollback()
        {
-               pg_free_result($result);
+               $this->query("ROLLBACK");
        }
        
-       // ###################################################################
        /**
-       * Wrapper: pg_num_rows
-       */
-       protected function _numRows($result)
+        * Commits a database transaction
+        */
+       public function commit()
        {
-               return pg_num_rows($result);
+               $this->query("COMMIT");
        }
        
-       // ###################################################################
        /**
-       * Wrapper: pg_affected_rows
-       */
-       protected function _affectedRows($result)
+        * Returns the error number
+        *
+        * @return      integer Error number
+        */
+       public function _errorNumber()
        {
-               return PG_AFFECTED_ROWS($result);
+               return -1;
        }
        
-       // ###################################################################
        /**
-       * Starts a database transaction
-       */
-       public function transactionStart()
+        * Returns the error string
+        *
+        * @return      string  Error string
+        */
+       public function _errorString()
        {
-               $this->query("BEGIN");
+               return pg_last_error($this->dblink);
        }
-       
-       // ###################################################################
-       /**
-       * Saves current transaction steps as a savepoint
-       *
-       * @param        string  Named savepoint
-       */
-       public function transactionSavepoint($name)
+}
+
+/**
+ * Database Result
+ *
+ * This class holds result information for a database result
+ *
+ * @author             rsesek
+ * @copyright  Copyright (c)2005 - 2009, Blue Static
+ * @package            ISSO
+ *
+ */
+class BSDbPostgreSqlResult extends BSDbResult
+{      
+       /**
+        * Wrapper: pg_fetch_assoc
+        */
+       protected function _fetchAssocArray($result)
        {
-               $this->query("SAVEPOINT $name");
+               return pg_fetch_assoc($result);
        }
        
-       // ###################################################################
        /**
-       * Reverts a transaction back to a given savepoint
-       *
-       * @param        string  Named savepoint
-       */
-       public function transactionRollback($name = null)
+        * Wrapper: pg_fetch_row
+        */
+       protected function _fetchRowArray($result)
        {
-               $this->query("ROLLBACK" . ($name != null ? " TO $name" : ""));
+               return pg_fetch_row($result);
        }
        
-       // ###################################################################
        /**
-       * Commits a database transaction
-       */
-       public function transactionCommit()
+        * Wrapper: pg_fetch_object
+        */
+       public function _fetchObject($result)
        {
-               $this->query("COMMIT");
+               return pg_fetch_object($result);
        }
        
-       // ###################################################################
        /**
-       * Returns the error number
-       *
-       * @return       integer Error number
-       */
-       public function _errorNumber()
+        * Wrapper: pg_free_result
+        */
+       protected function _freeResult($result)
        {
-               return -1;
+               pg_free_result($result);
        }
        
-       // ###################################################################
        /**
-       * Returns the error string
-       *
-       * @return       string  Error string
-       */
-       public function _errorString()
+        * Wrapper: pg_num_rows
+        */
+       protected function _numRows($result)
        {
-               return pg_last_error($this->dblink);
+               return pg_num_rows($result);
        }
 }
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file