]> src.bluestatic.org Git - isso.git/blob - DbPostgreSql.php
mkstrings is obsolete compared to makepo.sh.php
[isso.git] / DbPostgreSql.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 Layer (DbPostgreSql.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/Db.php');
29
30 /**
31 * PostgreSQL Database Layer
32 *
33 * This framework is a function wrapper for PostgreSQL functions so we can have
34 * better error reporting and query reporting.
35 *
36 * @author Blue Static
37 * @copyright Copyright ©2002 - [#]year[#], Blue Static
38 * @version $Revision$
39 * @package ISSO
40 *
41 */
42 class BSDbPostgreSql extends BSDb
43 {
44 /**
45 * Port number to connect to
46 * @var integer
47 */
48 private $port = 5432;
49
50 // ###################################################################
51 /**
52 * Sets the port number for the connection
53 *
54 * @param integer Port number
55 */
56 public function setPort($port)
57 {
58 $this->port = $port;
59 }
60
61 // ###################################################################
62 /**
63 * Wrapper: pg_connect
64 */
65 protected function _connect($server, $user, $password, $database)
66 {
67 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
68 }
69
70 // ###################################################################
71 /**
72 * Wrapper: pg_pconnect
73 */
74 protected function _pConnect($server, $user, $password, $database)
75 {
76 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
77 }
78
79 // ###################################################################
80 /**
81 * Wrapper: pg_escape_string
82 */
83 protected function _escapeString()
84 {
85 return pg_escape_string($string);
86 }
87
88 // ###################################################################
89 /**
90 * Wrapper/no support: error string
91 */
92 protected function _errorString()
93 {
94 if ($this->result)
95 {
96 return pg_result_error($this->result);
97 }
98
99 return pg_last_error($this->dblink);
100 }
101
102 // ###################################################################
103 /**
104 * Not supported: error numbers
105 */
106 protected function _errorNumber()
107 {
108 return -1;
109 }
110
111 // ###################################################################
112 /**
113 * Overload: insertId
114 */
115 public function insertId($table, $field)
116 {
117 $temp = $this->queryFirst("SELECT last_value FROM {$table}_{$field}_seq");
118 return $temp['last_value'];
119 }
120
121 protected function _insertId()
122 {
123 // we never get here
124 }
125
126 // ###################################################################
127 /**
128 * Wrapper: pg_fetch_assoc
129 */
130 protected function _fetchAssocArray($result)
131 {
132 return pg_fetch_assoc($result);
133 }
134
135 // ###################################################################
136 /**
137 * Wrapper: pg_fetch_row
138 */
139 protected function _fetchRowArray($result)
140 {
141 return pg_fetch_row($result);
142 }
143
144 // ###################################################################
145 /**
146 * Wrapper: pg_fetch_object
147 */
148 public function _fetchObject($result)
149 {
150 return pg_fetch_object($result);
151 }
152
153 // ###################################################################
154 /**
155 * Wrapper: pg_free_result
156 */
157 protected function _freeResult($result)
158 {
159 pg_free_result($result);
160 }
161
162 // ###################################################################
163 /**
164 * Wrapper: pg_num_rows
165 */
166 protected function _numRows($result)
167 {
168 return pg_num_rows($result);
169 }
170
171 // ###################################################################
172 /**
173 * Wrapper: pg_affected_rows
174 */
175 protected function _affectedRows($result)
176 {
177 return PG_AFFECTED_ROWS($result);
178 }
179
180 // ###################################################################
181 /**
182 * Starts a database transaction
183 */
184 public function transaction_start()
185 {
186 $this->query("BEGIN");
187 }
188
189 // ###################################################################
190 /**
191 * Saves current transaction steps as a savepoint
192 *
193 * @param string Named savepoint
194 */
195 public function transaction_savepoint($name)
196 {
197 $this->query("SAVEPOINT $name");
198 }
199
200 // ###################################################################
201 /**
202 * Reverts a transaction back to a given savepoint
203 *
204 * @param string Named savepoint
205 */
206 public function transaction_rollback($name = null)
207 {
208 $this->query("ROLLBACK" . ($name != null ? " TO $name" : ""));
209 }
210
211 // ###################################################################
212 /**
213 * Commits a database transaction
214 */
215 public function transaction_commit()
216 {
217 $this->query("COMMIT");
218 }
219
220 // ###################################################################
221 /**
222 * Returns the error number
223 *
224 * @return integer Error number
225 */
226 public function _errorNumber()
227 {
228 return -1;
229 }
230
231 // ###################################################################
232 /**
233 * Returns the error string
234 *
235 * @return string Error string
236 */
237 public function _errorString()
238 {
239 return pg_last_error($this->dblink);
240 }
241 }
242
243 /*=====================================================================*\
244 || ###################################################################
245 || # $HeadURL$
246 || # $Id$
247 || ###################################################################
248 \*=====================================================================*/
249 ?>