]> src.bluestatic.org Git - isso.git/blob - db_postgresql.php
Switch to actual public/private/protected indicators instead of @access ones
[isso.git] / db_postgresql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * PostgreSQL Database Abstraction Layer
24 * db_postgresql.php
25 *
26 * @package ISSO
27 */
28
29 $this->load('db', null);
30
31 /**
32 * PostgreSQL Database Abstraction Layer
33 *
34 * This framework is a function wrapper for PostgresQL functions so we can have
35 * better error reporting and query reporting.
36 *
37 * @author Blue Static
38 * @copyright Copyright ©2002 - [#]year[#], Blue Static
39 * @version $Revision$
40 * @package ISSO
41 *
42 */
43 class DB_PostgreSQL extends DB_Abstract
44 {
45 /**
46 * Command mapping list
47 * @var array
48 */
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'
65 );
66
67 /**
68 * Port number to connect to
69 * @var integer
70 */
71 private $port = 5432;
72
73 /**
74 * Fields array that is used in this module
75 * @var array
76 */
77 private $fields = array(
78 'port' => array(REQ_NO, null, true)
79 );
80
81 // ###################################################################
82 /**
83 * Constructor
84 */
85 function __construct(&$registry)
86 {
87 parent::__construct($registry);
88 }
89
90 // ###################################################################
91 /**
92 * (PHP 4) Constructor
93 */
94 function DB_PostgreSQL(&$registry)
95 {
96 $this->__construct($registry);
97 }
98
99 // ###################################################################
100 /**
101 * Sets an ISSO field
102 *
103 * @access public
104 *
105 * @param string Field name
106 * @param mixed Value of the field
107 */
108 function set($name, $value)
109 {
110 $this->registry->do_set($name, $value, 'db_postgresql');
111 }
112
113 // ###################################################################
114 /**
115 * Gets an ISSO field
116 *
117 * @access public
118 *
119 * @param string Field name
120 *
121 * @return mixed Value of the field
122 */
123 function get($fieldname)
124 {
125 return $this->registry->do_get($fieldname, 'db_postgresql');
126 }
127
128
129 // ###################################################################
130 /**
131 * Wrapper: pg_connect
132 *
133 * @access protected
134 *
135 * @param string Server name
136 * @param string User name
137 * @param string Password
138 * @param string Database
139 *
140 * @return integer DB-Link
141 */
142 function command_pg_connect($server, $user, $password, $database)
143 {
144 $this->registry->check_isso_fields(get_class($this));
145 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
146 }
147
148 // ###################################################################
149 /**
150 * Wrapper: pg_pconnect
151 *
152 * @access protected
153 *
154 * @param string Server name
155 * @param string User name
156 * @param string Password
157 * @param string Database
158 *
159 * @return integer DB-Link
160 */
161 function command_pg_pconnect($server, $user, $password, $database)
162 {
163 $this->registry->check_isso_fields(get_class($this));
164 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
165 }
166
167 // ###################################################################
168 /**
169 * Wrapper: pg_escape_string
170 *
171 * @access protected
172 *
173 * @param integer DB-Link (unused)
174 * @param string Raw string
175 *
176 * @return string Escaped string
177 */
178 function command_pg_escape_string($link, $string)
179 {
180 return pg_escape_string($string);
181 }
182
183 // ###################################################################
184 /**
185 * Wrapper/no support: error string
186 *
187 * @access protected
188 *
189 * @param integer DB-Link
190 *
191 * @return string Error string
192 */
193 function command_error_str($link)
194 {
195 if ($this->result)
196 {
197 return pg_result_error($this->result);
198 }
199
200 return pg_last_error($link);
201 }
202
203 // ###################################################################
204 /**
205 * Not supported: error numbers
206 *
207 * @access protected
208 *
209 * @param integer DB-Link
210 *
211 * @return integer Returns -1 always
212 */
213 function command_error_num($link)
214 {
215 return -1;
216 }
217
218 // ###################################################################
219 /**
220 * Overload: insert_id
221 *
222 * @access public
223 *
224 * @param string Table name
225 * @param string Auto-up field
226 *
227 * @return integer Insert ID
228 */
229 function insert_id($table, $field)
230 {
231 $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq");
232 return $temp['last_value'];
233 }
234
235 // ###################################################################
236 /**
237 * Starts a database transaction
238 *
239 * @access public
240 */
241 function transaction_start()
242 {
243 $this->query("BEGIN");
244 }
245
246 // ###################################################################
247 /**
248 * Saves current transaction steps as a savepoint
249 *
250 * @access public
251 *
252 * @param string Named savepoint
253 */
254 function transaction_savepoint($name)
255 {
256 $this->query("SAVEPOINT $name");
257 }
258
259 // ###################################################################
260 /**
261 * Reverts a transaction back to a given savepoint
262 *
263 * @access public
264 *
265 * @param string Named savepoint
266 */
267 function transaction_rollback($name = null)
268 {
269 $this->query("ROLLBACK" . ($name != null ? " TO $name" : ""));
270 }
271
272 // ###################################################################
273 /**
274 * Commits a database transaction
275 *
276 * @access public
277 */
278 function transaction_commit()
279 {
280 $this->query("COMMIT");
281 }
282 }
283
284 /*=====================================================================*\
285 || ###################################################################
286 || # $HeadURL$
287 || # $Id$
288 || ###################################################################
289 \*=====================================================================*/
290 ?>