2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * PostgreSQL Database Abstraction Layer
29 $this->load('db', null
);
32 * PostgreSQL Database Abstraction Layer
34 * This framework is a function wrapper for PostgresQL functions so we can have
35 * better error reporting and query reporting.
38 * @copyright Copyright ©2002 - [#]year[#], Blue Static
43 class DB_PostgreSQL
extends DB_Abstract
46 * Command mapping list
50 var $commands = array(
51 'pconnect' => '$this->command_pg_pconnect',
52 'connect' => '$this->command_pg_connect',
53 'query' => 'pg_query',
54 'error_num' => '$this->command_error_num',
55 'error_str' => '$this->command_error_str',
56 'escape_string' => '$this->command_pg_escape_string',
57 'escape_binary' => 'pg_escape_bytea',
58 'unescape_binary' => 'pg_unescape_bytea',
59 'fetch_assoc' => 'pg_fetch_assoc',
60 'fetch_row' => 'pg_fetch_row',
61 'fetch_object' => 'pg_fetch_object',
62 'free_result' => 'pg_free_result',
63 'insert_id' => '%link', // how do we support this...?
64 'num_rows' => 'pg_num_rows',
65 'affected_rows' => 'pg_affected_rows'
69 * Port number to connect to
75 // ###################################################################
79 function __construct(&$registry)
81 parent
::__construct($registry);
84 // ###################################################################
88 function DB_PostgreSQL(&$registry)
90 $this->__construct($registry);
93 // ###################################################################
95 * Sets the PGSQL port number
99 * @param integer The port number
101 function setPort($port)
106 // ###################################################################
108 * Gets the currently-set port number
112 * @return integer The port number
119 // ###################################################################
121 * Wrapper: pg_connect
125 * @param string Server name
126 * @param string User name
127 * @param string Password
128 * @param string Database
130 * @return integer DB-Link
132 function command_pg_connect($server, $user, $password, $database)
134 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
137 // ###################################################################
139 * Wrapper: pg_pconnect
143 * @param string Server name
144 * @param string User name
145 * @param string Password
146 * @param string Database
148 * @return integer DB-Link
150 function command_pg_pconnect($server, $user, $password, $database)
152 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
155 // ###################################################################
157 * Wrapper: pg_escape_string
161 * @param integer DB-Link (unused)
162 * @param string Raw string
164 * @return string Escaped string
166 function command_pg_escape_string($link, $string)
168 return pg_escape_string($string);
171 // ###################################################################
173 * Wrapper/no support: error string
177 * @param integer DB-Link
179 * @return string Error string
181 function command_error_str($link)
185 return pg_result_error($this->result
);
188 return pg_last_error($link);
191 // ###################################################################
193 * Not supported: error numbers
197 * @param integer DB-Link
199 * @return integer Returns -1 always
201 function command_error_num($link)
206 // ###################################################################
208 * Overload: insert_id
212 * @param string Table name
213 * @param string Auto-up field
215 * @return integer Insert ID
217 function insert_id($table, $field)
219 $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq");
220 return $temp['last_value'];
223 // ###################################################################
225 * Starts a database transaction
229 function transaction_start()
231 $this->query("BEGIN");
234 // ###################################################################
236 * Saves current transaction steps as a savepoint
240 * @param string Named savepoint
242 function transaction_savepoint($name)
244 $this->query("SAVEPOINT $name");
247 // ###################################################################
249 * Reverts a transaction back to a given savepoint
253 * @param string Named savepoint
255 function transaction_rollback($name = null
)
257 $this->query("ROLLBACK" . ($name != null ?
" TO $name" : ""));
260 // ###################################################################
262 * Commits a database transaction
266 function transaction_commit()
268 $this->query("COMMIT");
272 /*=====================================================================*\
273 || ###################################################################
276 || ###################################################################
277 \*=====================================================================*/