The colspan parameter in row_text now doesn't add an extra <td> but simply expands...
[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 * @access private
49 */
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'
66 );
67
68 /**
69 * Port number to connect to
70 * @var integer
71 * @access private
72 */
73 var $port = 5432;
74
75 /**
76 * Fields array that is used in this module
77 * @var array
78 * @access private
79 */
80 var $fields = array(
81 'port' => array(REQ_NO, null, true)
82 );
83
84 // ###################################################################
85 /**
86 * Constructor
87 */
88 function __construct(&$registry)
89 {
90 parent::__construct($registry);
91 }
92
93 // ###################################################################
94 /**
95 * (PHP 4) Constructor
96 */
97 function DB_PostgreSQL(&$registry)
98 {
99 $this->__construct($registry);
100 }
101
102 // ###################################################################
103 /**
104 * Sets an ISSO field
105 *
106 * @access public
107 *
108 * @param string Field name
109 * @param mixed Value of the field
110 */
111 function set($name, $value)
112 {
113 $this->registry->do_set($name, $value, 'db_postgresql');
114 }
115
116 // ###################################################################
117 /**
118 * Gets an ISSO field
119 *
120 * @access public
121 *
122 * @param string Field name
123 *
124 * @return mixed Value of the field
125 */
126 function get($fieldname)
127 {
128 return $this->registry->do_get($fieldname, 'db_postgresql');
129 }
130
131
132 // ###################################################################
133 /**
134 * Wrapper: pg_connect
135 *
136 * @access protected
137 *
138 * @param string Server name
139 * @param string User name
140 * @param string Password
141 * @param string Database
142 *
143 * @return integer DB-Link
144 */
145 function command_pg_connect($server, $user, $password, $database)
146 {
147 $this->registry->check_isso_fields(get_class($this));
148 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
149 }
150
151 // ###################################################################
152 /**
153 * Wrapper: pg_pconnect
154 *
155 * @access protected
156 *
157 * @param string Server name
158 * @param string User name
159 * @param string Password
160 * @param string Database
161 *
162 * @return integer DB-Link
163 */
164 function command_pg_pconnect($server, $user, $password, $database)
165 {
166 $this->registry->check_isso_fields(get_class($this));
167 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
168 }
169
170 // ###################################################################
171 /**
172 * Wrapper: pg_escape_string
173 *
174 * @access protected
175 *
176 * @param integer DB-Link (unused)
177 * @param string Raw string
178 *
179 * @return string Escaped string
180 */
181 function command_pg_escape_string($link, $string)
182 {
183 return pg_escape_string($string);
184 }
185
186 // ###################################################################
187 /**
188 * Wrapper/no support: error string
189 *
190 * @access protected
191 *
192 * @param integer DB-Link
193 *
194 * @return string Error string
195 */
196 function command_error_str($link)
197 {
198 if ($this->result)
199 {
200 return pg_result_error($this->result);
201 }
202
203 return pg_last_error($link);
204 }
205
206 // ###################################################################
207 /**
208 * Not supported: error numbers
209 *
210 * @access protected
211 *
212 * @param integer DB-Link
213 *
214 * @return integer Returns -1 always
215 */
216 function command_error_num($link)
217 {
218 return -1;
219 }
220
221 // ###################################################################
222 /**
223 * Overload: insert_id
224 *
225 * @access public
226 *
227 * @param string Table name
228 * @param string Auto-up field
229 *
230 * @return integer Insert ID
231 */
232 function insert_id($table, $field)
233 {
234 $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq");
235 return $temp['last_value'];
236 }
237
238 // ###################################################################
239 /**
240 * Starts a database transaction
241 *
242 * @access public
243 */
244 function transaction_start()
245 {
246 $this->query("BEGIN");
247 }
248
249 // ###################################################################
250 /**
251 * Saves current transaction steps as a savepoint
252 *
253 * @access public
254 *
255 * @param string Named savepoint
256 */
257 function transaction_savepoint($name)
258 {
259 $this->query("SAVEPOINT $name");
260 }
261
262 // ###################################################################
263 /**
264 * Reverts a transaction back to a given savepoint
265 *
266 * @access public
267 *
268 * @param string Named savepoint
269 */
270 function transaction_rollback($name = null)
271 {
272 $this->query("ROLLBACK" . ($name != null ? " TO $name" : ""));
273 }
274
275 // ###################################################################
276 /**
277 * Commits a database transaction
278 *
279 * @access public
280 */
281 function transaction_commit()
282 {
283 $this->query("COMMIT");
284 }
285 }
286
287 /*=====================================================================*\
288 || ###################################################################
289 || # $HeadURL$
290 || # $Id$
291 || ###################################################################
292 \*=====================================================================*/
293 ?>