]>
src.bluestatic.org Git - isso.git/blob - db_postgresql.php
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 public function __construct(&$registry)
87 parent
::__construct($registry);
90 // ###################################################################
94 * @param string Field name
95 * @param mixed Value of the field
97 public function set($name, $value)
99 $this->registry
->do_set($name, $value, 'db_postgresql');
102 // ###################################################################
106 * @param string Field name
108 * @return mixed Value of the field
110 public function get($fieldname)
112 return $this->registry
->do_get($fieldname, 'db_postgresql');
116 // ###################################################################
118 * Wrapper: pg_connect
120 * @param string Server name
121 * @param string User name
122 * @param string Password
123 * @param string Database
125 * @return integer DB-Link
127 protected function command_pg_connect($server, $user, $password, $database)
129 $this->registry
->check_isso_fields(get_class($this));
130 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
133 // ###################################################################
135 * Wrapper: pg_pconnect
137 * @param string Server name
138 * @param string User name
139 * @param string Password
140 * @param string Database
142 * @return integer DB-Link
144 protected function command_pg_pconnect($server, $user, $password, $database)
146 $this->registry->check_isso_fields(get_class($this));
147 return pg_pconnect("host
='$server' port={$this->port} user='$user' password
='$password' dbname='$database'");
150 // ###################################################################
152 * Wrapper: pg_escape_string
154 * @param integer DB-Link (unused)
155 * @param string Raw string
157 * @return string Escaped string
159 protected function command_pg_escape_string($link, $string)
161 return pg_escape_string($string);
164 // ###################################################################
166 * Wrapper/no support: error string
168 * @param integer DB-Link
170 * @return string Error string
172 protected function command_error_str($link)
176 return pg_result_error($this->result
);
179 return pg_last_error($link);
182 // ###################################################################
184 * Not supported: error numbers
186 * @param integer DB-Link
188 * @return integer Returns -1 always
190 protected function command_error_num($link)
195 // ###################################################################
197 * Overload: insert_id
199 * @param string Table name
200 * @param string Auto-up field
202 * @return integer Insert ID
204 public function insert_id($table, $field)
206 $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq");
207 return $temp['last_value'];
210 // ###################################################################
212 * Starts a database transaction
214 public function transaction_start()
216 $this->query("BEGIN");
219 // ###################################################################
221 * Saves current transaction steps as a savepoint
223 * @param string Named savepoint
225 public function transaction_savepoint($name)
227 $this->query("SAVEPOINT $name");
230 // ###################################################################
232 * Reverts a transaction back to a given savepoint
234 * @param string Named savepoint
236 public function transaction_rollback($name = null)
238 $this->query("ROLLBACK
" . ($name != null ? " TO
$name" : ""));
241 // ###################################################################
243 * Commits a database transaction
245 public function transaction_commit()
247 $this->query("COMMIT");
251 /*=====================================================================*\
252 || ###################################################################
255 || ###################################################################
256 \*=====================================================================*/