Index: trunk/phase3/includes/db/DatabaseIbm_db2.php |
— | — | @@ -1,7 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * This is the IBM DB2 database abstraction layer. |
5 | | - * See maintenance/ibm_db2/README for development notes and other specific information |
| 5 | + * See maintenance/ibm_db2/README for development notes |
| 6 | + * and other specific information |
6 | 7 | * |
7 | 8 | * @file |
8 | 9 | * @ingroup Database |
— | — | @@ -26,26 +27,26 @@ |
27 | 28 | * @param $field String: column name |
28 | 29 | * @return IBM_DB2Field |
29 | 30 | */ |
30 | | - static function fromText($db, $table, $field) { |
| 31 | + static function fromText( $db, $table, $field ) { |
31 | 32 | global $wgDBmwschema; |
32 | 33 | |
33 | 34 | $q = <<<SQL |
34 | 35 | SELECT |
35 | | -lcase(coltype) AS typname, |
| 36 | +lcase( coltype ) AS typname, |
36 | 37 | nulls AS attnotnull, length AS attlen |
37 | 38 | FROM sysibm.syscolumns |
38 | 39 | WHERE tbcreator=%s AND tbname=%s AND name=%s; |
39 | 40 | SQL; |
40 | | - $res = $db->query(sprintf($q, |
41 | | - $db->addQuotes($wgDBmwschema), |
42 | | - $db->addQuotes($table), |
43 | | - $db->addQuotes($field))); |
44 | | - $row = $db->fetchObject($res); |
45 | | - if (!$row) |
| 41 | + $res = $db->query( sprintf( $q, |
| 42 | + $db->addQuotes( $wgDBmwschema ), |
| 43 | + $db->addQuotes( $table ), |
| 44 | + $db->addQuotes( $field )) ); |
| 45 | + $row = $db->fetchObject( $res ); |
| 46 | + if ( !$row ) |
46 | 47 | return null; |
47 | 48 | $n = new IBM_DB2Field; |
48 | 49 | $n->type = $row->typname; |
49 | | - $n->nullable = ($row->attnotnull == 'N'); |
| 50 | + $n->nullable = ( $row->attnotnull == 'N' ); |
50 | 51 | $n->name = $field; |
51 | 52 | $n->tablename = $table; |
52 | 53 | $n->max_length = $row->attlen; |
— | — | @@ -85,7 +86,7 @@ |
86 | 87 | class IBM_DB2Blob { |
87 | 88 | private $mData; |
88 | 89 | |
89 | | - public function __construct($data) { |
| 90 | + public function __construct( $data ) { |
90 | 91 | $this->mData = $data; |
91 | 92 | } |
92 | 93 | |
— | — | @@ -122,196 +123,45 @@ |
123 | 124 | * |
124 | 125 | */ |
125 | 126 | |
126 | | - /// Server port |
| 127 | + /** Database server port */ |
127 | 128 | protected $mPort = null; |
128 | | - /// Schema for tables, stored procedures, triggers |
| 129 | + /** Schema for tables, stored procedures, triggers */ |
129 | 130 | protected $mSchema = null; |
130 | | - /// Whether the schema has been applied in this session |
| 131 | + /** Whether the schema has been applied in this session */ |
131 | 132 | protected $mSchemaSet = false; |
132 | | - /// Result of last query |
| 133 | + /** Result of last query */ |
133 | 134 | protected $mLastResult = null; |
134 | | - /// Number of rows affected by last INSERT/UPDATE/DELETE |
| 135 | + /** Number of rows affected by last INSERT/UPDATE/DELETE */ |
135 | 136 | protected $mAffectedRows = null; |
136 | | - /// Number of rows returned by last SELECT |
| 137 | + /** Number of rows returned by last SELECT */ |
137 | 138 | protected $mNumRows = null; |
138 | 139 | |
139 | | - /// Connection config options - see constructor |
| 140 | + /** Connection config options - see constructor */ |
140 | 141 | public $mConnOptions = array(); |
141 | | - /// Statement config options -- see constructor |
| 142 | + /** Statement config options -- see constructor */ |
142 | 143 | public $mStmtOptions = array(); |
143 | 144 | |
| 145 | + /** Default schema */ |
| 146 | + const USE_GLOBAL = "mediawiki"; |
144 | 147 | |
145 | | - const USE_GLOBAL = "get from global"; |
146 | | - |
| 148 | + /** Option that applies to nothing */ |
147 | 149 | const NONE_OPTION = 0x00; |
| 150 | + /** Option that applies to connection objects */ |
148 | 151 | const CONN_OPTION = 0x01; |
| 152 | + /** Option that applies to statement objects */ |
149 | 153 | const STMT_OPTION = 0x02; |
150 | 154 | |
| 155 | + /** Regular operation mode -- minimal debug messages */ |
151 | 156 | const REGULAR_MODE = 'regular'; |
| 157 | + /** Installation mode -- lots of debug messages */ |
152 | 158 | const INSTALL_MODE = 'install'; |
153 | 159 | |
154 | | - // Whether this is regular operation or the initial installation |
| 160 | + /** Controls the level of debug message output */ |
155 | 161 | protected $mMode = self::REGULAR_MODE; |
156 | 162 | |
157 | | - /// Last sequence value used for a primary key |
| 163 | + /** Last sequence value used for a primary key */ |
158 | 164 | protected $mInsertId = null; |
159 | 165 | |
160 | | - /* |
161 | | - * These can be safely inherited |
162 | | - * |
163 | | - * Getter/Setter: (18) |
164 | | - * failFunction |
165 | | - * bufferResults |
166 | | - * ignoreErrors |
167 | | - * trxLevel |
168 | | - * errorCount |
169 | | - * getLBInfo |
170 | | - * setLBInfo |
171 | | - * lastQuery |
172 | | - * isOpen |
173 | | - * setFlag |
174 | | - * clearFlag |
175 | | - * getFlag |
176 | | - * getProperty |
177 | | - * getDBname |
178 | | - * getServer |
179 | | - * tableNameCallback |
180 | | - * tablePrefix |
181 | | - * |
182 | | - * Administrative: (8) |
183 | | - * debug |
184 | | - * installErrorHandler |
185 | | - * restoreErrorHandler |
186 | | - * connectionErrorHandler |
187 | | - * reportConnectionError |
188 | | - * sourceFile |
189 | | - * sourceStream |
190 | | - * replaceVars |
191 | | - * |
192 | | - * Database: (5) |
193 | | - * query |
194 | | - * set |
195 | | - * selectField |
196 | | - * generalizeSQL |
197 | | - * update |
198 | | - * strreplace |
199 | | - * deadlockLoop |
200 | | - * |
201 | | - * Prepared Statement: 6 |
202 | | - * prepare |
203 | | - * freePrepared |
204 | | - * execute |
205 | | - * safeQuery |
206 | | - * fillPrepared |
207 | | - * fillPreparedArg |
208 | | - * |
209 | | - * Slave/Master: (4) |
210 | | - * masterPosWait |
211 | | - * getSlavePos |
212 | | - * getMasterPos |
213 | | - * getLag |
214 | | - * setFakeMaster |
215 | | - * |
216 | | - * Generation: (9) |
217 | | - * tableNames |
218 | | - * tableNamesN |
219 | | - * tableNamesWithUseIndexOrJOIN |
220 | | - * escapeLike |
221 | | - * delete |
222 | | - * insertSelect |
223 | | - * timestampOrNull |
224 | | - * resultObject |
225 | | - * aggregateValue |
226 | | - * selectSQLText |
227 | | - * selectRow |
228 | | - * makeUpdateOptions |
229 | | - * |
230 | | - * Reflection: (1) |
231 | | - * indexExists |
232 | | - */ |
233 | | - |
234 | | - /* |
235 | | - * These have been implemented |
236 | | - * |
237 | | - * Administrative: 7 / 7 |
238 | | - * constructor [Done] |
239 | | - * open [Done] |
240 | | - * openCataloged [Done] |
241 | | - * close [Done] |
242 | | - * newFromParams [Done] |
243 | | - * openUncataloged [Done] |
244 | | - * setup_database [Done] |
245 | | - * |
246 | | - * Getter/Setter: 13 / 13 |
247 | | - * cascadingDeletes [Done] |
248 | | - * cleanupTriggers [Done] |
249 | | - * strictIPs [Done] |
250 | | - * realTimestamps [Done] |
251 | | - * impliciGroupby [Done] |
252 | | - * implicitOrderby [Done] |
253 | | - * searchableIPs [Done] |
254 | | - * functionalIndexes [Done] |
255 | | - * getWikiID [Done] |
256 | | - * isOpen [Done] |
257 | | - * getServerVersion [Done] |
258 | | - * getSoftwareLink [Done] |
259 | | - * getSearchEngine [Done] |
260 | | - * |
261 | | - * Database driver wrapper: 23 / 23 |
262 | | - * lastError [Done] |
263 | | - * lastErrno [Done] |
264 | | - * doQuery [Done] |
265 | | - * tableExists [Done] |
266 | | - * fetchObject [Done] |
267 | | - * fetchRow [Done] |
268 | | - * freeResult [Done] |
269 | | - * numRows [Done] |
270 | | - * numFields [Done] |
271 | | - * fieldName [Done] |
272 | | - * insertId [Done] |
273 | | - * dataSeek [Done] |
274 | | - * affectedRows [Done] |
275 | | - * selectDB [Done] |
276 | | - * strencode [Done] |
277 | | - * conditional [Done] |
278 | | - * wasDeadlock [Done] |
279 | | - * ping [Done] |
280 | | - * getStatus [Done] |
281 | | - * setTimeout [Done] |
282 | | - * lock [Done] |
283 | | - * unlock [Done] |
284 | | - * insert [Done] |
285 | | - * select [Done] |
286 | | - * |
287 | | - * Slave/master: 2 / 2 |
288 | | - * setFakeSlaveLag [Done] - Where?? |
289 | | - * |
290 | | - * Reflection: 5 / 5 |
291 | | - * indexInfo [Done] |
292 | | - * fieldInfo [Done] |
293 | | - * fieldType [Done] |
294 | | - * indexUnique [Done] |
295 | | - * textFieldSize [Done] |
296 | | - * |
297 | | - * Generation: 16 / 16 |
298 | | - * tableName [Done] |
299 | | - * addQuotes [Done] |
300 | | - * makeList [Done] |
301 | | - * makeSelectOptions [Done] |
302 | | - * estimateRowCount [Done] |
303 | | - * nextSequenceValue [Done] |
304 | | - * useIndexClause [Done] |
305 | | - * replace [Done] |
306 | | - * deleteJoin [Done] |
307 | | - * lowPriorityOption [Done] |
308 | | - * limitResult [Done] |
309 | | - * limitResultForUpdate [Done] |
310 | | - * timestamp [Done] |
311 | | - * encodeBlob [Done] |
312 | | - * decodeBlob [Done] |
313 | | - * buildConcat [Done] |
314 | | - */ |
315 | | - |
316 | 166 | ###################################### |
317 | 167 | # Getters and Setters |
318 | 168 | ###################################### |
— | — | @@ -324,14 +174,16 @@ |
325 | 175 | } |
326 | 176 | |
327 | 177 | /** |
328 | | - * Returns true if this database supports (and uses) triggers (e.g. on the page table) |
| 178 | + * Returns true if this database supports (and uses) triggers (e.g. on the |
| 179 | + * page table) |
329 | 180 | */ |
330 | 181 | function cleanupTriggers() { |
331 | 182 | return true; |
332 | 183 | } |
333 | 184 | |
334 | 185 | /** |
335 | | - * Returns true if this database is strict about what can be put into an IP field. |
| 186 | + * Returns true if this database is strict about what can be put into an |
| 187 | + * IP field. |
336 | 188 | * Specifically, it uses a NULL value instead of an empty string. |
337 | 189 | */ |
338 | 190 | function strictIPs() { |
— | — | @@ -353,7 +205,8 @@ |
354 | 206 | } |
355 | 207 | |
356 | 208 | /** |
357 | | - * Returns true if this database does an implicit order by when the column has an index |
| 209 | + * Returns true if this database does an implicit order by when the column |
| 210 | + * has an index |
358 | 211 | * For example: SELECT page_title FROM page LIMIT 1 |
359 | 212 | */ |
360 | 213 | function implicitOrderby() { |
— | — | @@ -405,7 +258,8 @@ |
406 | 259 | * @param $flags Integer: database behaviour flags (optional, unused) |
407 | 260 | * @param $schema String |
408 | 261 | */ |
409 | | - public function DatabaseIbm_db2($server = false, $user = false, $password = false, |
| 262 | + public function DatabaseIbm_db2( $server = false, $user = false, |
| 263 | + $password = false, |
410 | 264 | $dbName = false, $failFunction = false, $flags = 0, |
411 | 265 | $schema = self::USE_GLOBAL ) |
412 | 266 | { |
— | — | @@ -427,11 +281,14 @@ |
428 | 282 | } |
429 | 283 | |
430 | 284 | // configure the connection and statement objects |
431 | | - $this->setDB2Option('db2_attr_case', 'DB2_CASE_LOWER', self::CONN_OPTION | self::STMT_OPTION); |
432 | | - $this->setDB2Option('deferred_prepare', 'DB2_DEFERRED_PREPARE_ON', self::STMT_OPTION); |
433 | | - $this->setDB2Option('rowcount', 'DB2_ROWCOUNT_PREFETCH_ON', self::STMT_OPTION); |
| 285 | + $this->setDB2Option( 'db2_attr_case', 'DB2_CASE_LOWER', |
| 286 | + self::CONN_OPTION | self::STMT_OPTION ); |
| 287 | + $this->setDB2Option( 'deferred_prepare', 'DB2_DEFERRED_PREPARE_ON', |
| 288 | + self::STMT_OPTION ); |
| 289 | + $this->setDB2Option( 'rowcount', 'DB2_ROWCOUNT_PREFETCH_ON', |
| 290 | + self::STMT_OPTION ); |
434 | 291 | |
435 | | - $this->open( $server, $user, $password, $dbName); |
| 292 | + $this->open( $server, $user, $password, $dbName ); |
436 | 293 | } |
437 | 294 | |
438 | 295 | /** |
— | — | @@ -440,13 +297,18 @@ |
441 | 298 | * @param $const String: name of the constant holding the right option value |
442 | 299 | * @param $type Integer: whether this is a Connection or Statement otion |
443 | 300 | */ |
444 | | - private function setDB2Option($name, $const, $type) { |
445 | | - if (defined($const)) { |
446 | | - if ($type & self::CONN_OPTION) $this->mConnOptions[$name] = constant($const); |
447 | | - if ($type & self::STMT_OPTION) $this->mStmtOptions[$name] = constant($const); |
| 301 | + private function setDB2Option( $name, $const, $type ) { |
| 302 | + if ( defined( $const )) { |
| 303 | + if ( $type & self::CONN_OPTION ) { |
| 304 | + $this->mConnOptions[$name] = constant( $const ); |
| 305 | + } |
| 306 | + if ( $type & self::STMT_OPTION ) { |
| 307 | + $this->mStmtOptions[$name] = constant( $const ); |
| 308 | + } |
448 | 309 | } |
449 | 310 | else { |
450 | | - $this->installPrint("$const is not defined. ibm_db2 version is likely too low."); |
| 311 | + $this->installPrint( |
| 312 | + "$const is not defined. ibm_db2 version is likely too low." ); |
451 | 313 | } |
452 | 314 | } |
453 | 315 | |
— | — | @@ -454,9 +316,9 @@ |
455 | 317 | * Outputs debug information in the appropriate place |
456 | 318 | * @param $string String: the relevant debug message |
457 | 319 | */ |
458 | | - private function installPrint($string) { |
459 | | - wfDebug("$string\n"); |
460 | | - if ($this->mMode == self::INSTALL_MODE) { |
| 320 | + private function installPrint( $string ) { |
| 321 | + wfDebug( "$string\n" ); |
| 322 | + if ( $this->mMode == self::INSTALL_MODE ) { |
461 | 323 | print "<li><pre>$string</pre></li>"; |
462 | 324 | flush(); |
463 | 325 | } |
— | — | @@ -482,12 +344,15 @@ |
483 | 345 | |
484 | 346 | // Test for IBM DB2 support, to avoid suppressed fatal error |
485 | 347 | if ( !function_exists( 'db2_connect' ) ) { |
486 | | - $error = "DB2 functions missing, have you enabled the ibm_db2 extension for PHP?\n"; |
487 | | - $this->installPrint($error); |
488 | | - $this->reportConnectionError($error); |
| 348 | + $error = <<<ERROR |
| 349 | +DB2 functions missing, have you enabled the ibm_db2 extension for PHP? |
| 350 | + |
| 351 | +ERROR; |
| 352 | + $this->installPrint( $error ); |
| 353 | + $this->reportConnectionError( $error ); |
489 | 354 | } |
490 | 355 | |
491 | | - if (!strlen($user)) { // Copied from Postgres |
| 356 | + if ( strlen( $user ) < 1) { |
492 | 357 | return null; |
493 | 358 | } |
494 | 359 | |
— | — | @@ -500,18 +365,21 @@ |
501 | 366 | $this->mPassword = $password; |
502 | 367 | $this->mDBname = $dbName; |
503 | 368 | |
504 | | - $this->openUncataloged($dbName, $user, $password, $server, $port); |
| 369 | + $this->openUncataloged( $dbName, $user, $password, $server, $port ); |
505 | 370 | |
506 | 371 | // Apply connection config |
507 | | - db2_set_option($this->mConn, $this->mConnOptions, 1); |
508 | | - // Not all MediaWiki code is transactional |
509 | | - // Rather, turn autocommit off in the begin function and turn on after a commit |
510 | | - db2_autocommit($this->mConn, DB2_AUTOCOMMIT_ON); |
| 372 | + db2_set_option( $this->mConn, $this->mConnOptions, 1 ); |
| 373 | + // Some MediaWiki code is still transaction-less (?). |
| 374 | + // The strategy is to keep AutoCommit on for that code |
| 375 | + // but switch it off whenever a transaction is begun. |
| 376 | + db2_autocommit( $this->mConn, DB2_AUTOCOMMIT_ON ); |
511 | 377 | |
512 | 378 | if ( !$this->mConn ) { |
513 | 379 | $this->installPrint( "DB connection error\n" ); |
514 | | - $this->installPrint( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" ); |
515 | | - $this->installPrint( $this->lastError()."\n" ); |
| 380 | + $this->installPrint( |
| 381 | + "Server: $server, Database: $dbName, User: $user, Password: " |
| 382 | + . substr( $password, 0, 3 ) . "...\n" ); |
| 383 | + $this->installPrint( $this->lastError() . "\n" ); |
516 | 384 | return null; |
517 | 385 | } |
518 | 386 | |
— | — | @@ -527,7 +395,7 @@ |
528 | 396 | */ |
529 | 397 | protected function openCataloged( $dbName, $user, $password ) |
530 | 398 | { |
531 | | - @$this->mConn = db2_pconnect($dbName, $user, $password); |
| 399 | + @$this->mConn = db2_pconnect( $dbName, $user, $password ); |
532 | 400 | } |
533 | 401 | |
534 | 402 | /** |
— | — | @@ -538,12 +406,13 @@ |
539 | 407 | $str = "DRIVER={IBM DB2 ODBC DRIVER};"; |
540 | 408 | $str .= "DATABASE=$dbName;"; |
541 | 409 | $str .= "HOSTNAME=$server;"; |
542 | | - if ($port) $str .= "PORT=$port;"; |
| 410 | + // port was formerly validated to not be 0 |
| 411 | + $str .= "PORT=$port;"; |
543 | 412 | $str .= "PROTOCOL=TCPIP;"; |
544 | 413 | $str .= "UID=$user;"; |
545 | 414 | $str .= "PWD=$password;"; |
546 | 415 | |
547 | | - @$this->mConn = db2_pconnect($str, $user, $password); |
| 416 | + @$this->mConn = db2_pconnect( $str, $user, $password ); |
548 | 417 | } |
549 | 418 | |
550 | 419 | /** |
— | — | @@ -574,9 +443,11 @@ |
575 | 444 | * @param $flags Integer: database behaviour flags (optional, unused) |
576 | 445 | * @return DatabaseIbm_db2 object |
577 | 446 | */ |
578 | | - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0) |
| 447 | + static function newFromParams( $server, $user, $password, $dbName, |
| 448 | + $failFunction = false, $flags = 0 ) |
579 | 449 | { |
580 | | - return new DatabaseIbm_db2( $server, $user, $password, $dbName, $failFunction, $flags ); |
| 450 | + return new DatabaseIbm_db2( $server, $user, $password, $dbName, |
| 451 | + $failFunction, $flags ); |
581 | 452 | } |
582 | 453 | |
583 | 454 | /** |
— | — | @@ -585,12 +456,12 @@ |
586 | 457 | */ |
587 | 458 | public function lastError() { |
588 | 459 | $connerr = db2_conn_errormsg(); |
589 | | - if ($connerr) { |
| 460 | + if ( $connerr ) { |
590 | 461 | //$this->rollback(); |
591 | 462 | return $connerr; |
592 | 463 | } |
593 | 464 | $stmterr = db2_stmt_errormsg(); |
594 | | - if ($stmterr) { |
| 465 | + if ( $stmterr ) { |
595 | 466 | //$this->rollback(); |
596 | 467 | return $stmterr; |
597 | 468 | } |
— | — | @@ -605,9 +476,13 @@ |
606 | 477 | */ |
607 | 478 | public function lastErrno() { |
608 | 479 | $connerr = db2_conn_error(); |
609 | | - if ($connerr) return $connerr; |
| 480 | + if ( $connerr ) { |
| 481 | + return $connerr; |
| 482 | + } |
610 | 483 | $stmterr = db2_stmt_error(); |
611 | | - if ($stmterr) return $stmterr; |
| 484 | + if ( $stmterr ) { |
| 485 | + return $stmterr; |
| 486 | + } |
612 | 487 | return 0; |
613 | 488 | } |
614 | 489 | |
— | — | @@ -620,7 +495,7 @@ |
621 | 496 | /** |
622 | 497 | * The DBMS-dependent part of query() |
623 | 498 | * @param $sql String: SQL query. |
624 | | - * @return object Result object to feed to fetchObject, fetchRow, ...; or false on failure |
| 499 | + * @return object Result object for fetch functions or false on failure |
625 | 500 | * @access private |
626 | 501 | */ |
627 | 502 | /*private*/ |
— | — | @@ -630,9 +505,10 @@ |
631 | 506 | $ret = db2_exec( $this->mConn, $sql, $this->mStmtOptions ); |
632 | 507 | if( $ret == FALSE ) { |
633 | 508 | $error = db2_stmt_errormsg(); |
634 | | - $this->installPrint("<pre>$sql</pre>"); |
635 | | - $this->installPrint($error); |
636 | | - throw new DBUnexpectedError($this, 'SQL error: ' . htmlspecialchars( $error ) ); |
| 509 | + $this->installPrint( "<pre>$sql</pre>" ); |
| 510 | + $this->installPrint( $error ); |
| 511 | + throw new DBUnexpectedError( $this, 'SQL error: ' |
| 512 | + . htmlspecialchars( $error ) ); |
637 | 513 | } |
638 | 514 | $this->mLastResult = $ret; |
639 | 515 | $this->mAffectedRows = null; // Not calculated until asked for |
— | — | @@ -654,16 +530,16 @@ |
655 | 531 | public function tableExists( $table ) { |
656 | 532 | $schema = $this->mSchema; |
657 | 533 | $sql = <<< EOF |
658 | | -SELECT COUNT(*) FROM SYSIBM.SYSTABLES ST |
| 534 | +SELECT COUNT( * ) FROM SYSIBM.SYSTABLES ST |
659 | 535 | WHERE ST.NAME = '$table' AND ST.CREATOR = '$schema' |
660 | 536 | EOF; |
661 | 537 | $res = $this->query( $sql ); |
662 | | - if (!$res) return false; |
| 538 | + if ( !$res ) return false; |
663 | 539 | |
664 | 540 | // If the table exists, there should be one of it |
665 | | - @$row = $this->fetchRow($res); |
| 541 | + @$row = $this->fetchRow( $res ); |
666 | 542 | $count = $row[0]; |
667 | | - if ($count == '1' or $count == 1) { |
| 543 | + if ( $count == '1' or $count == 1 ) { |
668 | 544 | return true; |
669 | 545 | } |
670 | 546 | |
— | — | @@ -685,7 +561,8 @@ |
686 | 562 | } |
687 | 563 | @$row = db2_fetch_object( $res ); |
688 | 564 | if( $this->lastErrno() ) { |
689 | | - throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); |
| 565 | + throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' |
| 566 | + . htmlspecialchars( $this->lastError() ) ); |
690 | 567 | } |
691 | 568 | return $row; |
692 | 569 | } |
— | — | @@ -704,7 +581,8 @@ |
705 | 582 | } |
706 | 583 | @$row = db2_fetch_array( $res ); |
707 | 584 | if ( $this->lastErrno() ) { |
708 | | - throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); |
| 585 | + throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' |
| 586 | + . htmlspecialchars( $this->lastError() ) ); |
709 | 587 | } |
710 | 588 | return $row; |
711 | 589 | } |
— | — | @@ -720,9 +598,6 @@ |
721 | 599 | * Create tables, stored procedures, and so on |
722 | 600 | */ |
723 | 601 | public function setup_database() { |
724 | | - // Timeout was being changed earlier due to mysterious crashes |
725 | | - // Changing it now may cause more problems than not changing it |
726 | | - //set_time_limit(240); |
727 | 602 | try { |
728 | 603 | // TODO: switch to root login if available |
729 | 604 | |
— | — | @@ -731,13 +606,13 @@ |
732 | 607 | $this->begin(); |
733 | 608 | |
734 | 609 | $res = $this->sourceFile( "../maintenance/ibm_db2/tables.sql" ); |
735 | | - if ($res !== true) { |
| 610 | + if ( $res !== true ) { |
736 | 611 | print " <b>FAILED</b>: " . htmlspecialchars( $res ) . "</li>"; |
737 | 612 | } else { |
738 | 613 | print " done</li>"; |
739 | 614 | } |
740 | 615 | $res = $this->sourceFile( "../maintenance/ibm_db2/foreignkeys.sql" ); |
741 | | - if ($res !== true) { |
| 616 | + if ( $res !== true ) { |
742 | 617 | print " <b>FAILED</b>: " . htmlspecialchars( $res ) . "</li>"; |
743 | 618 | } else { |
744 | 619 | print "<li>Foreign keys done</li>"; |
— | — | @@ -746,16 +621,17 @@ |
747 | 622 | |
748 | 623 | // TODO: populate interwiki links |
749 | 624 | |
750 | | - if ($this->lastError()) { |
751 | | - print "<li>Errors encountered during table creation -- rolled back</li>\n"; |
752 | | - print "<li>Please install again</li>\n"; |
| 625 | + if ( $this->lastError() ) { |
| 626 | + $this->installPrint( |
| 627 | + "Errors encountered during table creation -- rolled back" ); |
| 628 | + $this->installPrint( "Please install again" ); |
753 | 629 | $this->rollback(); |
754 | 630 | } |
755 | 631 | else { |
756 | 632 | $this->commit(); |
757 | 633 | } |
758 | 634 | } |
759 | | - catch (MWException $mwe) |
| 635 | + catch ( MWException $mwe ) |
760 | 636 | { |
761 | 637 | print "<br><pre>$mwe</pre><br>"; |
762 | 638 | } |
— | — | @@ -768,16 +644,16 @@ |
769 | 645 | * @return escaped string |
770 | 646 | */ |
771 | 647 | public function addQuotes( $s ) { |
772 | | - //$this->installPrint("DB2::addQuotes($s)\n"); |
| 648 | + //$this->installPrint( "DB2::addQuotes( $s )\n" ); |
773 | 649 | if ( is_null( $s ) ) { |
774 | 650 | return "NULL"; |
775 | | - } else if ($s instanceof Blob) { |
776 | | - return "'".$s->fetch($s)."'"; |
777 | | - } else if ($s instanceof IBM_DB2Blob) { |
778 | | - return "'".$this->decodeBlob($s)."'"; |
| 651 | + } else if ( $s instanceof Blob ) { |
| 652 | + return "'" . $s->fetch( $s ) . "'"; |
| 653 | + } else if ( $s instanceof IBM_DB2Blob ) { |
| 654 | + return "'" . $this->decodeBlob( $s ) . "'"; |
779 | 655 | } |
780 | | - $s = $this->strencode($s); |
781 | | - if ( is_numeric($s) ) { |
| 656 | + $s = $this->strencode( $s ); |
| 657 | + if ( is_numeric( $s ) ) { |
782 | 658 | return $s; |
783 | 659 | } |
784 | 660 | else { |
— | — | @@ -791,7 +667,7 @@ |
792 | 668 | * @param $type String: DB2 column type |
793 | 669 | */ |
794 | 670 | public function is_numeric_type( $type ) { |
795 | | - switch (strtoupper($type)) { |
| 671 | + switch ( strtoupper( $type )) { |
796 | 672 | case 'SMALLINT': |
797 | 673 | case 'INTEGER': |
798 | 674 | case 'INT': |
— | — | @@ -814,13 +690,13 @@ |
815 | 691 | // Bloody useless function |
816 | 692 | // Prepends backslashes to \x00, \n, \r, \, ', " and \x1a. |
817 | 693 | // But also necessary |
818 | | - $s = db2_escape_string($s); |
| 694 | + $s = db2_escape_string( $s ); |
819 | 695 | // Wide characters are evil -- some of them look like ' |
820 | | - $s = utf8_encode($s); |
| 696 | + $s = utf8_encode( $s ); |
821 | 697 | // Fix its stupidity |
822 | | - $from = array("\\\\", "\\'", '\\n', '\\t', '\\"', '\\r'); |
823 | | - $to = array("\\", "''", "\n", "\t", '"', "\r"); |
824 | | - $s = str_replace($from, $to, $s); // DB2 expects '', not \' escaping |
| 698 | + $from = array( "\\\\", "\\'", '\\n', '\\t', '\\"', '\\r' ); |
| 699 | + $to = array( "\\", "''", "\n", "\t", '"', "\r" ); |
| 700 | + $s = str_replace( $from, $to, $s ); // DB2 expects '', not \' escaping |
825 | 701 | return $s; |
826 | 702 | } |
827 | 703 | |
— | — | @@ -828,10 +704,10 @@ |
829 | 705 | * Switch into the database schema |
830 | 706 | */ |
831 | 707 | protected function applySchema() { |
832 | | - if ( !($this->mSchemaSet) ) { |
| 708 | + if ( !( $this->mSchemaSet ) ) { |
833 | 709 | $this->mSchemaSet = true; |
834 | 710 | $this->begin(); |
835 | | - $this->doQuery("SET SCHEMA = $this->mSchema"); |
| 711 | + $this->doQuery( "SET SCHEMA = $this->mSchema" ); |
836 | 712 | $this->commit(); |
837 | 713 | } |
838 | 714 | } |
— | — | @@ -840,8 +716,14 @@ |
841 | 717 | * Start a transaction (mandatory) |
842 | 718 | */ |
843 | 719 | public function begin( $fname = 'DatabaseIbm_db2::begin' ) { |
844 | | - // turn off auto-commit |
845 | | - db2_autocommit($this->mConn, DB2_AUTOCOMMIT_OFF); |
| 720 | + // BEGIN is implicit for DB2 |
| 721 | + // However, it requires that AutoCommit be off. |
| 722 | + |
| 723 | + // Some MediaWiki code is still transaction-less (?). |
| 724 | + // The strategy is to keep AutoCommit on for that code |
| 725 | + // but switch it off whenever a transaction is begun. |
| 726 | + db2_autocommit( $this->mConn, DB2_AUTOCOMMIT_OFF ); |
| 727 | + |
846 | 728 | $this->mTrxLevel = 1; |
847 | 729 | } |
848 | 730 | |
— | — | @@ -850,9 +732,13 @@ |
851 | 733 | * Must have a preceding begin() |
852 | 734 | */ |
853 | 735 | public function commit( $fname = 'DatabaseIbm_db2::commit' ) { |
854 | | - db2_commit($this->mConn); |
855 | | - // turn auto-commit back on |
856 | | - db2_autocommit($this->mConn, DB2_AUTOCOMMIT_ON); |
| 736 | + db2_commit( $this->mConn ); |
| 737 | + |
| 738 | + // Some MediaWiki code is still transaction-less (?). |
| 739 | + // The strategy is to keep AutoCommit on for that code |
| 740 | + // but switch it off whenever a transaction is begun. |
| 741 | + db2_autocommit( $this->mConn, DB2_AUTOCOMMIT_ON ); |
| 742 | + |
857 | 743 | $this->mTrxLevel = 0; |
858 | 744 | } |
859 | 745 | |
— | — | @@ -860,41 +746,42 @@ |
861 | 747 | * Cancel a transaction |
862 | 748 | */ |
863 | 749 | public function rollback( $fname = 'DatabaseIbm_db2::rollback' ) { |
864 | | - db2_rollback($this->mConn); |
| 750 | + db2_rollback( $this->mConn ); |
865 | 751 | // turn auto-commit back on |
866 | 752 | // not sure if this is appropriate |
867 | | - db2_autocommit($this->mConn, DB2_AUTOCOMMIT_ON); |
| 753 | + db2_autocommit( $this->mConn, DB2_AUTOCOMMIT_ON ); |
868 | 754 | $this->mTrxLevel = 0; |
869 | 755 | } |
870 | 756 | |
871 | 757 | /** |
872 | 758 | * Makes an encoded list of strings from an array |
873 | 759 | * $mode: |
874 | | - * LIST_COMMA - comma separated, no field names |
875 | | - * LIST_AND - ANDed WHERE clause (without the WHERE) |
876 | | - * LIST_OR - ORed WHERE clause (without the WHERE) |
877 | | - * LIST_SET - comma separated with field names, like a SET clause |
878 | | - * LIST_NAMES - comma separated field names |
879 | | - * LIST_SET_PREPARED - like LIST_SET, except with ? tokens as values |
| 760 | + * LIST_COMMA - comma separated, no field names |
| 761 | + * LIST_AND - ANDed WHERE clause (without the WHERE) |
| 762 | + * LIST_OR - ORed WHERE clause (without the WHERE) |
| 763 | + * LIST_SET - comma separated with field names, like a SET clause |
| 764 | + * LIST_NAMES - comma separated field names |
| 765 | + * LIST_SET_PREPARED - like LIST_SET, except with ? tokens as values |
880 | 766 | */ |
881 | 767 | function makeList( $a, $mode = LIST_COMMA ) { |
882 | 768 | if ( !is_array( $a ) ) { |
883 | | - throw new DBUnexpectedError( $this, 'DatabaseBase::makeList called with incorrect parameters' ); |
| 769 | + throw new DBUnexpectedError( $this, |
| 770 | + 'DatabaseBase::makeList called with incorrect parameters' ); |
884 | 771 | } |
885 | 772 | |
886 | 773 | // if this is for a prepared UPDATE statement |
887 | 774 | // (this should be promoted to the parent class |
888 | 775 | // once other databases use prepared statements) |
889 | | - if ($mode == LIST_SET_PREPARED) { |
| 776 | + if ( $mode == LIST_SET_PREPARED ) { |
890 | 777 | $first = true; |
891 | 778 | $list = ''; |
892 | 779 | foreach ( $a as $field => $value ) { |
893 | | - if (!$first) { |
| 780 | + if ( !$first ) { |
894 | 781 | $list .= ", $field = ?"; |
895 | 782 | } |
896 | 783 | else { |
897 | 784 | $list .= "$field = ?"; |
898 | | - $first = false; |
| 785 | + $first = false; |
899 | 786 | } |
900 | 787 | } |
901 | 788 | $list .= ''; |
— | — | @@ -913,17 +800,17 @@ |
914 | 801 | * @param $limit integer the SQL limit |
915 | 802 | * @param $offset integer the SQL offset (default false) |
916 | 803 | */ |
917 | | - public function limitResult($sql, $limit, $offset=false) { |
918 | | - if( !is_numeric($limit) ) { |
919 | | - throw new DBUnexpectedError( $this, "Invalid non-numeric limit passed to limitResult()\n" ); |
| 804 | + public function limitResult( $sql, $limit, $offset=false ) { |
| 805 | + if( !is_numeric( $limit ) ) { |
| 806 | + throw new DBUnexpectedError( $this, |
| 807 | + "Invalid non-numeric limit passed to limitResult()\n" ); |
920 | 808 | } |
921 | 809 | if( $offset ) { |
922 | | - //$this->installPrint("Offset parameter not supported in limitResult()\n"); |
923 | | - if ( stripos($sql, 'where') === false ) { |
924 | | - return "$sql AND (ROWNUM BETWEEN $offset AND $offset+$limit)"; |
| 810 | + if ( stripos( $sql, 'where' ) === false ) { |
| 811 | + return "$sql AND ( ROWNUM BETWEEN $offset AND $offset+$limit )"; |
925 | 812 | } |
926 | 813 | else { |
927 | | - return "$sql WHERE (ROWNUM BETWEEN $offset AND $offset+$limit)"; |
| 814 | + return "$sql WHERE ( ROWNUM BETWEEN $offset AND $offset+$limit )"; |
928 | 815 | } |
929 | 816 | } |
930 | 817 | return "$sql FETCH FIRST $limit ROWS ONLY "; |
— | — | @@ -935,15 +822,6 @@ |
936 | 823 | * @param $name Object |
937 | 824 | */ |
938 | 825 | public function tableName( $name ) { |
939 | | - # Replace reserved words with better ones |
940 | | -// switch( $name ) { |
941 | | -// case 'user': |
942 | | -// return 'mwuser'; |
943 | | -// case 'text': |
944 | | -// return 'pagecontent'; |
945 | | -// default: |
946 | | -// return $name; |
947 | | -// } |
948 | 826 | // we want maximum compatibility with MySQL schema |
949 | 827 | return $name; |
950 | 828 | } |
— | — | @@ -955,7 +833,7 @@ |
956 | 834 | */ |
957 | 835 | public function timestamp( $ts=0 ) { |
958 | 836 | // TS_MW cannot be easily distinguished from an integer |
959 | | - return wfTimestamp(TS_DB2,$ts); |
| 837 | + return wfTimestamp( TS_DB2, $ts ); |
960 | 838 | } |
961 | 839 | |
962 | 840 | /** |
— | — | @@ -964,8 +842,10 @@ |
965 | 843 | * @return next value in that sequence |
966 | 844 | */ |
967 | 845 | public function nextSequenceValue( $seqName ) { |
968 | | - // Not using sequences in the primary schema to allow for easy third-party migration scripts |
969 | | - // Emulating MySQL behaviour of using NULL to signal that sequences aren't used |
| 846 | + // Not using sequences in the primary schema to allow for easier migration |
| 847 | + // from MySQL |
| 848 | + // Emulating MySQL behaviour of using NULL to signal that sequences |
| 849 | + // aren't used |
970 | 850 | /* |
971 | 851 | $safeseq = preg_replace( "/'/", "''", $seqName ); |
972 | 852 | $res = $this->query( "VALUES NEXTVAL FOR $safeseq" ); |
— | — | @@ -985,24 +865,24 @@ |
986 | 866 | } |
987 | 867 | |
988 | 868 | /** |
989 | | - * Updates the mInsertId property with the value of the last insert into a generated column |
| 869 | + * Updates the mInsertId property with the value of the last insert |
| 870 | + * into a generated column |
990 | 871 | * @param $table String: sanitized table name |
991 | | - * @param $primaryKey Mixed: string name of the primary key or a bool if this call is a do-nothing |
| 872 | + * @param $primaryKey Mixed: string name of the primary key |
992 | 873 | * @param $stmt Resource: prepared statement resource |
993 | 874 | * of the SELECT primary_key FROM FINAL TABLE ( INSERT ... ) form |
994 | 875 | */ |
995 | | - private function calcInsertId($table, $primaryKey, $stmt) { |
996 | | - if ($primaryKey) { |
997 | | - $this->mInsertId = db2_last_insert_id($this->mConn); |
998 | | - //$this->installPrint("Last $primaryKey for $table was $this->mInsertId"); |
| 876 | + private function calcInsertId( $table, $primaryKey, $stmt ) { |
| 877 | + if ( $primaryKey ) { |
| 878 | + $this->mInsertId = db2_last_insert_id( $this->mConn ); |
999 | 879 | } |
1000 | 880 | } |
1001 | 881 | |
1002 | 882 | /** |
1003 | 883 | * INSERT wrapper, inserts an array into a table |
1004 | 884 | * |
1005 | | - * $args may be a single associative array, or an array of these with numeric keys, |
1006 | | - * for multi-row insert |
| 885 | + * $args may be a single associative array, or an array of arrays |
| 886 | + * with numeric keys, for multi-row insert |
1007 | 887 | * |
1008 | 888 | * @param $table String: Name of the table to insert to. |
1009 | 889 | * @param $args Array: Items to insert into the table. |
— | — | @@ -1011,31 +891,33 @@ |
1012 | 892 | * |
1013 | 893 | * @return bool Success of insert operation. IGNORE always returns true. |
1014 | 894 | */ |
1015 | | - public function insert( $table, $args, $fname = 'DatabaseIbm_db2::insert', $options = array() ) { |
| 895 | + public function insert( $table, $args, $fname = 'DatabaseIbm_db2::insert', |
| 896 | + $options = array() ) |
| 897 | + { |
1016 | 898 | if ( !count( $args ) ) { |
1017 | 899 | return true; |
1018 | 900 | } |
1019 | 901 | // get database-specific table name (not used) |
1020 | 902 | $table = $this->tableName( $table ); |
1021 | 903 | // format options as an array |
1022 | | - $options = IBM_DB2Helper::makeArray($options); |
| 904 | + $options = IBM_DB2Helper::makeArray( $options ); |
1023 | 905 | // format args as an array of arrays |
1024 | 906 | if ( !( isset( $args[0] ) && is_array( $args[0] ) ) ) { |
1025 | | - $args = array($args); |
| 907 | + $args = array( $args ); |
1026 | 908 | } |
1027 | 909 | |
1028 | 910 | // prevent insertion of NULL into primary key columns |
1029 | | - list($args, $primaryKeys) = $this->removeNullPrimaryKeys($table, $args); |
| 911 | + list( $args, $primaryKeys ) = $this->removeNullPrimaryKeys( $table, $args ); |
1030 | 912 | // if there's only one primary key |
1031 | 913 | // we'll be able to read its value after insertion |
1032 | 914 | $primaryKey = false; |
1033 | | - if (count($primaryKeys) == 1) { |
| 915 | + if ( count( $primaryKeys ) == 1 ) { |
1034 | 916 | $primaryKey = $primaryKeys[0]; |
1035 | 917 | } |
1036 | 918 | |
1037 | 919 | // get column names |
1038 | 920 | $keys = array_keys( $args[0] ); |
1039 | | - $key_count = count($keys); |
| 921 | + $key_count = count( $keys ); |
1040 | 922 | |
1041 | 923 | // If IGNORE is set, we use savepoints to emulate mysql's behavior |
1042 | 924 | $ignore = in_array( 'IGNORE', $options ) ? 'mw' : ''; |
— | — | @@ -1043,20 +925,20 @@ |
1044 | 926 | // assume success |
1045 | 927 | $res = true; |
1046 | 928 | // If we are not in a transaction, we need to be for savepoint trickery |
1047 | | - if (! $this->mTrxLevel) { |
| 929 | + if ( ! $this->mTrxLevel ) { |
1048 | 930 | $this->begin(); |
1049 | 931 | } |
1050 | 932 | |
1051 | | - $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES '; |
1052 | | - if ($key_count == 1) { |
1053 | | - $sql .= '(?)'; |
| 933 | + $sql = "INSERT INTO $table ( " . implode( ',', $keys ) . ' ) VALUES '; |
| 934 | + if ( $key_count == 1 ) { |
| 935 | + $sql .= '( ? )'; |
1054 | 936 | } else { |
1055 | | - $sql .= '(?' . str_repeat(',?', $key_count-1) . ')'; |
| 937 | + $sql .= '( ?' . str_repeat( ',?', $key_count-1 ) . ' )'; |
1056 | 938 | } |
1057 | | - //$this->installPrint("Preparing the following SQL:"); |
1058 | | - //$this->installPrint("$sql"); |
1059 | | - //$this->installPrint(print_r($args, true)); |
1060 | | - $stmt = $this->prepare($sql); |
| 939 | + //$this->installPrint( "Preparing the following SQL:" ); |
| 940 | + //$this->installPrint( "$sql" ); |
| 941 | + //$this->installPrint( print_r( $args, true )); |
| 942 | + $stmt = $this->prepare( $sql ); |
1061 | 943 | |
1062 | 944 | // start a transaction/enter transaction mode |
1063 | 945 | $this->begin(); |
— | — | @@ -1064,15 +946,15 @@ |
1065 | 947 | if ( !$ignore ) { |
1066 | 948 | //$first = true; |
1067 | 949 | foreach ( $args as $row ) { |
1068 | | - //$this->installPrint("Inserting " . print_r($row, true)); |
| 950 | + //$this->installPrint( "Inserting " . print_r( $row, true )); |
1069 | 951 | // insert each row into the database |
1070 | | - $res = $res & $this->execute($stmt, $row); |
1071 | | - if (!$res) { |
1072 | | - $this->installPrint("Last error:"); |
1073 | | - $this->installPrint($this->lastError()); |
| 952 | + $res = $res & $this->execute( $stmt, $row ); |
| 953 | + if ( !$res ) { |
| 954 | + $this->installPrint( "Last error:" ); |
| 955 | + $this->installPrint( $this->lastError() ); |
1074 | 956 | } |
1075 | 957 | // get the last inserted value into a generated column |
1076 | | - $this->calcInsertId($table, $primaryKey, $stmt); |
| 958 | + $this->calcInsertId( $table, $primaryKey, $stmt ); |
1077 | 959 | } |
1078 | 960 | } |
1079 | 961 | else { |
— | — | @@ -1086,24 +968,26 @@ |
1087 | 969 | |
1088 | 970 | foreach ( $args as $row ) { |
1089 | 971 | $overhead = "SAVEPOINT $ignore ON ROLLBACK RETAIN CURSORS"; |
1090 | | - db2_exec($this->mConn, $overhead, $this->mStmtOptions); |
1091 | | - //$this->installPrint("Inserting " . print_r($row, true)); |
| 972 | + db2_exec( $this->mConn, $overhead, $this->mStmtOptions ); |
1092 | 973 | |
1093 | | - $this->execute($stmt, $row); |
1094 | | - //$this->installPrint(wfGetAllCallers()); |
1095 | | - if (!$res2) { |
1096 | | - $this->installPrint("Last error:"); |
1097 | | - $this->installPrint($this->lastError()); |
| 974 | + |
| 975 | + $this->execute( $stmt, $row ); |
| 976 | + |
| 977 | + if ( !$res2 ) { |
| 978 | + $this->installPrint( "Last error:" ); |
| 979 | + $this->installPrint( $this->lastError() ); |
1098 | 980 | } |
1099 | 981 | // get the last inserted value into a generated column |
1100 | | - $this->calcInsertId($table, $primaryKey, $stmt); |
| 982 | + $this->calcInsertId( $table, $primaryKey, $stmt ); |
1101 | 983 | |
1102 | 984 | $errNum = $this->lastErrno(); |
1103 | | - if ($errNum) { |
1104 | | - db2_exec( $this->mConn, "ROLLBACK TO SAVEPOINT $ignore", $this->mStmtOptions ); |
| 985 | + if ( $errNum ) { |
| 986 | + db2_exec( $this->mConn, "ROLLBACK TO SAVEPOINT $ignore", |
| 987 | + $this->mStmtOptions ); |
1105 | 988 | } |
1106 | 989 | else { |
1107 | | - db2_exec( $this->mConn, "RELEASE SAVEPOINT $ignore", $this->mStmtOptions ); |
| 990 | + db2_exec( $this->mConn, "RELEASE SAVEPOINT $ignore", |
| 991 | + $this->mStmtOptions ); |
1108 | 992 | $numrowsinserted++; |
1109 | 993 | } |
1110 | 994 | } |
— | — | @@ -1114,7 +998,7 @@ |
1115 | 999 | } |
1116 | 1000 | // commit either way |
1117 | 1001 | $this->commit(); |
1118 | | - $this->freePrepared($stmt); |
| 1002 | + $this->freePrepared( $stmt ); |
1119 | 1003 | |
1120 | 1004 | return $res; |
1121 | 1005 | } |
— | — | @@ -1125,27 +1009,32 @@ |
1126 | 1010 | * |
1127 | 1011 | * @param $table String: name of the table |
1128 | 1012 | * @param $args Array of hashes of column names with values |
1129 | | - * @return Array: tuple containing filtered array of columns, array of primary keys |
| 1013 | + * @return Array: tuple( filtered array of columns, array of primary keys ) |
1130 | 1014 | */ |
1131 | | - private function removeNullPrimaryKeys($table, $args) { |
| 1015 | + private function removeNullPrimaryKeys( $table, $args ) { |
1132 | 1016 | $schema = $this->mSchema; |
1133 | 1017 | // find out the primary keys |
1134 | | - $keyres = db2_primary_keys($this->mConn, null, strtoupper($schema), strtoupper($table)); |
| 1018 | + $keyres = db2_primary_keys( $this->mConn, null, strtoupper( $schema ), |
| 1019 | + strtoupper( $table )); |
1135 | 1020 | $keys = array(); |
1136 | | - for ($row = $this->fetchObject($keyres); $row != null; $row = $this->fetchRow($keyres)) { |
1137 | | - $keys[] = strtolower($row->column_name); |
| 1021 | + for ( |
| 1022 | + $row = $this->fetchObject( $keyres ); |
| 1023 | + $row != null; |
| 1024 | + $row = $this->fetchObject( $keyres )) |
| 1025 | + { |
| 1026 | + $keys[] = strtolower( $row->column_name ); |
1138 | 1027 | } |
1139 | 1028 | // remove primary keys |
1140 | | - foreach ($args as $ai => $row) { |
1141 | | - foreach ($keys as $ki => $key) { |
1142 | | - if ($row[$key] == null) { |
1143 | | - unset($row[$key]); |
| 1029 | + foreach ( $args as $ai => $row ) { |
| 1030 | + foreach ( $keys as $ki => $key ) { |
| 1031 | + if ( $row[$key] == null ) { |
| 1032 | + unset( $row[$key] ); |
1144 | 1033 | } |
1145 | 1034 | } |
1146 | 1035 | $args[$ai] = $row; |
1147 | 1036 | } |
1148 | 1037 | // return modified hash |
1149 | | - return array($args, $keys); |
| 1038 | + return array( $args, $keys ); |
1150 | 1039 | } |
1151 | 1040 | |
1152 | 1041 | /** |
— | — | @@ -1153,29 +1042,30 @@ |
1154 | 1043 | * |
1155 | 1044 | * @param $table String: The table to UPDATE |
1156 | 1045 | * @param $values An array of values to SET |
1157 | | - * @param $conds An array of conditions (WHERE). Use '*' to update all rows. |
| 1046 | + * @param $conds An array of conditions ( WHERE ). Use '*' to update all rows. |
1158 | 1047 | * @param $fname String: The Class::Function calling this function |
1159 | | - * (for the log) |
| 1048 | + * ( for the log ) |
1160 | 1049 | * @param $options An array of UPDATE options, can be one or |
1161 | 1050 | * more of IGNORE, LOW_PRIORITY |
1162 | 1051 | * @return Boolean |
1163 | 1052 | */ |
1164 | | - public function update( $table, $values, $conds, $fname = 'Database::update', $options = array() ) { |
| 1053 | + public function update( $table, $values, $conds, $fname = 'Database::update', |
| 1054 | + $options = array() ) |
| 1055 | + { |
1165 | 1056 | $table = $this->tableName( $table ); |
1166 | 1057 | $opts = $this->makeUpdateOptions( $options ); |
1167 | | - $sql = "UPDATE $opts $table SET " . $this->makeList( $values, LIST_SET_PREPARED ); |
| 1058 | + $sql = "UPDATE $opts $table SET " |
| 1059 | + . $this->makeList( $values, LIST_SET_PREPARED ); |
1168 | 1060 | if ( $conds != '*' ) { |
1169 | 1061 | $sql .= " WHERE " . $this->makeList( $conds, LIST_AND ); |
1170 | 1062 | } |
1171 | 1063 | $stmt = $this->prepare( $sql ); |
1172 | | - $this->installPrint("UPDATE: " . print_r($values, TRUE)); |
| 1064 | + $this->installPrint( "UPDATE: " . print_r( $values, TRUE )); |
1173 | 1065 | // assuming for now that an array with string keys will work |
1174 | 1066 | // if not, convert to simple array first |
1175 | 1067 | $result = $this->execute( $stmt, $values ); |
1176 | 1068 | $this->freePrepared( $stmt ); |
1177 | | - //$result = $this->query( $sql, $fname ); |
1178 | | - // commit regardless of state |
1179 | | - //$this->commit(); |
| 1069 | + |
1180 | 1070 | return $result; |
1181 | 1071 | } |
1182 | 1072 | |
— | — | @@ -1186,7 +1076,8 @@ |
1187 | 1077 | */ |
1188 | 1078 | public function delete( $table, $conds, $fname = 'Database::delete' ) { |
1189 | 1079 | if ( !$conds ) { |
1190 | | - throw new DBUnexpectedError( $this, 'Database::delete() called with no conditions' ); |
| 1080 | + throw new DBUnexpectedError( $this, |
| 1081 | + 'Database::delete() called with no conditions' ); |
1191 | 1082 | } |
1192 | 1083 | $table = $this->tableName( $table ); |
1193 | 1084 | $sql = "DELETE FROM $table"; |
— | — | @@ -1194,8 +1085,7 @@ |
1195 | 1086 | $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND ); |
1196 | 1087 | } |
1197 | 1088 | $result = $this->query( $sql, $fname ); |
1198 | | - // commit regardless |
1199 | | - //$this->commit(); |
| 1089 | + |
1200 | 1090 | return $result; |
1201 | 1091 | } |
1202 | 1092 | |
— | — | @@ -1221,10 +1111,12 @@ |
1222 | 1112 | * @param $fname String: name of the function for profiling |
1223 | 1113 | * @return nothing |
1224 | 1114 | */ |
1225 | | - function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseIbm_db2::replace' ) { |
| 1115 | + function replace( $table, $uniqueIndexes, $rows, |
| 1116 | + $fname = 'DatabaseIbm_db2::replace' ) |
| 1117 | + { |
1226 | 1118 | $table = $this->tableName( $table ); |
1227 | 1119 | |
1228 | | - if (count($rows)==0) { |
| 1120 | + if ( count( $rows )==0 ) { |
1229 | 1121 | return; |
1230 | 1122 | } |
1231 | 1123 | |
— | — | @@ -1241,9 +1133,9 @@ |
1242 | 1134 | foreach ( $uniqueIndexes as $index ) { |
1243 | 1135 | if ( $first ) { |
1244 | 1136 | $first = false; |
1245 | | - $sql .= "("; |
| 1137 | + $sql .= "( "; |
1246 | 1138 | } else { |
1247 | | - $sql .= ') OR ('; |
| 1139 | + $sql .= ' ) OR ( '; |
1248 | 1140 | } |
1249 | 1141 | if ( is_array( $index ) ) { |
1250 | 1142 | $first2 = true; |
— | — | @@ -1253,19 +1145,20 @@ |
1254 | 1146 | } else { |
1255 | 1147 | $sql .= ' AND '; |
1256 | 1148 | } |
1257 | | - $sql .= $col.'=' . $this->addQuotes( $row[$col] ); |
| 1149 | + $sql .= $col . '=' . $this->addQuotes( $row[$col] ); |
1258 | 1150 | } |
1259 | 1151 | } else { |
1260 | | - $sql .= $index.'=' . $this->addQuotes( $row[$index] ); |
| 1152 | + $sql .= $index . '=' . $this->addQuotes( $row[$index] ); |
1261 | 1153 | } |
1262 | 1154 | } |
1263 | | - $sql .= ')'; |
| 1155 | + $sql .= ' )'; |
1264 | 1156 | $this->query( $sql, $fname ); |
1265 | 1157 | } |
1266 | 1158 | |
1267 | 1159 | # Now insert the row |
1268 | | - $sql = "INSERT INTO $table (" . $this->makeList( array_keys( $row ), LIST_NAMES ) .') VALUES (' . |
1269 | | - $this->makeList( $row, LIST_COMMA ) . ')'; |
| 1160 | + $sql = "INSERT INTO $table ( " |
| 1161 | + . $this->makeList( array_keys( $row ), LIST_NAMES ) |
| 1162 | + .' ) VALUES ( ' . $this->makeList( $row, LIST_COMMA ) . ' )'; |
1270 | 1163 | $this->query( $sql, $fname ); |
1271 | 1164 | } |
1272 | 1165 | } |
— | — | @@ -1315,7 +1208,7 @@ |
1316 | 1209 | $res = $res->result; |
1317 | 1210 | } |
1318 | 1211 | if ( !@db2_free_result( $res ) ) { |
1319 | | - throw new DBUnexpectedError($this, "Unable to free DB2 result\n" ); |
| 1212 | + throw new DBUnexpectedError( $this, "Unable to free DB2 result\n" ); |
1320 | 1213 | } |
1321 | 1214 | } |
1322 | 1215 | |
— | — | @@ -1350,40 +1243,52 @@ |
1351 | 1244 | * @param $table Array or string, table name(s) (prefix auto-added) |
1352 | 1245 | * @param $vars Array or string, field name(s) to be retrieved |
1353 | 1246 | * @param $conds Array or string, condition(s) for WHERE |
1354 | | - * @param $fname String: calling function name (use __METHOD__) for logs/profiling |
1355 | | - * @param $options Associative array of options (e.g. array('GROUP BY' => 'page_title')), |
1356 | | - * see Database::makeSelectOptions code for list of supported stuff |
| 1247 | + * @param $fname String: calling function name (use __METHOD__) |
| 1248 | + * for logs/profiling |
| 1249 | + * @param $options Associative array of options |
| 1250 | + * (e.g. array('GROUP BY' => 'page_title')), |
| 1251 | + * see Database::makeSelectOptions code for list of |
| 1252 | + * supported stuff |
1357 | 1253 | * @param $join_conds Associative array of table join conditions (optional) |
1358 | | - * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) |
1359 | | - * @return Mixed: database result resource (feed to Database::fetchObject or whatever), or false on failure |
| 1254 | + * (e.g. array( 'page' => array('LEFT JOIN', |
| 1255 | + * 'page_latest=rev_id') ) |
| 1256 | + * @return Mixed: database result resource for fetch functions or false |
| 1257 | + * on failure |
1360 | 1258 | */ |
1361 | 1259 | public function select( $table, $vars, $conds='', $fname = 'DatabaseIbm_db2::select', $options = array(), $join_conds = array() ) |
1362 | 1260 | { |
1363 | | - $res = parent::select( $table, $vars, $conds, $fname, $options, $join_conds ); |
| 1261 | + $res = parent::select( $table, $vars, $conds, $fname, $options, |
| 1262 | + $join_conds ); |
1364 | 1263 | |
1365 | 1264 | // We must adjust for offset |
1366 | 1265 | if ( isset( $options['LIMIT'] ) ) { |
1367 | | - if ( isset ($options['OFFSET'] ) ) { |
| 1266 | + if ( isset ( $options['OFFSET'] ) ) { |
1368 | 1267 | $limit = $options['LIMIT']; |
1369 | 1268 | $offset = $options['OFFSET']; |
1370 | 1269 | } |
1371 | 1270 | } |
1372 | 1271 | |
1373 | 1272 | |
1374 | | - // DB2 does not have a proper num_rows() function yet, so we must emulate it |
1375 | | - // DB2 9.5.3/9.5.4 and the corresponding ibm_db2 driver will introduce a working one |
1376 | | - // Yay! |
| 1273 | + // DB2 does not have a proper num_rows() function yet, so we must emulate |
| 1274 | + // DB2 9.5.4 and the corresponding ibm_db2 driver will introduce |
| 1275 | + // a working one |
| 1276 | + // TODO: Yay! |
1377 | 1277 | |
1378 | 1278 | // we want the count |
1379 | | - $vars2 = array('count(*) as num_rows'); |
| 1279 | + $vars2 = array( 'count( * ) as num_rows' ); |
1380 | 1280 | // respecting just the limit option |
1381 | 1281 | $options2 = array(); |
1382 | | - if ( isset( $options['LIMIT'] ) ) $options2['LIMIT'] = $options['LIMIT']; |
| 1282 | + if ( isset( $options['LIMIT'] ) ) { |
| 1283 | + $options2['LIMIT'] = $options['LIMIT']; |
| 1284 | + } |
1383 | 1285 | // but don't try to emulate for GROUP BY |
1384 | | - if ( isset( $options['GROUP BY'] ) ) return $res; |
| 1286 | + if ( isset( $options['GROUP BY'] ) ) { |
| 1287 | + return $res; |
| 1288 | + } |
1385 | 1289 | |
1386 | | - $res2 = parent::select( $table, $vars2, $conds, $fname, $options2, $join_conds ); |
1387 | | - $obj = $this->fetchObject($res2); |
| 1290 | + $res2 = parent::select( $table, $vars2, $conds, $fname, $options2, |
| 1291 | + $join_conds ); |
| 1292 | + $obj = $this->fetchObject( $res2 ); |
1388 | 1293 | $this->mNumRows = $obj->num_rows; |
1389 | 1294 | |
1390 | 1295 | |
— | — | @@ -1411,11 +1316,21 @@ |
1412 | 1317 | } |
1413 | 1318 | } |
1414 | 1319 | |
1415 | | - if ( isset( $options['GROUP BY'] ) ) $preLimitTail .= " GROUP BY {$options['GROUP BY']}"; |
1416 | | - if ( isset( $options['HAVING'] ) ) $preLimitTail .= " HAVING {$options['HAVING']}"; |
1417 | | - if ( isset( $options['ORDER BY'] ) ) $preLimitTail .= " ORDER BY {$options['ORDER BY']}"; |
| 1320 | + if ( isset( $options['GROUP BY'] ) ) { |
| 1321 | + $preLimitTail .= " GROUP BY {$options['GROUP BY']}"; |
| 1322 | + } |
| 1323 | + if ( isset( $options['HAVING'] ) ) { |
| 1324 | + $preLimitTail .= " HAVING {$options['HAVING']}"; |
| 1325 | + } |
| 1326 | + if ( isset( $options['ORDER BY'] ) ) { |
| 1327 | + $preLimitTail .= " ORDER BY {$options['ORDER BY']}"; |
| 1328 | + } |
1418 | 1329 | |
1419 | | - if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) $startOpts .= 'DISTINCT'; |
| 1330 | + if ( isset( $noKeyOptions['DISTINCT'] ) |
| 1331 | + || isset( $noKeyOptions['DISTINCTROW'] ) ) |
| 1332 | + { |
| 1333 | + $startOpts .= 'DISTINCT'; |
| 1334 | + } |
1420 | 1335 | |
1421 | 1336 | return array( $startOpts, '', $preLimitTail, $postLimitTail ); |
1422 | 1337 | } |
— | — | @@ -1425,7 +1340,7 @@ |
1426 | 1341 | * @return string wikitext of a link to the server software's web site |
1427 | 1342 | */ |
1428 | 1343 | public static function getSoftwareLink() { |
1429 | | - return "[http://www.ibm.com/software/data/db2/express/?s_cmp=ECDDWW01&s_tact=MediaWiki IBM DB2]"; |
| 1344 | + return "[http://www.ibm.com/db2/express/ IBM DB2]"; |
1430 | 1345 | } |
1431 | 1346 | |
1432 | 1347 | /** |
— | — | @@ -1445,11 +1360,12 @@ |
1446 | 1361 | public function wasDeadlock() { |
1447 | 1362 | // get SQLSTATE |
1448 | 1363 | $err = $this->lastErrno(); |
1449 | | - switch($err) { |
| 1364 | + switch( $err ) { |
| 1365 | + // This is literal port of the MySQL logic and may be wrong for DB2 |
1450 | 1366 | case '40001': // sql0911n, Deadlock or timeout, rollback |
1451 | 1367 | case '57011': // sql0904n, Resource unavailable, no rollback |
1452 | 1368 | case '57033': // sql0913n, Deadlock or timeout, no rollback |
1453 | | - $this->installPrint("In a deadlock because of SQLSTATE $err"); |
| 1369 | + $this->installPrint( "In a deadlock because of SQLSTATE $err" ); |
1454 | 1370 | return true; |
1455 | 1371 | } |
1456 | 1372 | return false; |
— | — | @@ -1464,7 +1380,8 @@ |
1465 | 1381 | // db2_ping() doesn't exist |
1466 | 1382 | // Emulate |
1467 | 1383 | $this->close(); |
1468 | | - $this->mConn = $this->openUncataloged($this->mDBName, $this->mUser, $this->mPassword, $this->mServer, $this->mPort); |
| 1384 | + $this->mConn = $this->openUncataloged( $this->mDBName, $this->mUser, |
| 1385 | + $this->mPassword, $this->mServer, $this->mPort ); |
1469 | 1386 | |
1470 | 1387 | return false; |
1471 | 1388 | } |
— | — | @@ -1475,18 +1392,27 @@ |
1476 | 1393 | * Not implemented |
1477 | 1394 | * @return string '' |
1478 | 1395 | */ |
1479 | | - public function getStatus( $which="%" ) { $this->installPrint('Not implemented for DB2: getStatus()'); return ''; } |
| 1396 | + public function getStatus( $which="%" ) { |
| 1397 | + $this->installPrint( 'Not implemented for DB2: getStatus()' ); |
| 1398 | + return ''; |
| 1399 | + } |
1480 | 1400 | /** |
1481 | 1401 | * Not implemented |
1482 | 1402 | * @return string $sql |
1483 | 1403 | */ |
1484 | | - public function limitResultForUpdate($sql, $num) { $this->installPrint('Not implemented for DB2: limitResultForUpdate()'); return $sql; } |
| 1404 | + public function limitResultForUpdate( $sql, $num ) { |
| 1405 | + $this->installPrint( 'Not implemented for DB2: limitResultForUpdate()' ); |
| 1406 | + return $sql; |
| 1407 | + } |
1485 | 1408 | |
1486 | 1409 | /** |
1487 | 1410 | * Only useful with fake prepare like in base Database class |
1488 | 1411 | * @return string |
1489 | 1412 | */ |
1490 | | - public function fillPreparedArg( $matches ) { $this->installPrint('Not useful for DB2: fillPreparedArg()'); return ''; } |
| 1413 | + public function fillPreparedArg( $matches ) { |
| 1414 | + $this->installPrint( 'Not useful for DB2: fillPreparedArg()' ); |
| 1415 | + return ''; |
| 1416 | + } |
1491 | 1417 | |
1492 | 1418 | ###################################### |
1493 | 1419 | # Reflection |
— | — | @@ -1500,19 +1426,24 @@ |
1501 | 1427 | * @param $fname String: function name for logging and profiling |
1502 | 1428 | * @return Object query row in object form |
1503 | 1429 | */ |
1504 | | - public function indexInfo( $table, $index, $fname = 'DatabaseIbm_db2::indexExists' ) { |
| 1430 | + public function indexInfo( $table, $index, |
| 1431 | + $fname = 'DatabaseIbm_db2::indexExists' ) |
| 1432 | + { |
1505 | 1433 | $table = $this->tableName( $table ); |
1506 | 1434 | $sql = <<<SQL |
1507 | 1435 | SELECT name as indexname |
1508 | 1436 | FROM sysibm.sysindexes si |
1509 | | -WHERE si.name='$index' AND si.tbname='$table' AND sc.tbcreator='$this->mSchema' |
| 1437 | +WHERE si.name='$index' AND si.tbname='$table' |
| 1438 | +AND sc.tbcreator='$this->mSchema' |
1510 | 1439 | SQL; |
1511 | 1440 | $res = $this->query( $sql, $fname ); |
1512 | 1441 | if ( !$res ) { |
1513 | 1442 | return null; |
1514 | 1443 | } |
1515 | 1444 | $row = $this->fetchObject( $res ); |
1516 | | - if ($row != null) return $row; |
| 1445 | + if ( $row != null ) { |
| 1446 | + return $row; |
| 1447 | + } |
1517 | 1448 | else return false; |
1518 | 1449 | } |
1519 | 1450 | |
— | — | @@ -1523,7 +1454,7 @@ |
1524 | 1455 | * @return IBM_DB2Field |
1525 | 1456 | */ |
1526 | 1457 | public function fieldInfo( $table, $field ) { |
1527 | | - return IBM_DB2Field::fromText($this, $table, $field); |
| 1458 | + return IBM_DB2Field::fromText( $this, $table, $field ); |
1528 | 1459 | } |
1529 | 1460 | |
1530 | 1461 | /** |
— | — | @@ -1546,19 +1477,22 @@ |
1547 | 1478 | * @param $fname function name for profiling |
1548 | 1479 | * @return Bool |
1549 | 1480 | */ |
1550 | | - public function indexUnique ($table, $index, $fname = 'Database::indexUnique' ) { |
| 1481 | + public function indexUnique ( $table, $index, |
| 1482 | + $fname = 'Database::indexUnique' ) |
| 1483 | + { |
1551 | 1484 | $table = $this->tableName( $table ); |
1552 | 1485 | $sql = <<<SQL |
1553 | 1486 | SELECT si.name as indexname |
1554 | 1487 | FROM sysibm.sysindexes si |
1555 | | -WHERE si.name='$index' AND si.tbname='$table' AND sc.tbcreator='$this->mSchema' |
1556 | | -AND si.uniquerule IN ('U', 'P') |
| 1488 | +WHERE si.name='$index' AND si.tbname='$table' |
| 1489 | +AND sc.tbcreator='$this->mSchema' |
| 1490 | +AND si.uniquerule IN ( 'U', 'P' ) |
1557 | 1491 | SQL; |
1558 | 1492 | $res = $this->query( $sql, $fname ); |
1559 | 1493 | if ( !$res ) { |
1560 | 1494 | return null; |
1561 | 1495 | } |
1562 | | - if ($this->fetchObject( $res )) { |
| 1496 | + if ( $this->fetchObject( $res ) ) { |
1563 | 1497 | return true; |
1564 | 1498 | } |
1565 | 1499 | return false; |
— | — | @@ -1576,10 +1510,11 @@ |
1577 | 1511 | $sql = <<<SQL |
1578 | 1512 | SELECT length as size |
1579 | 1513 | FROM sysibm.syscolumns sc |
1580 | | -WHERE sc.name='$field' AND sc.tbname='$table' AND sc.tbcreator='$this->mSchema' |
| 1514 | +WHERE sc.name='$field' AND sc.tbname='$table' |
| 1515 | +AND sc.tbcreator='$this->mSchema' |
1581 | 1516 | SQL; |
1582 | | - $res = $this->query($sql); |
1583 | | - $row = $this->fetchObject($res); |
| 1517 | + $res = $this->query( $sql ); |
| 1518 | + $row = $this->fetchObject( $res ); |
1584 | 1519 | $size = $row->size; |
1585 | 1520 | return $size; |
1586 | 1521 | } |
— | — | @@ -1593,18 +1528,26 @@ |
1594 | 1529 | * @param $conds Array: conditionals for join table |
1595 | 1530 | * @param $fname String: function name for profiling |
1596 | 1531 | */ |
1597 | | - public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = "DatabaseIbm_db2::deleteJoin" ) { |
| 1532 | + public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, |
| 1533 | + $conds, $fname = "DatabaseIbm_db2::deleteJoin" ) |
| 1534 | + { |
1598 | 1535 | if ( !$conds ) { |
1599 | | - throw new DBUnexpectedError($this, 'Database::deleteJoin() called with empty $conds' ); |
| 1536 | + throw new DBUnexpectedError( $this, |
| 1537 | + 'Database::deleteJoin() called with empty $conds' ); |
1600 | 1538 | } |
1601 | 1539 | |
1602 | 1540 | $delTable = $this->tableName( $delTable ); |
1603 | 1541 | $joinTable = $this->tableName( $joinTable ); |
1604 | | - $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable "; |
| 1542 | + $sql = <<<SQL |
| 1543 | +DELETE FROM $delTable |
| 1544 | +WHERE $delVar IN ( |
| 1545 | + SELECT $joinVar FROM $joinTable |
| 1546 | + |
| 1547 | +SQL; |
1605 | 1548 | if ( $conds != '*' ) { |
1606 | 1549 | $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND ); |
1607 | 1550 | } |
1608 | | - $sql .= ')'; |
| 1551 | + $sql .= ' )'; |
1609 | 1552 | |
1610 | 1553 | $this->query( $sql, $fname ); |
1611 | 1554 | } |
— | — | @@ -1614,8 +1557,8 @@ |
1615 | 1558 | * @param $b Mixed: data to be encoded |
1616 | 1559 | * @return IBM_DB2Blob |
1617 | 1560 | */ |
1618 | | - public function encodeBlob($b) { |
1619 | | - return new IBM_DB2Blob($b); |
| 1561 | + public function encodeBlob( $b ) { |
| 1562 | + return new IBM_DB2Blob( $b ); |
1620 | 1563 | } |
1621 | 1564 | |
1622 | 1565 | /** |
— | — | @@ -1623,13 +1566,14 @@ |
1624 | 1567 | * @param $b IBM_DB2Blob: data to be decoded |
1625 | 1568 | * @return mixed |
1626 | 1569 | */ |
1627 | | - public function decodeBlob($b) { |
| 1570 | + public function decodeBlob( $b ) { |
1628 | 1571 | return "$b"; |
1629 | 1572 | } |
1630 | 1573 | |
1631 | 1574 | /** |
1632 | 1575 | * Convert into a list of string being concatenated |
1633 | | - * @param $stringList Array: strings that need to be joined together by the SQL engine |
| 1576 | + * @param $stringList Array: strings that need to be joined together |
| 1577 | + * by the SQL engine |
1634 | 1578 | * @return String: joined by the concatenation operator |
1635 | 1579 | */ |
1636 | 1580 | public function buildConcat( $stringList ) { |
— | — | @@ -1665,7 +1609,7 @@ |
1666 | 1610 | * @return resource a prepared DB2 SQL statement |
1667 | 1611 | */ |
1668 | 1612 | public function prepare( $sql, $func = 'DB2::prepare' ) { |
1669 | | - $stmt = db2_prepare($this->mConn, $sql, $this->mStmtOptions); |
| 1613 | + $stmt = db2_prepare( $this->mConn, $sql, $this->mStmtOptions ); |
1670 | 1614 | return $stmt; |
1671 | 1615 | } |
1672 | 1616 | |
— | — | @@ -1674,7 +1618,7 @@ |
1675 | 1619 | * @return Boolean success or failure |
1676 | 1620 | */ |
1677 | 1621 | public function freePrepared( $prepared ) { |
1678 | | - return db2_free_stmt($prepared); |
| 1622 | + return db2_free_stmt( $prepared ); |
1679 | 1623 | } |
1680 | 1624 | |
1681 | 1625 | /** |
— | — | @@ -1689,9 +1633,9 @@ |
1690 | 1634 | $args = func_get_args(); |
1691 | 1635 | array_shift( $args ); |
1692 | 1636 | } |
1693 | | - $res = db2_execute($prepared, $args); |
| 1637 | + $res = db2_execute( $prepared, $args ); |
1694 | 1638 | if ( !$res ) { |
1695 | | - $this->installPrint(db2_stmt_errormsg()); |
| 1639 | + $this->installPrint( db2_stmt_errormsg() ); |
1696 | 1640 | } |
1697 | 1641 | return $res; |
1698 | 1642 | } |
— | — | @@ -1726,8 +1670,8 @@ |
1727 | 1671 | reset( $args ); |
1728 | 1672 | $this->preparedArgs =& $args; |
1729 | 1673 | |
1730 | | - foreach ($args as $i => $arg) { |
1731 | | - db2_bind_param($preparedQuery, $i+1, $args[$i]); |
| 1674 | + foreach ( $args as $i => $arg ) { |
| 1675 | + db2_bind_param( $preparedQuery, $i+1, $args[$i] ); |
1732 | 1676 | } |
1733 | 1677 | |
1734 | 1678 | return $preparedQuery; |
— | — | @@ -1736,7 +1680,7 @@ |
1737 | 1681 | /** |
1738 | 1682 | * Switches module between regular and install modes |
1739 | 1683 | */ |
1740 | | - public function setMode($mode) { |
| 1684 | + public function setMode( $mode ) { |
1741 | 1685 | $old = $this->mMode; |
1742 | 1686 | $this->mMode = $mode; |
1743 | 1687 | return $old; |
— | — | @@ -1748,9 +1692,9 @@ |
1749 | 1693 | * @param $field String |
1750 | 1694 | * @return String |
1751 | 1695 | */ |
1752 | | - function bitNot($field) { |
| 1696 | + function bitNot( $field ) { |
1753 | 1697 | //expecting bit-fields smaller than 4bytes |
1754 | | - return 'BITNOT('.$field.')'; |
| 1698 | + return "BITNOT( $field )"; |
1755 | 1699 | } |
1756 | 1700 | |
1757 | 1701 | /** |
— | — | @@ -1760,8 +1704,8 @@ |
1761 | 1705 | * @param $fieldRight String |
1762 | 1706 | * @return String |
1763 | 1707 | */ |
1764 | | - function bitAnd($fieldLeft, $fieldRight) { |
1765 | | - return 'BITAND('.$fieldLeft.', '.$fieldRight.')'; |
| 1708 | + function bitAnd( $fieldLeft, $fieldRight ) { |
| 1709 | + return "BITAND( $fieldLeft, $fieldRight )"; |
1766 | 1710 | } |
1767 | 1711 | |
1768 | 1712 | /** |
— | — | @@ -1771,14 +1715,16 @@ |
1772 | 1716 | * @param $fieldRight String |
1773 | 1717 | * @return String |
1774 | 1718 | */ |
1775 | | - function bitOr($fieldLeft, $fieldRight) { |
1776 | | - return 'BITOR('.$fieldLeft.', '.$fieldRight.')'; |
| 1719 | + function bitOr( $fieldLeft, $fieldRight ) { |
| 1720 | + return "BITOR( $fieldLeft, $fieldRight )"; |
1777 | 1721 | } |
1778 | 1722 | } |
1779 | 1723 | |
1780 | 1724 | class IBM_DB2Helper { |
1781 | | - public static function makeArray($maybeArray) { |
1782 | | - if ( !is_array( $maybeArray ) ) $maybeArray = array( $maybeArray ); |
| 1725 | + public static function makeArray( $maybeArray ) { |
| 1726 | + if ( !is_array( $maybeArray ) ) { |
| 1727 | + return array( $maybeArray ); |
| 1728 | + } |
1783 | 1729 | |
1784 | 1730 | return $maybeArray; |
1785 | 1731 | } |