]>
src.bluestatic.org Git - isso.git/blob - db_postgresql.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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.
37 * @author Iris Studios, Inc.
38 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
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
76 * Fields array that is used in this module
81 'port' => array(REQ_NO
, null, true)
84 // ###################################################################
88 function __construct(&$registry)
90 parent
::__construct($registry);
93 // ###################################################################
97 function DB_PostgreSQL(&$registry)
99 $this->__construct($registry);
102 // ###################################################################
108 * @param string Field name
109 * @param mixed Value of the field
111 function set($name, $value)
113 $this->registry
->do_set($name, $value, 'db_postgresql');
116 // ###################################################################
122 * @param string Field name
124 * @return mixed Value of the field
126 function get($fieldname)
128 return $this->registry
->do_get($fieldname, 'db_postgresql');
132 // ###################################################################
134 * Wrapper: pg_connect
138 * @param string Server name
139 * @param string User name
140 * @param string Password
141 * @param string Database
143 * @return integer DB-Link
145 function command_pg_connect($server, $user, $password, $database)
147 $this->registry
->check_isso_fields(get_class($this));
148 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
151 // ###################################################################
153 * Wrapper: pg_pconnect
157 * @param string Server name
158 * @param string User name
159 * @param string Password
160 * @param string Database
162 * @return integer DB-Link
164 function command_pg_pconnect($server, $user, $password, $database)
166 $this->registry->check_isso_fields(get_class($this));
167 return pg_pconnect("host
='$server' port={$this->port} user='$user' password
='$password' dbname='$database'");
170 // ###################################################################
172 * Wrapper: pg_escape_string
176 * @param integer DB-Link (unused)
177 * @param string Raw string
179 * @return string Escaped string
181 function command_pg_escape_string($link, $string)
183 return pg_escape_string($string);
186 // ###################################################################
188 * Wrapper/no support: error string
192 * @param integer DB-Link
194 * @return string Error string
196 function command_error_str($link)
200 return pg_result_error($this->result
);
203 return pg_last_error($link);
206 // ###################################################################
208 * Not supported: error numbers
212 * @param integer DB-Link
214 * @return integer Returns -1 always
216 function command_error_num($link)
221 // ###################################################################
223 * Overload: insert_id
227 * @param string Table name
228 * @param string Auto-up field
230 * @return integer Insert ID
232 function insert_id($table, $field)
234 $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq");
235 return $temp['last_value'];
238 // ###################################################################
240 * Starts a database transaction
244 function transaction_start()
246 $this->query("BEGIN");
249 // ###################################################################
251 * Saves current transaction steps as a savepoint
255 * @param string Named savepoint
257 function transaction_savepoint($name)
259 $this->query("SAVEPOINT $name");
262 // ###################################################################
264 * Reverts a transaction back to a given savepoint
268 * @param string Named savepoint
270 function transaction_rollback($name = null)
272 $this->query("ROLLBACK
" . ($name != null ? " TO
$name" : ""));
275 // ###################################################################
277 * Commits a database transaction
281 function transaction_commit()
283 $this->query("COMMIT");
287 /*=====================================================================*\
288 || ###################################################################
291 || ###################################################################
292 \*=====================================================================*/