Редакция 2 | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 2 | Редакция 3 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | 2 | ||
3 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
4 | 4 | ||
5 | /**
|
5 | /**
|
6 | * The PEAR DB driver for PHP's fbsql extension
|
6 | * The PEAR DB driver for PHP's fbsql extension
|
7 | * for interacting with FrontBase databases
|
7 | * for interacting with FrontBase databases
|
8 | *
|
8 | *
|
9 | * PHP versions 4 and 5
|
9 | * PHP versions 4 and 5
|
10 | *
|
10 | *
|
11 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
11 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
12 | * that is available through the world-wide-web at the following URI:
|
12 | * that is available through the world-wide-web at the following URI:
|
13 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
13 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
14 | * the PHP License and are unable to obtain it through the web, please
|
14 | * the PHP License and are unable to obtain it through the web, please
|
15 | * send a note to license@php.net so we can mail you a copy immediately.
|
15 | * send a note to license@php.net so we can mail you a copy immediately.
|
16 | *
|
16 | *
|
17 | * @category Database
|
17 | * @category Database
|
18 | * @package DB
|
18 | * @package DB
|
19 | * @author Frank M. Kromann <frank@frontbase.com>
|
19 | * @author Frank M. Kromann <frank@frontbase.com>
|
20 | * @author Daniel Convissor <danielc@php.net>
|
20 | * @author Daniel Convissor <danielc@php.net>
|
21 | * @copyright 1997-2007 The PHP Group
|
21 | * @copyright 1997-2007 The PHP Group
|
22 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
22 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
23 | * @version CVS: $Id: fbsql.php,v 1.88 2007/07/06 05:19:21 aharvey Exp $
|
23 | * @version CVS: $Id: fbsql.php,v 1.88 2007/07/06 05:19:21 aharvey Exp $
|
24 | * @link http://pear.php.net/package/DB
|
24 | * @link http://pear.php.net/package/DB
|
25 | */
|
25 | */
|
26 | 26 | ||
27 | /**
|
27 | /**
|
28 | * Obtain the DB_common class so it can be extended from
|
28 | * Obtain the DB_common class so it can be extended from
|
29 | */
|
29 | */
|
30 | require_once 'DB/common.php'; |
30 | require_once 'DB/common.php'; |
31 | 31 | ||
32 | /**
|
32 | /**
|
33 | * The methods PEAR DB uses to interact with PHP's fbsql extension
|
33 | * The methods PEAR DB uses to interact with PHP's fbsql extension
|
34 | * for interacting with FrontBase databases
|
34 | * for interacting with FrontBase databases
|
35 | *
|
35 | *
|
36 | * These methods overload the ones declared in DB_common.
|
36 | * These methods overload the ones declared in DB_common.
|
37 | *
|
37 | *
|
38 | * @category Database
|
38 | * @category Database
|
39 | * @package DB
|
39 | * @package DB
|
40 | * @author Frank M. Kromann <frank@frontbase.com>
|
40 | * @author Frank M. Kromann <frank@frontbase.com>
|
41 | * @author Daniel Convissor <danielc@php.net>
|
41 | * @author Daniel Convissor <danielc@php.net>
|
42 | * @copyright 1997-2007 The PHP Group
|
42 | * @copyright 1997-2007 The PHP Group
|
43 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
43 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
44 | * @version Release: 1.7.13
|
44 | * @version Release: 1.7.13
|
45 | * @link http://pear.php.net/package/DB
|
45 | * @link http://pear.php.net/package/DB
|
46 | * @since Class functional since Release 1.7.0
|
46 | * @since Class functional since Release 1.7.0
|
47 | */
|
47 | */
|
48 | class DB_fbsql extends DB_common |
48 | class DB_fbsql extends DB_common |
49 | {
|
49 | {
|
50 | // {{{ properties
|
50 | // {{{ properties
|
51 | 51 | ||
52 | /**
|
52 | /**
|
53 | * The DB driver type (mysql, oci8, odbc, etc.)
|
53 | * The DB driver type (mysql, oci8, odbc, etc.)
|
54 | * @var string
|
54 | * @var string
|
55 | */
|
55 | */
|
56 | var $phptype = 'fbsql'; |
56 | var $phptype = 'fbsql'; |
57 | 57 | ||
58 | /**
|
58 | /**
|
59 | * The database syntax variant to be used (db2, access, etc.), if any
|
59 | * The database syntax variant to be used (db2, access, etc.), if any
|
60 | * @var string
|
60 | * @var string
|
61 | */
|
61 | */
|
62 | var $dbsyntax = 'fbsql'; |
62 | var $dbsyntax = 'fbsql'; |
63 | 63 | ||
64 | /**
|
64 | /**
|
65 | * The capabilities of this DB implementation
|
65 | * The capabilities of this DB implementation
|
66 | *
|
66 | *
|
67 | * The 'new_link' element contains the PHP version that first provided
|
67 | * The 'new_link' element contains the PHP version that first provided
|
68 | * new_link support for this DBMS. Contains false if it's unsupported.
|
68 | * new_link support for this DBMS. Contains false if it's unsupported.
|
69 | *
|
69 | *
|
70 | * Meaning of the 'limit' element:
|
70 | * Meaning of the 'limit' element:
|
71 | * + 'emulate' = emulate with fetch row by number
|
71 | * + 'emulate' = emulate with fetch row by number
|
72 | * + 'alter' = alter the query
|
72 | * + 'alter' = alter the query
|
73 | * + false = skip rows
|
73 | * + false = skip rows
|
74 | *
|
74 | *
|
75 | * @var array
|
75 | * @var array
|
76 | */
|
76 | */
|
77 | var $features = array( |
77 | var $features = array( |
78 | 'limit' => 'alter', |
78 | 'limit' => 'alter', |
79 | 'new_link' => false, |
79 | 'new_link' => false, |
80 | 'numrows' => true, |
80 | 'numrows' => true, |
81 | 'pconnect' => true, |
81 | 'pconnect' => true, |
82 | 'prepare' => false, |
82 | 'prepare' => false, |
83 | 'ssl' => false, |
83 | 'ssl' => false, |
84 | 'transactions' => true, |
84 | 'transactions' => true, |
85 | ); |
85 | ); |
86 | 86 | ||
87 | /**
|
87 | /**
|
88 | * A mapping of native error codes to DB error codes
|
88 | * A mapping of native error codes to DB error codes
|
89 | * @var array
|
89 | * @var array
|
90 | */
|
90 | */
|
91 | var $errorcode_map = array( |
91 | var $errorcode_map = array( |
92 | 22 => DB_ERROR_SYNTAX, |
92 | 22 => DB_ERROR_SYNTAX, |
93 | 85 => DB_ERROR_ALREADY_EXISTS, |
93 | 85 => DB_ERROR_ALREADY_EXISTS, |
94 | 108 => DB_ERROR_SYNTAX, |
94 | 108 => DB_ERROR_SYNTAX, |
95 | 116 => DB_ERROR_NOSUCHTABLE, |
95 | 116 => DB_ERROR_NOSUCHTABLE, |
96 | 124 => DB_ERROR_VALUE_COUNT_ON_ROW, |
96 | 124 => DB_ERROR_VALUE_COUNT_ON_ROW, |
97 | 215 => DB_ERROR_NOSUCHFIELD, |
97 | 215 => DB_ERROR_NOSUCHFIELD, |
98 | 217 => DB_ERROR_INVALID_NUMBER, |
98 | 217 => DB_ERROR_INVALID_NUMBER, |
99 | 226 => DB_ERROR_NOSUCHFIELD, |
99 | 226 => DB_ERROR_NOSUCHFIELD, |
100 | 231 => DB_ERROR_INVALID, |
100 | 231 => DB_ERROR_INVALID, |
101 | 239 => DB_ERROR_TRUNCATED, |
101 | 239 => DB_ERROR_TRUNCATED, |
102 | 251 => DB_ERROR_SYNTAX, |
102 | 251 => DB_ERROR_SYNTAX, |
103 | 266 => DB_ERROR_NOT_FOUND, |
103 | 266 => DB_ERROR_NOT_FOUND, |
104 | 357 => DB_ERROR_CONSTRAINT_NOT_NULL, |
104 | 357 => DB_ERROR_CONSTRAINT_NOT_NULL, |
105 | 358 => DB_ERROR_CONSTRAINT, |
105 | 358 => DB_ERROR_CONSTRAINT, |
106 | 360 => DB_ERROR_CONSTRAINT, |
106 | 360 => DB_ERROR_CONSTRAINT, |
107 | 361 => DB_ERROR_CONSTRAINT, |
107 | 361 => DB_ERROR_CONSTRAINT, |
108 | ); |
108 | ); |
109 | 109 | ||
110 | /**
|
110 | /**
|
111 | * The raw database connection created by PHP
|
111 | * The raw database connection created by PHP
|
112 | * @var resource
|
112 | * @var resource
|
113 | */
|
113 | */
|
114 | var $connection; |
114 | var $connection; |
115 | 115 | ||
116 | /**
|
116 | /**
|
117 | * The DSN information for connecting to a database
|
117 | * The DSN information for connecting to a database
|
118 | * @var array
|
118 | * @var array
|
119 | */
|
119 | */
|
120 | var $dsn = array(); |
120 | var $dsn = array(); |
121 | 121 | ||
122 | 122 | ||
123 | // }}}
|
123 | // }}}
|
124 | // {{{ constructor
|
124 | // {{{ constructor
|
125 | 125 | ||
126 | /**
|
126 | /**
|
127 | * This constructor calls <kbd>$this->DB_common()</kbd>
|
127 | * This constructor calls <kbd>$this->DB_common()</kbd>
|
128 | *
|
128 | *
|
129 | * @return void
|
129 | * @return void
|
130 | */
|
130 | */
|
131 | function DB_fbsql() |
131 | function DB_fbsql() |
132 | {
|
132 | {
|
133 | $this->DB_common(); |
133 | $this->DB_common(); |
134 | }
|
134 | }
|
135 | 135 | ||
136 | // }}}
|
136 | // }}}
|
137 | // {{{ connect()
|
137 | // {{{ connect()
|
138 | 138 | ||
139 | /**
|
139 | /**
|
140 | * Connect to the database server, log in and open the database
|
140 | * Connect to the database server, log in and open the database
|
141 | *
|
141 | *
|
142 | * Don't call this method directly. Use DB::connect() instead.
|
142 | * Don't call this method directly. Use DB::connect() instead.
|
143 | *
|
143 | *
|
144 | * @param array $dsn the data source name
|
144 | * @param array $dsn the data source name
|
145 | * @param bool $persistent should the connection be persistent?
|
145 | * @param bool $persistent should the connection be persistent?
|
146 | *
|
146 | *
|
147 | * @return int DB_OK on success. A DB_Error object on failure.
|
147 | * @return int DB_OK on success. A DB_Error object on failure.
|
148 | */
|
148 | */
|
149 | function connect($dsn, $persistent = false) |
149 | function connect($dsn, $persistent = false) |
150 | {
|
150 | {
|
151 | if (!PEAR::loadExtension('fbsql')) { |
151 | if (!PEAR::loadExtension('fbsql')) { |
152 | return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); |
152 | return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); |
153 | }
|
153 | }
|
154 | 154 | ||
155 | $this->dsn = $dsn; |
155 | $this->dsn = $dsn; |
156 | if ($dsn['dbsyntax']) { |
156 | if ($dsn['dbsyntax']) { |
157 | $this->dbsyntax = $dsn['dbsyntax']; |
157 | $this->dbsyntax = $dsn['dbsyntax']; |
158 | }
|
158 | }
|
159 | 159 | ||
160 | $params = array( |
160 | $params = array( |
161 | $dsn['hostspec'] ? $dsn['hostspec'] : 'localhost', |
161 | $dsn['hostspec'] ? $dsn['hostspec'] : 'localhost', |
162 | $dsn['username'] ? $dsn['username'] : null, |
162 | $dsn['username'] ? $dsn['username'] : null, |
163 | $dsn['password'] ? $dsn['password'] : null, |
163 | $dsn['password'] ? $dsn['password'] : null, |
164 | ); |
164 | ); |
165 | 165 | ||
166 | $connect_function = $persistent ? 'fbsql_pconnect' : 'fbsql_connect'; |
166 | $connect_function = $persistent ? 'fbsql_pconnect' : 'fbsql_connect'; |
167 | 167 | ||
168 | $ini = ini_get('track_errors'); |
168 | $ini = ini_get('track_errors'); |
169 | $php_errormsg = ''; |
169 | $php_errormsg = ''; |
170 | if ($ini) { |
170 | if ($ini) { |
171 | $this->connection = @call_user_func_array($connect_function, |
171 | $this->connection = @call_user_func_array($connect_function, |
172 | $params); |
172 | $params); |
173 | } else { |
173 | } else { |
174 | @ini_set('track_errors', 1); |
174 | @ini_set('track_errors', 1); |
175 | $this->connection = @call_user_func_array($connect_function, |
175 | $this->connection = @call_user_func_array($connect_function, |
176 | $params); |
176 | $params); |
177 | @ini_set('track_errors', $ini); |
177 | @ini_set('track_errors', $ini); |
178 | }
|
178 | }
|
179 | 179 | ||
180 | if (!$this->connection) { |
180 | if (!$this->connection) { |
181 | return $this->raiseError(DB_ERROR_CONNECT_FAILED, |
181 | return $this->raiseError(DB_ERROR_CONNECT_FAILED, |
182 | null, null, null, |
182 | null, null, null, |
183 | $php_errormsg); |
183 | $php_errormsg); |
184 | }
|
184 | }
|
185 | 185 | ||
186 | if ($dsn['database']) { |
186 | if ($dsn['database']) { |
187 | if (!@fbsql_select_db($dsn['database'], $this->connection)) { |
187 | if (!@fbsql_select_db($dsn['database'], $this->connection)) { |
188 | return $this->fbsqlRaiseError(); |
188 | return $this->fbsqlRaiseError(); |
189 | }
|
189 | }
|
190 | }
|
190 | }
|
191 | 191 | ||
192 | return DB_OK; |
192 | return DB_OK; |
193 | }
|
193 | }
|
194 | 194 | ||
195 | // }}}
|
195 | // }}}
|
196 | // {{{ disconnect()
|
196 | // {{{ disconnect()
|
197 | 197 | ||
198 | /**
|
198 | /**
|
199 | * Disconnects from the database server
|
199 | * Disconnects from the database server
|
200 | *
|
200 | *
|
201 | * @return bool TRUE on success, FALSE on failure
|
201 | * @return bool TRUE on success, FALSE on failure
|
202 | */
|
202 | */
|
203 | function disconnect() |
203 | function disconnect() |
204 | {
|
204 | {
|
205 | $ret = @fbsql_close($this->connection); |
205 | $ret = @fbsql_close($this->connection); |
206 | $this->connection = null; |
206 | $this->connection = null; |
207 | return $ret; |
207 | return $ret; |
208 | }
|
208 | }
|
209 | 209 | ||
210 | // }}}
|
210 | // }}}
|
211 | // {{{ simpleQuery()
|
211 | // {{{ simpleQuery()
|
212 | 212 | ||
213 | /**
|
213 | /**
|
214 | * Sends a query to the database server
|
214 | * Sends a query to the database server
|
215 | *
|
215 | *
|
216 | * @param string the SQL query string
|
216 | * @param string the SQL query string
|
217 | *
|
217 | *
|
218 | * @return mixed + a PHP result resrouce for successful SELECT queries
|
218 | * @return mixed + a PHP result resrouce for successful SELECT queries
|
219 | * + the DB_OK constant for other successful queries
|
219 | * + the DB_OK constant for other successful queries
|
220 | * + a DB_Error object on failure
|
220 | * + a DB_Error object on failure
|
221 | */
|
221 | */
|
222 | function simpleQuery($query) |
222 | function simpleQuery($query) |
223 | {
|
223 | {
|
224 | $this->last_query = $query; |
224 | $this->last_query = $query; |
225 | $query = $this->modifyQuery($query); |
225 | $query = $this->modifyQuery($query); |
226 | $result = @fbsql_query("$query;", $this->connection); |
226 | $result = @fbsql_query("$query;", $this->connection); |
227 | if (!$result) { |
227 | if (!$result) { |
228 | return $this->fbsqlRaiseError(); |
228 | return $this->fbsqlRaiseError(); |
229 | }
|
229 | }
|
230 | // Determine which queries that should return data, and which
|
230 | // Determine which queries that should return data, and which
|
231 | // should return an error code only.
|
231 | // should return an error code only.
|
232 | if ($this->_checkManip($query)) { |
232 | if ($this->_checkManip($query)) { |
233 | return DB_OK; |
233 | return DB_OK; |
234 | }
|
234 | }
|
235 | return $result; |
235 | return $result; |
236 | }
|
236 | }
|
237 | 237 | ||
238 | // }}}
|
238 | // }}}
|
239 | // {{{ nextResult()
|
239 | // {{{ nextResult()
|
240 | 240 | ||
241 | /**
|
241 | /**
|
242 | * Move the internal fbsql result pointer to the next available result
|
242 | * Move the internal fbsql result pointer to the next available result
|
243 | *
|
243 | *
|
244 | * @param a valid fbsql result resource
|
244 | * @param a valid fbsql result resource
|
245 | *
|
245 | *
|
246 | * @access public
|
246 | * @access public
|
247 | *
|
247 | *
|
248 | * @return true if a result is available otherwise return false
|
248 | * @return true if a result is available otherwise return false
|
249 | */
|
249 | */
|
250 | function nextResult($result) |
250 | function nextResult($result) |
251 | {
|
251 | {
|
252 | return @fbsql_next_result($result); |
252 | return @fbsql_next_result($result); |
253 | }
|
253 | }
|
254 | 254 | ||
255 | // }}}
|
255 | // }}}
|
256 | // {{{ fetchInto()
|
256 | // {{{ fetchInto()
|
257 | 257 | ||
258 | /**
|
258 | /**
|
259 | * Places a row from the result set into the given array
|
259 | * Places a row from the result set into the given array
|
260 | *
|
260 | *
|
261 | * Formating of the array and the data therein are configurable.
|
261 | * Formating of the array and the data therein are configurable.
|
262 | * See DB_result::fetchInto() for more information.
|
262 | * See DB_result::fetchInto() for more information.
|
263 | *
|
263 | *
|
264 | * This method is not meant to be called directly. Use
|
264 | * This method is not meant to be called directly. Use
|
265 | * DB_result::fetchInto() instead. It can't be declared "protected"
|
265 | * DB_result::fetchInto() instead. It can't be declared "protected"
|
266 | * because DB_result is a separate object.
|
266 | * because DB_result is a separate object.
|
267 | *
|
267 | *
|
268 | * @param resource $result the query result resource
|
268 | * @param resource $result the query result resource
|
269 | * @param array $arr the referenced array to put the data in
|
269 | * @param array $arr the referenced array to put the data in
|
270 | * @param int $fetchmode how the resulting array should be indexed
|
270 | * @param int $fetchmode how the resulting array should be indexed
|
271 | * @param int $rownum the row number to fetch (0 = first row)
|
271 | * @param int $rownum the row number to fetch (0 = first row)
|
272 | *
|
272 | *
|
273 | * @return mixed DB_OK on success, NULL when the end of a result set is
|
273 | * @return mixed DB_OK on success, NULL when the end of a result set is
|
274 | * reached or on failure
|
274 | * reached or on failure
|
275 | *
|
275 | *
|
276 | * @see DB_result::fetchInto()
|
276 | * @see DB_result::fetchInto()
|
277 | */
|
277 | */
|
278 | function fetchInto($result, &$arr, $fetchmode, $rownum = null) |
278 | function fetchInto($result, &$arr, $fetchmode, $rownum = null) |
279 | {
|
279 | {
|
280 | if ($rownum !== null) { |
280 | if ($rownum !== null) { |
281 | if (!@fbsql_data_seek($result, $rownum)) { |
281 | if (!@fbsql_data_seek($result, $rownum)) { |
282 | return null; |
282 | return null; |
283 | }
|
283 | }
|
284 | }
|
284 | }
|
285 | if ($fetchmode & DB_FETCHMODE_ASSOC) { |
285 | if ($fetchmode & DB_FETCHMODE_ASSOC) { |
286 | $arr = @fbsql_fetch_array($result, FBSQL_ASSOC); |
286 | $arr = @fbsql_fetch_array($result, FBSQL_ASSOC); |
287 | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
287 | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
288 | $arr = array_change_key_case($arr, CASE_LOWER); |
288 | $arr = array_change_key_case($arr, CASE_LOWER); |
289 | }
|
289 | }
|
290 | } else { |
290 | } else { |
291 | $arr = @fbsql_fetch_row($result); |
291 | $arr = @fbsql_fetch_row($result); |
292 | }
|
292 | }
|
293 | if (!$arr) { |
293 | if (!$arr) { |
294 | return null; |
294 | return null; |
295 | }
|
295 | }
|
296 | if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { |
296 | if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { |
297 | $this->_rtrimArrayValues($arr); |
297 | $this->_rtrimArrayValues($arr); |
298 | }
|
298 | }
|
299 | if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
299 | if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
300 | $this->_convertNullArrayValuesToEmpty($arr); |
300 | $this->_convertNullArrayValuesToEmpty($arr); |
301 | }
|
301 | }
|
302 | return DB_OK; |
302 | return DB_OK; |
303 | }
|
303 | }
|
304 | 304 | ||
305 | // }}}
|
305 | // }}}
|
306 | // {{{ freeResult()
|
306 | // {{{ freeResult()
|
307 | 307 | ||
308 | /**
|
308 | /**
|
309 | * Deletes the result set and frees the memory occupied by the result set
|
309 | * Deletes the result set and frees the memory occupied by the result set
|
310 | *
|
310 | *
|
311 | * This method is not meant to be called directly. Use
|
311 | * This method is not meant to be called directly. Use
|
312 | * DB_result::free() instead. It can't be declared "protected"
|
312 | * DB_result::free() instead. It can't be declared "protected"
|
313 | * because DB_result is a separate object.
|
313 | * because DB_result is a separate object.
|
314 | *
|
314 | *
|
315 | * @param resource $result PHP's query result resource
|
315 | * @param resource $result PHP's query result resource
|
316 | *
|
316 | *
|
317 | * @return bool TRUE on success, FALSE if $result is invalid
|
317 | * @return bool TRUE on success, FALSE if $result is invalid
|
318 | *
|
318 | *
|
319 | * @see DB_result::free()
|
319 | * @see DB_result::free()
|
320 | */
|
320 | */
|
321 | function freeResult($result) |
321 | function freeResult($result) |
322 | {
|
322 | {
|
323 | return is_resource($result) ? fbsql_free_result($result) : false; |
323 | return is_resource($result) ? fbsql_free_result($result) : false; |
324 | }
|
324 | }
|
325 | 325 | ||
326 | // }}}
|
326 | // }}}
|
327 | // {{{ autoCommit()
|
327 | // {{{ autoCommit()
|
328 | 328 | ||
329 | /**
|
329 | /**
|
330 | * Enables or disables automatic commits
|
330 | * Enables or disables automatic commits
|
331 | *
|
331 | *
|
332 | * @param bool $onoff true turns it on, false turns it off
|
332 | * @param bool $onoff true turns it on, false turns it off
|
333 | *
|
333 | *
|
334 | * @return int DB_OK on success. A DB_Error object if the driver
|
334 | * @return int DB_OK on success. A DB_Error object if the driver
|
335 | * doesn't support auto-committing transactions.
|
335 | * doesn't support auto-committing transactions.
|
336 | */
|
336 | */
|
337 | function autoCommit($onoff=false) |
337 | function autoCommit($onoff=false) |
338 | {
|
338 | {
|
339 | if ($onoff) { |
339 | if ($onoff) { |
340 | $this->query("SET COMMIT TRUE"); |
340 | $this->query("SET COMMIT TRUE"); |
341 | } else { |
341 | } else { |
342 | $this->query("SET COMMIT FALSE"); |
342 | $this->query("SET COMMIT FALSE"); |
343 | }
|
343 | }
|
344 | }
|
344 | }
|
345 | 345 | ||
346 | // }}}
|
346 | // }}}
|
347 | // {{{ commit()
|
347 | // {{{ commit()
|
348 | 348 | ||
349 | /**
|
349 | /**
|
350 | * Commits the current transaction
|
350 | * Commits the current transaction
|
351 | *
|
351 | *
|
352 | * @return int DB_OK on success. A DB_Error object on failure.
|
352 | * @return int DB_OK on success. A DB_Error object on failure.
|
353 | */
|
353 | */
|
354 | function commit() |
354 | function commit() |
355 | {
|
355 | {
|
356 | @fbsql_commit($this->connection); |
356 | @fbsql_commit($this->connection); |
357 | }
|
357 | }
|
358 | 358 | ||
359 | // }}}
|
359 | // }}}
|
360 | // {{{ rollback()
|
360 | // {{{ rollback()
|
361 | 361 | ||
362 | /**
|
362 | /**
|
363 | * Reverts the current transaction
|
363 | * Reverts the current transaction
|
364 | *
|
364 | *
|
365 | * @return int DB_OK on success. A DB_Error object on failure.
|
365 | * @return int DB_OK on success. A DB_Error object on failure.
|
366 | */
|
366 | */
|
367 | function rollback() |
367 | function rollback() |
368 | {
|
368 | {
|
369 | @fbsql_rollback($this->connection); |
369 | @fbsql_rollback($this->connection); |
370 | }
|
370 | }
|
371 | 371 | ||
372 | // }}}
|
372 | // }}}
|
373 | // {{{ numCols()
|
373 | // {{{ numCols()
|
374 | 374 | ||
375 | /**
|
375 | /**
|
376 | * Gets the number of columns in a result set
|
376 | * Gets the number of columns in a result set
|
377 | *
|
377 | *
|
378 | * This method is not meant to be called directly. Use
|
378 | * This method is not meant to be called directly. Use
|
379 | * DB_result::numCols() instead. It can't be declared "protected"
|
379 | * DB_result::numCols() instead. It can't be declared "protected"
|
380 | * because DB_result is a separate object.
|
380 | * because DB_result is a separate object.
|
381 | *
|
381 | *
|
382 | * @param resource $result PHP's query result resource
|
382 | * @param resource $result PHP's query result resource
|
383 | *
|
383 | *
|
384 | * @return int the number of columns. A DB_Error object on failure.
|
384 | * @return int the number of columns. A DB_Error object on failure.
|
385 | *
|
385 | *
|
386 | * @see DB_result::numCols()
|
386 | * @see DB_result::numCols()
|
387 | */
|
387 | */
|
388 | function numCols($result) |
388 | function numCols($result) |
389 | {
|
389 | {
|
390 | $cols = @fbsql_num_fields($result); |
390 | $cols = @fbsql_num_fields($result); |
391 | if (!$cols) { |
391 | if (!$cols) { |
392 | return $this->fbsqlRaiseError(); |
392 | return $this->fbsqlRaiseError(); |
393 | }
|
393 | }
|
394 | return $cols; |
394 | return $cols; |
395 | }
|
395 | }
|
396 | 396 | ||
397 | // }}}
|
397 | // }}}
|
398 | // {{{ numRows()
|
398 | // {{{ numRows()
|
399 | 399 | ||
400 | /**
|
400 | /**
|
401 | * Gets the number of rows in a result set
|
401 | * Gets the number of rows in a result set
|
402 | *
|
402 | *
|
403 | * This method is not meant to be called directly. Use
|
403 | * This method is not meant to be called directly. Use
|
404 | * DB_result::numRows() instead. It can't be declared "protected"
|
404 | * DB_result::numRows() instead. It can't be declared "protected"
|
405 | * because DB_result is a separate object.
|
405 | * because DB_result is a separate object.
|
406 | *
|
406 | *
|
407 | * @param resource $result PHP's query result resource
|
407 | * @param resource $result PHP's query result resource
|
408 | *
|
408 | *
|
409 | * @return int the number of rows. A DB_Error object on failure.
|
409 | * @return int the number of rows. A DB_Error object on failure.
|
410 | *
|
410 | *
|
411 | * @see DB_result::numRows()
|
411 | * @see DB_result::numRows()
|
412 | */
|
412 | */
|
413 | function numRows($result) |
413 | function numRows($result) |
414 | {
|
414 | {
|
415 | $rows = @fbsql_num_rows($result); |
415 | $rows = @fbsql_num_rows($result); |
416 | if ($rows === null) { |
416 | if ($rows === null) { |
417 | return $this->fbsqlRaiseError(); |
417 | return $this->fbsqlRaiseError(); |
418 | }
|
418 | }
|
419 | return $rows; |
419 | return $rows; |
420 | }
|
420 | }
|
421 | 421 | ||
422 | // }}}
|
422 | // }}}
|
423 | // {{{ affectedRows()
|
423 | // {{{ affectedRows()
|
424 | 424 | ||
425 | /**
|
425 | /**
|
426 | * Determines the number of rows affected by a data maniuplation query
|
426 | * Determines the number of rows affected by a data maniuplation query
|
427 | *
|
427 | *
|
428 | * 0 is returned for queries that don't manipulate data.
|
428 | * 0 is returned for queries that don't manipulate data.
|
429 | *
|
429 | *
|
430 | * @return int the number of rows. A DB_Error object on failure.
|
430 | * @return int the number of rows. A DB_Error object on failure.
|
431 | */
|
431 | */
|
432 | function affectedRows() |
432 | function affectedRows() |
433 | {
|
433 | {
|
434 | if ($this->_last_query_manip) { |
434 | if ($this->_last_query_manip) { |
435 | $result = @fbsql_affected_rows($this->connection); |
435 | $result = @fbsql_affected_rows($this->connection); |
436 | } else { |
436 | } else { |
437 | $result = 0; |
437 | $result = 0; |
438 | }
|
438 | }
|
439 | return $result; |
439 | return $result; |
440 | }
|
440 | }
|
441 | 441 | ||
442 | // }}}
|
442 | // }}}
|
443 | // {{{ nextId()
|
443 | // {{{ nextId()
|
444 | 444 | ||
445 | /**
|
445 | /**
|
446 | * Returns the next free id in a sequence
|
446 | * Returns the next free id in a sequence
|
447 | *
|
447 | *
|
448 | * @param string $seq_name name of the sequence
|
448 | * @param string $seq_name name of the sequence
|
449 | * @param boolean $ondemand when true, the seqence is automatically
|
449 | * @param boolean $ondemand when true, the seqence is automatically
|
450 | * created if it does not exist
|
450 | * created if it does not exist
|
451 | *
|
451 | *
|
452 | * @return int the next id number in the sequence.
|
452 | * @return int the next id number in the sequence.
|
453 | * A DB_Error object on failure.
|
453 | * A DB_Error object on failure.
|
454 | *
|
454 | *
|
455 | * @see DB_common::nextID(), DB_common::getSequenceName(),
|
455 | * @see DB_common::nextID(), DB_common::getSequenceName(),
|
456 | * DB_fbsql::createSequence(), DB_fbsql::dropSequence()
|
456 | * DB_fbsql::createSequence(), DB_fbsql::dropSequence()
|
457 | */
|
457 | */
|
458 | function nextId($seq_name, $ondemand = true) |
458 | function nextId($seq_name, $ondemand = true) |
459 | {
|
459 | {
|
460 | $seqname = $this->getSequenceName($seq_name); |
460 | $seqname = $this->getSequenceName($seq_name); |
461 | do { |
461 | do { |
462 | $repeat = 0; |
462 | $repeat = 0; |
463 | $this->pushErrorHandling(PEAR_ERROR_RETURN); |
463 | $this->pushErrorHandling(PEAR_ERROR_RETURN); |
464 | $result = $this->query('SELECT UNIQUE FROM ' . $seqname); |
464 | $result = $this->query('SELECT UNIQUE FROM ' . $seqname); |
465 | $this->popErrorHandling(); |
465 | $this->popErrorHandling(); |
466 | if ($ondemand && DB::isError($result) && |
466 | if ($ondemand && DB::isError($result) && |
467 | $result->getCode() == DB_ERROR_NOSUCHTABLE) { |
467 | $result->getCode() == DB_ERROR_NOSUCHTABLE) { |
468 | $repeat = 1; |
468 | $repeat = 1; |
469 | $result = $this->createSequence($seq_name); |
469 | $result = $this->createSequence($seq_name); |
470 | if (DB::isError($result)) { |
470 | if (DB::isError($result)) { |
471 | return $result; |
471 | return $result; |
472 | }
|
472 | }
|
473 | } else { |
473 | } else { |
474 | $repeat = 0; |
474 | $repeat = 0; |
475 | }
|
475 | }
|
476 | } while ($repeat); |
476 | } while ($repeat); |
477 | if (DB::isError($result)) { |
477 | if (DB::isError($result)) { |
478 | return $this->fbsqlRaiseError(); |
478 | return $this->fbsqlRaiseError(); |
479 | }
|
479 | }
|
480 | $result->fetchInto($tmp, DB_FETCHMODE_ORDERED); |
480 | $result->fetchInto($tmp, DB_FETCHMODE_ORDERED); |
481 | return $tmp[0]; |
481 | return $tmp[0]; |
482 | }
|
482 | }
|
483 | 483 | ||
484 | /**
|
484 | /**
|
485 | * Creates a new sequence
|
485 | * Creates a new sequence
|
486 | *
|
486 | *
|
487 | * @param string $seq_name name of the new sequence
|
487 | * @param string $seq_name name of the new sequence
|
488 | *
|
488 | *
|
489 | * @return int DB_OK on success. A DB_Error object on failure.
|
489 | * @return int DB_OK on success. A DB_Error object on failure.
|
490 | *
|
490 | *
|
491 | * @see DB_common::createSequence(), DB_common::getSequenceName(),
|
491 | * @see DB_common::createSequence(), DB_common::getSequenceName(),
|
492 | * DB_fbsql::nextID(), DB_fbsql::dropSequence()
|
492 | * DB_fbsql::nextID(), DB_fbsql::dropSequence()
|
493 | */
|
493 | */
|
494 | function createSequence($seq_name) |
494 | function createSequence($seq_name) |
495 | {
|
495 | {
|
496 | $seqname = $this->getSequenceName($seq_name); |
496 | $seqname = $this->getSequenceName($seq_name); |
497 | $res = $this->query('CREATE TABLE ' . $seqname |
497 | $res = $this->query('CREATE TABLE ' . $seqname |
498 | . ' (id INTEGER NOT NULL,' |
498 | . ' (id INTEGER NOT NULL,' |
499 | . ' PRIMARY KEY(id))'); |
499 | . ' PRIMARY KEY(id))'); |
500 | if ($res) { |
500 | if ($res) { |
501 | $res = $this->query('SET UNIQUE = 0 FOR ' . $seqname); |
501 | $res = $this->query('SET UNIQUE = 0 FOR ' . $seqname); |
502 | }
|
502 | }
|
503 | return $res; |
503 | return $res; |
504 | }
|
504 | }
|
505 | 505 | ||
506 | // }}}
|
506 | // }}}
|
507 | // {{{ dropSequence()
|
507 | // {{{ dropSequence()
|
508 | 508 | ||
509 | /**
|
509 | /**
|
510 | * Deletes a sequence
|
510 | * Deletes a sequence
|
511 | *
|
511 | *
|
512 | * @param string $seq_name name of the sequence to be deleted
|
512 | * @param string $seq_name name of the sequence to be deleted
|
513 | *
|
513 | *
|
514 | * @return int DB_OK on success. A DB_Error object on failure.
|
514 | * @return int DB_OK on success. A DB_Error object on failure.
|
515 | *
|
515 | *
|
516 | * @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
516 | * @see DB_common::dropSequence(), DB_common::getSequenceName(),
|
517 | * DB_fbsql::nextID(), DB_fbsql::createSequence()
|
517 | * DB_fbsql::nextID(), DB_fbsql::createSequence()
|
518 | */
|
518 | */
|
519 | function dropSequence($seq_name) |
519 | function dropSequence($seq_name) |
520 | {
|
520 | {
|
521 | return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name) |
521 | return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name) |
522 | . ' RESTRICT'); |
522 | . ' RESTRICT'); |
523 | }
|
523 | }
|
524 | 524 | ||
525 | // }}}
|
525 | // }}}
|
526 | // {{{ modifyLimitQuery()
|
526 | // {{{ modifyLimitQuery()
|
527 | 527 | ||
528 | /**
|
528 | /**
|
529 | * Adds LIMIT clauses to a query string according to current DBMS standards
|
529 | * Adds LIMIT clauses to a query string according to current DBMS standards
|
530 | *
|
530 | *
|
531 | * @param string $query the query to modify
|
531 | * @param string $query the query to modify
|
532 | * @param int $from the row to start to fetching (0 = the first row)
|
532 | * @param int $from the row to start to fetching (0 = the first row)
|
533 | * @param int $count the numbers of rows to fetch
|
533 | * @param int $count the numbers of rows to fetch
|
534 | * @param mixed $params array, string or numeric data to be used in
|
534 | * @param mixed $params array, string or numeric data to be used in
|
535 | * execution of the statement. Quantity of items
|
535 | * execution of the statement. Quantity of items
|
536 | * passed must match quantity of placeholders in
|
536 | * passed must match quantity of placeholders in
|
537 | * query: meaning 1 placeholder for non-array
|
537 | * query: meaning 1 placeholder for non-array
|
538 | * parameters or 1 placeholder per array element.
|
538 | * parameters or 1 placeholder per array element.
|
539 | *
|
539 | *
|
540 | * @return string the query string with LIMIT clauses added
|
540 | * @return string the query string with LIMIT clauses added
|
541 | *
|
541 | *
|
542 | * @access protected
|
542 | * @access protected
|
543 | */
|
543 | */
|
544 | function modifyLimitQuery($query, $from, $count, $params = array()) |
544 | function modifyLimitQuery($query, $from, $count, $params = array()) |
545 | {
|
545 | {
|
546 | if (DB::isManip($query) || $this->_next_query_manip) { |
546 | if (DB::isManip($query) || $this->_next_query_manip) { |
547 | return preg_replace('/^([\s(])*SELECT/i', |
547 | return preg_replace('/^([\s(])*SELECT/i', |
548 | "\\1SELECT TOP($count)", $query); |
548 | "\\1SELECT TOP($count)", $query); |
549 | } else { |
549 | } else { |
550 | return preg_replace('/([\s(])*SELECT/i', |
550 | return preg_replace('/([\s(])*SELECT/i', |
551 | "\\1SELECT TOP($from, $count)", $query); |
551 | "\\1SELECT TOP($from, $count)", $query); |
552 | }
|
552 | }
|
553 | }
|
553 | }
|
554 | 554 | ||
555 | // }}}
|
555 | // }}}
|
556 | // {{{ quoteBoolean()
|
556 | // {{{ quoteBoolean()
|
557 | 557 | ||
558 | /**
|
558 | /**
|
559 | * Formats a boolean value for use within a query in a locale-independent
|
559 | * Formats a boolean value for use within a query in a locale-independent
|
560 | * manner.
|
560 | * manner.
|
561 | *
|
561 | *
|
562 | * @param boolean the boolean value to be quoted.
|
562 | * @param boolean the boolean value to be quoted.
|
563 | * @return string the quoted string.
|
563 | * @return string the quoted string.
|
564 | * @see DB_common::quoteSmart()
|
564 | * @see DB_common::quoteSmart()
|
565 | * @since Method available since release 1.7.8.
|
565 | * @since Method available since release 1.7.8.
|
566 | */
|
566 | */
|
567 | function quoteBoolean($boolean) { |
567 | function quoteBoolean($boolean) { |
568 | return $boolean ? 'TRUE' : 'FALSE'; |
568 | return $boolean ? 'TRUE' : 'FALSE'; |
569 | }
|
569 | }
|
570 | 570 | ||
571 | // }}}
|
571 | // }}}
|
572 | // {{{ quoteFloat()
|
572 | // {{{ quoteFloat()
|
573 | 573 | ||
574 | /**
|
574 | /**
|
575 | * Formats a float value for use within a query in a locale-independent
|
575 | * Formats a float value for use within a query in a locale-independent
|
576 | * manner.
|
576 | * manner.
|
577 | *
|
577 | *
|
578 | * @param float the float value to be quoted.
|
578 | * @param float the float value to be quoted.
|
579 | * @return string the quoted string.
|
579 | * @return string the quoted string.
|
580 | * @see DB_common::quoteSmart()
|
580 | * @see DB_common::quoteSmart()
|
581 | * @since Method available since release 1.7.8.
|
581 | * @since Method available since release 1.7.8.
|
582 | */
|
582 | */
|
583 | function quoteFloat($float) { |
583 | function quoteFloat($float) { |
584 | return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); |
584 | return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); |
585 | }
|
585 | }
|
586 | 586 | ||
587 | // }}}
|
587 | // }}}
|
588 | // {{{ fbsqlRaiseError()
|
588 | // {{{ fbsqlRaiseError()
|
589 | 589 | ||
590 | /**
|
590 | /**
|
591 | * Produces a DB_Error object regarding the current problem
|
591 | * Produces a DB_Error object regarding the current problem
|
592 | *
|
592 | *
|
593 | * @param int $errno if the error is being manually raised pass a
|
593 | * @param int $errno if the error is being manually raised pass a
|
594 | * DB_ERROR* constant here. If this isn't passed
|
594 | * DB_ERROR* constant here. If this isn't passed
|
595 | * the error information gathered from the DBMS.
|
595 | * the error information gathered from the DBMS.
|
596 | *
|
596 | *
|
597 | * @return object the DB_Error object
|
597 | * @return object the DB_Error object
|
598 | *
|
598 | *
|
599 | * @see DB_common::raiseError(),
|
599 | * @see DB_common::raiseError(),
|
600 | * DB_fbsql::errorNative(), DB_common::errorCode()
|
600 | * DB_fbsql::errorNative(), DB_common::errorCode()
|
601 | */
|
601 | */
|
602 | function fbsqlRaiseError($errno = null) |
602 | function fbsqlRaiseError($errno = null) |
603 | {
|
603 | {
|
604 | if ($errno === null) { |
604 | if ($errno === null) { |
605 | $errno = $this->errorCode(fbsql_errno($this->connection)); |
605 | $errno = $this->errorCode(fbsql_errno($this->connection)); |
606 | }
|
606 | }
|
607 | return $this->raiseError($errno, null, null, null, |
607 | return $this->raiseError($errno, null, null, null, |
608 | @fbsql_error($this->connection)); |
608 | @fbsql_error($this->connection)); |
609 | }
|
609 | }
|
610 | 610 | ||
611 | // }}}
|
611 | // }}}
|
612 | // {{{ errorNative()
|
612 | // {{{ errorNative()
|
613 | 613 | ||
614 | /**
|
614 | /**
|
615 | * Gets the DBMS' native error code produced by the last query
|
615 | * Gets the DBMS' native error code produced by the last query
|
616 | *
|
616 | *
|
617 | * @return int the DBMS' error code
|
617 | * @return int the DBMS' error code
|
618 | */
|
618 | */
|
619 | function errorNative() |
619 | function errorNative() |
620 | {
|
620 | {
|
621 | return @fbsql_errno($this->connection); |
621 | return @fbsql_errno($this->connection); |
622 | }
|
622 | }
|
623 | 623 | ||
624 | // }}}
|
624 | // }}}
|
625 | // {{{ tableInfo()
|
625 | // {{{ tableInfo()
|
626 | 626 | ||
627 | /**
|
627 | /**
|
628 | * Returns information about a table or a result set
|
628 | * Returns information about a table or a result set
|
629 | *
|
629 | *
|
630 | * @param object|string $result DB_result object from a query or a
|
630 | * @param object|string $result DB_result object from a query or a
|
631 | * string containing the name of a table.
|
631 | * string containing the name of a table.
|
632 | * While this also accepts a query result
|
632 | * While this also accepts a query result
|
633 | * resource identifier, this behavior is
|
633 | * resource identifier, this behavior is
|
634 | * deprecated.
|
634 | * deprecated.
|
635 | * @param int $mode a valid tableInfo mode
|
635 | * @param int $mode a valid tableInfo mode
|
636 | *
|
636 | *
|
637 | * @return array an associative array with the information requested.
|
637 | * @return array an associative array with the information requested.
|
638 | * A DB_Error object on failure.
|
638 | * A DB_Error object on failure.
|
639 | *
|
639 | *
|
640 | * @see DB_common::tableInfo()
|
640 | * @see DB_common::tableInfo()
|
641 | */
|
641 | */
|
642 | function tableInfo($result, $mode = null) |
642 | function tableInfo($result, $mode = null) |
643 | {
|
643 | {
|
644 | if (is_string($result)) { |
644 | if (is_string($result)) { |
645 | /*
|
645 | /*
|
646 | * Probably received a table name.
|
646 | * Probably received a table name.
|
647 | * Create a result resource identifier.
|
647 | * Create a result resource identifier.
|
648 | */
|
648 | */
|
649 | $id = @fbsql_list_fields($this->dsn['database'], |
649 | $id = @fbsql_list_fields($this->dsn['database'], |
650 | $result, $this->connection); |
650 | $result, $this->connection); |
651 | $got_string = true; |
651 | $got_string = true; |
652 | } elseif (isset($result->result)) { |
652 | } elseif (isset($result->result)) { |
653 | /*
|
653 | /*
|
654 | * Probably received a result object.
|
654 | * Probably received a result object.
|
655 | * Extract the result resource identifier.
|
655 | * Extract the result resource identifier.
|
656 | */
|
656 | */
|
657 | $id = $result->result; |
657 | $id = $result->result; |
658 | $got_string = false; |
658 | $got_string = false; |
659 | } else { |
659 | } else { |
660 | /*
|
660 | /*
|
661 | * Probably received a result resource identifier.
|
661 | * Probably received a result resource identifier.
|
662 | * Copy it.
|
662 | * Copy it.
|
663 | * Deprecated. Here for compatibility only.
|
663 | * Deprecated. Here for compatibility only.
|
664 | */
|
664 | */
|
665 | $id = $result; |
665 | $id = $result; |
666 | $got_string = false; |
666 | $got_string = false; |
667 | }
|
667 | }
|
668 | 668 | ||
669 | if (!is_resource($id)) { |
669 | if (!is_resource($id)) { |
670 | return $this->fbsqlRaiseError(DB_ERROR_NEED_MORE_DATA); |
670 | return $this->fbsqlRaiseError(DB_ERROR_NEED_MORE_DATA); |
671 | }
|
671 | }
|
672 | 672 | ||
673 | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) { |
673 | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) { |
674 | $case_func = 'strtolower'; |
674 | $case_func = 'strtolower'; |
675 | } else { |
675 | } else { |
676 | $case_func = 'strval'; |
676 | $case_func = 'strval'; |
677 | }
|
677 | }
|
678 | 678 | ||
679 | $count = @fbsql_num_fields($id); |
679 | $count = @fbsql_num_fields($id); |
680 | $res = array(); |
680 | $res = array(); |
681 | 681 | ||
682 | if ($mode) { |
682 | if ($mode) { |
683 | $res['num_fields'] = $count; |
683 | $res['num_fields'] = $count; |
684 | }
|
684 | }
|
685 | 685 | ||
686 | for ($i = 0; $i < $count; $i++) { |
686 | for ($i = 0; $i < $count; $i++) { |
687 | $res[$i] = array( |
687 | $res[$i] = array( |
688 | 'table' => $case_func(@fbsql_field_table($id, $i)), |
688 | 'table' => $case_func(@fbsql_field_table($id, $i)), |
689 | 'name' => $case_func(@fbsql_field_name($id, $i)), |
689 | 'name' => $case_func(@fbsql_field_name($id, $i)), |
690 | 'type' => @fbsql_field_type($id, $i), |
690 | 'type' => @fbsql_field_type($id, $i), |
691 | 'len' => @fbsql_field_len($id, $i), |
691 | 'len' => @fbsql_field_len($id, $i), |
692 | 'flags' => @fbsql_field_flags($id, $i), |
692 | 'flags' => @fbsql_field_flags($id, $i), |
693 | ); |
693 | ); |
694 | if ($mode & DB_TABLEINFO_ORDER) { |
694 | if ($mode & DB_TABLEINFO_ORDER) { |
695 | $res['order'][$res[$i]['name']] = $i; |
695 | $res['order'][$res[$i]['name']] = $i; |
696 | }
|
696 | }
|
697 | if ($mode & DB_TABLEINFO_ORDERTABLE) { |
697 | if ($mode & DB_TABLEINFO_ORDERTABLE) { |
698 | $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; |
698 | $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; |
699 | }
|
699 | }
|
700 | }
|
700 | }
|
701 | 701 | ||
702 | // free the result only if we were called on a table
|
702 | // free the result only if we were called on a table
|
703 | if ($got_string) { |
703 | if ($got_string) { |
704 | @fbsql_free_result($id); |
704 | @fbsql_free_result($id); |
705 | }
|
705 | }
|
706 | return $res; |
706 | return $res; |
707 | }
|
707 | }
|
708 | 708 | ||
709 | // }}}
|
709 | // }}}
|
710 | // {{{ getSpecialQuery()
|
710 | // {{{ getSpecialQuery()
|
711 | 711 | ||
712 | /**
|
712 | /**
|
713 | * Obtains the query string needed for listing a given type of objects
|
713 | * Obtains the query string needed for listing a given type of objects
|
714 | *
|
714 | *
|
715 | * @param string $type the kind of objects you want to retrieve
|
715 | * @param string $type the kind of objects you want to retrieve
|
716 | *
|
716 | *
|
717 | * @return string the SQL query string or null if the driver doesn't
|
717 | * @return string the SQL query string or null if the driver doesn't
|
718 | * support the object type requested
|
718 | * support the object type requested
|
719 | *
|
719 | *
|
720 | * @access protected
|
720 | * @access protected
|
721 | * @see DB_common::getListOf()
|
721 | * @see DB_common::getListOf()
|
722 | */
|
722 | */
|
723 | function getSpecialQuery($type) |
723 | function getSpecialQuery($type) |
724 | {
|
724 | {
|
725 | switch ($type) { |
725 | switch ($type) { |
726 | case 'tables': |
726 | case 'tables': |
727 | return 'SELECT "table_name" FROM information_schema.tables' |
727 | return 'SELECT "table_name" FROM information_schema.tables' |
728 | . ' t0, information_schema.schemata t1' |
728 | . ' t0, information_schema.schemata t1' |
729 | . ' WHERE t0.schema_pk=t1.schema_pk AND' |
729 | . ' WHERE t0.schema_pk=t1.schema_pk AND' |
730 | . ' "table_type" = \'BASE TABLE\'' |
730 | . ' "table_type" = \'BASE TABLE\'' |
731 | . ' AND "schema_name" = current_schema'; |
731 | . ' AND "schema_name" = current_schema'; |
732 | case 'views': |
732 | case 'views': |
733 | return 'SELECT "table_name" FROM information_schema.tables' |
733 | return 'SELECT "table_name" FROM information_schema.tables' |
734 | . ' t0, information_schema.schemata t1' |
734 | . ' t0, information_schema.schemata t1' |
735 | . ' WHERE t0.schema_pk=t1.schema_pk AND' |
735 | . ' WHERE t0.schema_pk=t1.schema_pk AND' |
736 | . ' "table_type" = \'VIEW\'' |
736 | . ' "table_type" = \'VIEW\'' |
737 | . ' AND "schema_name" = current_schema'; |
737 | . ' AND "schema_name" = current_schema'; |
738 | case 'users': |
738 | case 'users': |
739 | return 'SELECT "user_name" from information_schema.users'; |
739 | return 'SELECT "user_name" from information_schema.users'; |
740 | case 'functions': |
740 | case 'functions': |
741 | return 'SELECT "routine_name" FROM' |
741 | return 'SELECT "routine_name" FROM' |
742 | . ' information_schema.psm_routines' |
742 | . ' information_schema.psm_routines' |
743 | . ' t0, information_schema.schemata t1' |
743 | . ' t0, information_schema.schemata t1' |
744 | . ' WHERE t0.schema_pk=t1.schema_pk' |
744 | . ' WHERE t0.schema_pk=t1.schema_pk' |
745 | . ' AND "routine_kind"=\'FUNCTION\'' |
745 | . ' AND "routine_kind"=\'FUNCTION\'' |
746 | . ' AND "schema_name" = current_schema'; |
746 | . ' AND "schema_name" = current_schema'; |
747 | case 'procedures': |
747 | case 'procedures': |
748 | return 'SELECT "routine_name" FROM' |
748 | return 'SELECT "routine_name" FROM' |
749 | . ' information_schema.psm_routines' |
749 | . ' information_schema.psm_routines' |
750 | . ' t0, information_schema.schemata t1' |
750 | . ' t0, information_schema.schemata t1' |
751 | . ' WHERE t0.schema_pk=t1.schema_pk' |
751 | . ' WHERE t0.schema_pk=t1.schema_pk' |
752 | . ' AND "routine_kind"=\'PROCEDURE\'' |
752 | . ' AND "routine_kind"=\'PROCEDURE\'' |
753 | . ' AND "schema_name" = current_schema'; |
753 | . ' AND "schema_name" = current_schema'; |
754 | default: |
754 | default: |
755 | return null; |
755 | return null; |
756 | }
|
756 | }
|
757 | }
|
757 | }
|
758 | 758 | ||
759 | // }}}
|
759 | // }}}
|
760 | }
|
760 | }
|
761 | 761 | ||
762 | /*
|
762 | /*
|
763 | * Local variables:
|
763 | * Local variables:
|
764 | * tab-width: 4
|
764 | * tab-width: 4
|
765 | * c-basic-offset: 4
|
765 | * c-basic-offset: 4
|
766 | * End:
|
766 | * End:
|
767 | */
|
767 | */
|
768 | 768 | ||
769 | ?>
|
769 | ?>
|
770 | 770 |