]>
src.bluestatic.org Git - isso.git/blob - db_postgresql.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
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' => 'mysqli_real_escape_string',
58 'unescape_binary' => '$this->command_unescape_binary',
59 'escape_binary' => 'pg_escape_bytea',
60 'unescape_binary' => 'pg_unescape_bytea',
61 'fetch_assoc' => 'pg_fetch_assoc',
62 'fetch_row' => 'pg_fetch_row',
63 'fetch_object' => 'pg_fetch_object',
64 'free_result' => 'pg_free_result',
65 'insert_id' => '%link', // how do we support this...?
66 'num_rows' => 'pg_num_rows',
67 'affected_rows' => 'pg_affected_rows'
71 * Port number to connect to
78 * Fields array that is used in this module
83 'port' => array(REQ_NO
, null, true)
86 // ###################################################################
90 function __construct(&$registry)
92 parent
::__construct($registry);
95 // ###################################################################
99 function DB_PostgreSQL(&$registry)
101 $this->__construct($registry);
104 // ###################################################################
110 * @param string Field name
111 * @param mixed Value of the field
113 function set($name, $value)
115 $this->registry
->do_set($name, $value, 'db_postgresql');
118 // ###################################################################
124 * @param string Field name
126 * @return mixed Value of the field
128 function get($fieldname)
130 return $this->registry
->do_get($fieldname, 'db_postgresql');
134 // ###################################################################
136 * Wrapper: pg_connect
140 * @param string Server name
141 * @param string User name
142 * @param string Password
143 * @param string Database
145 * @return integer DB-Link
147 function command_pg_connect($server, $user, $password, $database)
149 $this->registry
->check_isso_fields(get_class($this));
150 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
153 // ###################################################################
155 * Wrapper: pg_pconnect
159 * @param string Server name
160 * @param string User name
161 * @param string Password
162 * @param string Database
164 * @return integer DB-Link
166 function command_pg_pconnect($server, $user, $password, $database)
168 $this->registry->check_isso_fields(get_class($this));
169 return pg_pconnect("host
='$server' port={$this->port} user='$user' password
='$password' dbname='$database'");
172 // ###################################################################
174 * Wrapper: pg_escape_string
178 * @param integer DB-Link (unused)
179 * @param string Raw string
181 * @return string Escaped string
183 function command_pg_escape_string($link, $string)
185 return pg_escape_string($string);
188 // ###################################################################
190 * Wrapper/no support: error string
194 * @param integer DB-Link
196 * @return string Error string
198 function command_error_str($link)
202 return pg_result_error($this->result
);
205 return pg_last_error($link);
208 // ###################################################################
210 * Not supported: error numbers
214 * @param integer DB-Link
216 * @return integer Returns -1 always
218 function command_error_num($link)
223 // ###################################################################
225 * Overload: insert_id
229 * @param string Table name
230 * @param string Auto-up field
232 * @return integer Insert ID
234 function insert_id($table, $field)
236 $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq");
237 return $temp['last_value'];
240 // ###################################################################
242 * Starts a database transaction
246 function transaction_start()
248 $this->query("BEGIN");
251 // ###################################################################
253 * Saves current transaction steps as a savepoint
257 * @param string Named savepoint
259 function transaction_savepoint($name)
261 $this->query("SAVEPOINT $name");
264 // ###################################################################
266 * Reverts a transaction back to a given savepoint
270 * @param string Named savepoint
272 function transaction_rollback($name = null)
274 $this->query("ROLLBACK
" . ($name != null ? " TO
$name" : ""));
277 // ###################################################################
279 * Commits a database transaction
283 function transaction_commit()
285 $this->query("COMMIT");
289 /*=====================================================================*\
290 || ###################################################################
293 || ###################################################################
294 \*=====================================================================*/