2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
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
49 private $commands = array(
50 'pconnect' => '$this->command_pg_pconnect',
51 'connect' => '$this->command_pg_connect',
52 'query' => 'pg_query',
53 'error_num' => '$this->command_error_num',
54 'error_str' => '$this->command_error_str',
55 'escape_string' => '$this->command_pg_escape_string',
56 'escape_binary' => 'pg_escape_bytea',
57 'unescape_binary' => 'pg_unescape_bytea',
58 'fetch_assoc' => 'pg_fetch_assoc',
59 'fetch_row' => 'pg_fetch_row',
60 'fetch_object' => 'pg_fetch_object',
61 'free_result' => 'pg_free_result',
62 'insert_id' => '%link', // how do we support this...?
63 'num_rows' => 'pg_num_rows',
64 'affected_rows' => 'pg_affected_rows'
68 * Port number to connect to
74 * Fields array that is used in this module
77 private $fields = array(
78 'port' => array(REQ_NO
, null
, true
)
81 // ###################################################################
85 function __construct(&$registry)
87 parent
::__construct($registry);
90 // ###################################################################
96 * @param string Field name
97 * @param mixed Value of the field
99 function set($name, $value)
101 $this->registry
->do_set($name, $value, 'db_postgresql');
104 // ###################################################################
110 * @param string Field name
112 * @return mixed Value of the field
114 function get($fieldname)
116 return $this->registry
->do_get($fieldname, 'db_postgresql');
120 // ###################################################################
122 * Wrapper: pg_connect
126 * @param string Server name
127 * @param string User name
128 * @param string Password
129 * @param string Database
131 * @return integer DB-Link
133 function command_pg_connect($server, $user, $password, $database)
135 $this->registry
->check_isso_fields(get_class($this));
136 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
139 // ###################################################################
141 * Wrapper: pg_pconnect
145 * @param string Server name
146 * @param string User name
147 * @param string Password
148 * @param string Database
150 * @return integer DB-Link
152 function command_pg_pconnect($server, $user, $password, $database)
154 $this->registry
->check_isso_fields(get_class($this));
155 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
158 // ###################################################################
160 * Wrapper: pg_escape_string
164 * @param integer DB-Link (unused)
165 * @param string Raw string
167 * @return string Escaped string
169 function command_pg_escape_string($link, $string)
171 return pg_escape_string($string);
174 // ###################################################################
176 * Wrapper/no support: error string
180 * @param integer DB-Link
182 * @return string Error string
184 function command_error_str($link)
188 return pg_result_error($this->result
);
191 return pg_last_error($link);
194 // ###################################################################
196 * Not supported: error numbers
200 * @param integer DB-Link
202 * @return integer Returns -1 always
204 function command_error_num($link)
209 // ###################################################################
211 * Overload: insert_id
215 * @param string Table name
216 * @param string Auto-up field
218 * @return integer Insert ID
220 function insert_id($table, $field)
222 $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq");
223 return $temp['last_value'];
226 // ###################################################################
228 * Starts a database transaction
232 function transaction_start()
234 $this->query("BEGIN");
237 // ###################################################################
239 * Saves current transaction steps as a savepoint
243 * @param string Named savepoint
245 function transaction_savepoint($name)
247 $this->query("SAVEPOINT $name");
250 // ###################################################################
252 * Reverts a transaction back to a given savepoint
256 * @param string Named savepoint
258 function transaction_rollback($name = null
)
260 $this->query("ROLLBACK" . ($name != null ?
" TO $name" : ""));
263 // ###################################################################
265 * Commits a database transaction
269 function transaction_commit()
271 $this->query("COMMIT");
275 /*=====================================================================*\
276 || ###################################################################
279 || ###################################################################
280 \*=====================================================================*/