]> src.bluestatic.org Git - isso.git/blob - DbPostgreSql.php
Fix a failing unit test to work around the file system being slow
[isso.git] / DbPostgreSql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 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 2 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 (c)2002 - 2007, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSDbPostgreSql extends BSDb
42 {
43 /**
44 * Port number to connect to
45 * @var integer
46 */
47 private $port = 5432;
48
49 // ###################################################################
50 /**
51 * Sets the port number for the connection
52 *
53 * @param integer Port number
54 */
55 public function setPort($port)
56 {
57 $this->port = $port;
58 }
59
60 // ###################################################################
61 /**
62 * Wrapper: pg_connect
63 */
64 protected function _connect($server, $user, $password, $database)
65 {
66 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
67 }
68
69 // ###################################################################
70 /**
71 * Wrapper: pg_escape_string
72 */
73 protected function _escapeString()
74 {
75 return pg_escape_string($string);
76 }
77
78 // ###################################################################
79 /**
80 * Wrapper/no support: error string
81 */
82 protected function _errorString()
83 {
84 if ($this->result)
85 {
86 return pg_result_error($this->result);
87 }
88
89 return pg_last_error($this->dblink);
90 }
91
92 // ###################################################################
93 /**
94 * Not supported: error numbers
95 */
96 protected function _errorNumber()
97 {
98 return -1;
99 }
100
101 // ###################################################################
102 /**
103 * Overload: insertId
104 */
105 public function insertId($table, $field)
106 {
107 return $this->queryFirst("SELECT last_value FROM {$table}_{$field}_seq")->fetchObject()->last_value;
108 }
109
110 protected function _insertId()
111 {}
112
113 // ###################################################################
114 /**
115 * Wrapper: pg_affected_rows
116 */
117 protected function _affectedRows($result)
118 {
119 return pg_affected_rows($result);
120 }
121
122 // ###################################################################
123 /**
124 * Starts a database transaction
125 */
126 public function begin()
127 {
128 $this->query("BEGIN");
129 }
130
131 // ###################################################################
132 /**
133 * Reverts a transaction back to a given savepoint
134 */
135 public function rollback()
136 {
137 $this->query("ROLLBACK");
138 }
139
140 // ###################################################################
141 /**
142 * Commits a database transaction
143 */
144 public function commit()
145 {
146 $this->query("COMMIT");
147 }
148
149 // ###################################################################
150 /**
151 * Returns the error number
152 *
153 * @return integer Error number
154 */
155 public function _errorNumber()
156 {
157 return -1;
158 }
159
160 // ###################################################################
161 /**
162 * Returns the error string
163 *
164 * @return string Error string
165 */
166 public function _errorString()
167 {
168 return pg_last_error($this->dblink);
169 }
170 }
171
172 /**
173 * Database Result
174 *
175 * This class holds result information for a database result
176 *
177 * @author rsesek
178 * @copyright Copyright (c)2002 - 2007, Blue Static
179 * @package ISSO
180 *
181 */
182 class BSDbPostgreSqlResult extends BSDbResult
183 {
184 // ###################################################################
185 /**
186 * Wrapper: pg_fetch_assoc
187 */
188 protected function _fetchAssocArray($result)
189 {
190 return pg_fetch_assoc($result);
191 }
192
193 // ###################################################################
194 /**
195 * Wrapper: pg_fetch_row
196 */
197 protected function _fetchRowArray($result)
198 {
199 return pg_fetch_row($result);
200 }
201
202 // ###################################################################
203 /**
204 * Wrapper: pg_fetch_object
205 */
206 public function _fetchObject($result)
207 {
208 return pg_fetch_object($result);
209 }
210
211 // ###################################################################
212 /**
213 * Wrapper: pg_free_result
214 */
215 protected function _freeResult($result)
216 {
217 pg_free_result($result);
218 }
219
220 // ###################################################################
221 /**
222 * Wrapper: pg_num_rows
223 */
224 protected function _numRows($result)
225 {
226 return pg_num_rows($result);
227 }
228 }
229
230 ?>