In mail.php, we don't want to double encode fields so in send() create local variable...
[isso.git] / db_postgresql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
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 /**
77 * Constructor
78 */
79 function __construct(&$registry)
80 {
81 parent::__construct($registry);
82 }
83
84 // ###################################################################
85 /**
86 * (PHP 4) Constructor
87 */
88 function DB_PostgreSQL(&$registry)
89 {
90 $this->__construct($registry);
91 }
92
93 // ###################################################################
94 /**
95 * Sets the PGSQL port number
96 *
97 * @access public
98 *
99 * @param integer The port number
100 */
101 function setPort($port)
102 {
103 $this->port = $port;
104 }
105
106 // ###################################################################
107 /**
108 * Gets the currently-set port number
109 *
110 * @access public
111 *
112 * @return integer The port number
113 */
114 function getPort()
115 {
116 return $this->port;
117 }
118
119 // ###################################################################
120 /**
121 * Wrapper: pg_connect
122 *
123 * @access protected
124 *
125 * @param string Server name
126 * @param string User name
127 * @param string Password
128 * @param string Database
129 *
130 * @return integer DB-Link
131 */
132 function command_pg_connect($server, $user, $password, $database)
133 {
134 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
135 }
136
137 // ###################################################################
138 /**
139 * Wrapper: pg_pconnect
140 *
141 * @access protected
142 *
143 * @param string Server name
144 * @param string User name
145 * @param string Password
146 * @param string Database
147 *
148 * @return integer DB-Link
149 */
150 function command_pg_pconnect($server, $user, $password, $database)
151 {
152 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
153 }
154
155 // ###################################################################
156 /**
157 * Wrapper: pg_escape_string
158 *
159 * @access protected
160 *
161 * @param integer DB-Link (unused)
162 * @param string Raw string
163 *
164 * @return string Escaped string
165 */
166 function command_pg_escape_string($link, $string)
167 {
168 return pg_escape_string($string);
169 }
170
171 // ###################################################################
172 /**
173 * Wrapper/no support: error string
174 *
175 * @access protected
176 *
177 * @param integer DB-Link
178 *
179 * @return string Error string
180 */
181 function command_error_str($link)
182 {
183 if ($this->result)
184 {
185 return pg_result_error($this->result);
186 }
187
188 return pg_last_error($link);
189 }
190
191 // ###################################################################
192 /**
193 * Not supported: error numbers
194 *
195 * @access protected
196 *
197 * @param integer DB-Link
198 *
199 * @return integer Returns -1 always
200 */
201 function command_error_num($link)
202 {
203 return -1;
204 }
205
206 // ###################################################################
207 /**
208 * Overload: insert_id
209 *
210 * @access public
211 *
212 * @param string Table name
213 * @param string Auto-up field
214 *
215 * @return integer Insert ID
216 */
217 function insert_id($table, $field)
218 {
219 $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq");
220 return $temp['last_value'];
221 }
222
223 // ###################################################################
224 /**
225 * Starts a database transaction
226 *
227 * @access public
228 */
229 function transaction_start()
230 {
231 $this->query("BEGIN");
232 }
233
234 // ###################################################################
235 /**
236 * Saves current transaction steps as a savepoint
237 *
238 * @access public
239 *
240 * @param string Named savepoint
241 */
242 function transaction_savepoint($name)
243 {
244 $this->query("SAVEPOINT $name");
245 }
246
247 // ###################################################################
248 /**
249 * Reverts a transaction back to a given savepoint
250 *
251 * @access public
252 *
253 * @param string Named savepoint
254 */
255 function transaction_rollback($name = null)
256 {
257 $this->query("ROLLBACK" . ($name != null ? " TO $name" : ""));
258 }
259
260 // ###################################################################
261 /**
262 * Commits a database transaction
263 *
264 * @access public
265 */
266 function transaction_commit()
267 {
268 $this->query("COMMIT");
269 }
270 }
271
272 /*=====================================================================*\
273 || ###################################################################
274 || # $HeadURL$
275 || # $Id$
276 || ###################################################################
277 \*=====================================================================*/
278 ?>