Index: trunk/phase3/includes/db/DatabaseIbm_db2.php |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | private $max_length = 0; |
23 | 23 | |
24 | 24 | /** |
25 | | - * Builder method for the class |
| 25 | + * Builder method for the class |
26 | 26 | * @param $db DatabaseIbm_db2: Database interface |
27 | 27 | * @param $table String: table name |
28 | 28 | * @param $field String: column name |
— | — | @@ -93,7 +93,7 @@ |
94 | 94 | public function getData() { |
95 | 95 | return $this->mData; |
96 | 96 | } |
97 | | - |
| 97 | + |
98 | 98 | public function __toString() |
99 | 99 | { |
100 | 100 | return $this->mData; |
— | — | @@ -122,7 +122,7 @@ |
123 | 123 | protected $mFakeSlaveLag = null, $mFakeMaster = false; |
124 | 124 | * |
125 | 125 | */ |
126 | | - |
| 126 | + |
127 | 127 | /** Database server port */ |
128 | 128 | protected $mPort = null; |
129 | 129 | /** Schema for tables, stored procedures, triggers */ |
— | — | @@ -135,37 +135,37 @@ |
136 | 136 | protected $mAffectedRows = null; |
137 | 137 | /** Number of rows returned by last SELECT */ |
138 | 138 | protected $mNumRows = null; |
139 | | - |
| 139 | + |
140 | 140 | /** Connection config options - see constructor */ |
141 | 141 | public $mConnOptions = array(); |
142 | 142 | /** Statement config options -- see constructor */ |
143 | 143 | public $mStmtOptions = array(); |
144 | | - |
| 144 | + |
145 | 145 | /** Default schema */ |
146 | 146 | const USE_GLOBAL = "mediawiki"; |
147 | | - |
| 147 | + |
148 | 148 | /** Option that applies to nothing */ |
149 | 149 | const NONE_OPTION = 0x00; |
150 | 150 | /** Option that applies to connection objects */ |
151 | 151 | const CONN_OPTION = 0x01; |
152 | 152 | /** Option that applies to statement objects */ |
153 | 153 | const STMT_OPTION = 0x02; |
154 | | - |
| 154 | + |
155 | 155 | /** Regular operation mode -- minimal debug messages */ |
156 | 156 | const REGULAR_MODE = 'regular'; |
157 | 157 | /** Installation mode -- lots of debug messages */ |
158 | 158 | const INSTALL_MODE = 'install'; |
159 | | - |
| 159 | + |
160 | 160 | /** Controls the level of debug message output */ |
161 | 161 | protected $mMode = self::REGULAR_MODE; |
162 | | - |
| 162 | + |
163 | 163 | /** Last sequence value used for a primary key */ |
164 | 164 | protected $mInsertId = null; |
165 | | - |
| 165 | + |
166 | 166 | ###################################### |
167 | 167 | # Getters and Setters |
168 | 168 | ###################################### |
169 | | - |
| 169 | + |
170 | 170 | /** |
171 | 171 | * Returns true if this database supports (and uses) cascading deletes |
172 | 172 | */ |
— | — | @@ -189,7 +189,7 @@ |
190 | 190 | function strictIPs() { |
191 | 191 | return true; |
192 | 192 | } |
193 | | - |
| 193 | + |
194 | 194 | /** |
195 | 195 | * Returns true if this database uses timestamps rather than integers |
196 | 196 | */ |
— | — | @@ -227,7 +227,7 @@ |
228 | 228 | function functionalIndexes() { |
229 | 229 | return true; |
230 | 230 | } |
231 | | - |
| 231 | + |
232 | 232 | /** |
233 | 233 | * Returns a unique string representing the wiki on the server |
234 | 234 | */ |
— | — | @@ -242,14 +242,14 @@ |
243 | 243 | function getType() { |
244 | 244 | return 'ibm_db2'; |
245 | 245 | } |
246 | | - |
| 246 | + |
247 | 247 | ###################################### |
248 | 248 | # Setup |
249 | 249 | ###################################### |
250 | | - |
251 | | - |
| 250 | + |
| 251 | + |
252 | 252 | /** |
253 | | - * |
| 253 | + * |
254 | 254 | * @param $server String: hostname of database server |
255 | 255 | * @param $user String: username |
256 | 256 | * @param $password String: password |
— | — | @@ -272,14 +272,14 @@ |
273 | 273 | $this->mOut =& $wgOut; |
274 | 274 | $this->mFailFunction = $failFunction; |
275 | 275 | $this->mFlags = DBO_TRX | $flags; |
276 | | - |
| 276 | + |
277 | 277 | if ( $schema == self::USE_GLOBAL ) { |
278 | 278 | $this->mSchema = $wgDBmwschema; |
279 | 279 | } |
280 | 280 | else { |
281 | 281 | $this->mSchema = $schema; |
282 | 282 | } |
283 | | - |
| 283 | + |
284 | 284 | // configure the connection and statement objects |
285 | 285 | $this->setDB2Option( 'db2_attr_case', 'DB2_CASE_LOWER', |
286 | 286 | self::CONN_OPTION | self::STMT_OPTION ); |
— | — | @@ -287,10 +287,10 @@ |
288 | 288 | self::STMT_OPTION ); |
289 | 289 | $this->setDB2Option( 'rowcount', 'DB2_ROWCOUNT_PREFETCH_ON', |
290 | 290 | self::STMT_OPTION ); |
291 | | - |
| 291 | + |
292 | 292 | $this->open( $server, $user, $password, $dbName ); |
293 | 293 | } |
294 | | - |
| 294 | + |
295 | 295 | /** |
296 | 296 | * Enables options only if the ibm_db2 extension version supports them |
297 | 297 | * @param $name String: name of the option in the options array |
— | — | @@ -311,7 +311,7 @@ |
312 | 312 | "$const is not defined. ibm_db2 version is likely too low." ); |
313 | 313 | } |
314 | 314 | } |
315 | | - |
| 315 | + |
316 | 316 | /** |
317 | 317 | * Outputs debug information in the appropriate place |
318 | 318 | * @param $string String: the relevant debug message |
— | — | @@ -321,9 +321,9 @@ |
322 | 322 | if ( $this->mMode == self::INSTALL_MODE ) { |
323 | 323 | print "<li><pre>$string</pre></li>"; |
324 | 324 | flush(); |
325 | | - } |
| 325 | + } |
326 | 326 | } |
327 | | - |
| 327 | + |
328 | 328 | /** |
329 | 329 | * Opens a database connection and returns it |
330 | 330 | * Closes any existing connection |
— | — | @@ -338,7 +338,7 @@ |
339 | 339 | // Load the port number |
340 | 340 | global $wgDBport; |
341 | 341 | wfProfileIn( __METHOD__ ); |
342 | | - |
| 342 | + |
343 | 343 | // Load IBM DB2 driver if missing |
344 | 344 | wfDl( 'ibm_db2' ); |
345 | 345 | |
— | — | @@ -355,7 +355,7 @@ |
356 | 356 | if ( strlen( $user ) < 1) { |
357 | 357 | return null; |
358 | 358 | } |
359 | | - |
| 359 | + |
360 | 360 | // Close existing connection |
361 | 361 | $this->close(); |
362 | 362 | // Cache conn info |
— | — | @@ -364,9 +364,9 @@ |
365 | 365 | $this->mUser = $user; |
366 | 366 | $this->mPassword = $password; |
367 | 367 | $this->mDBname = $dbName; |
368 | | - |
| 368 | + |
369 | 369 | $this->openUncataloged( $dbName, $user, $password, $server, $port ); |
370 | | - |
| 370 | + |
371 | 371 | // Apply connection config |
372 | 372 | db2_set_option( $this->mConn, $this->mConnOptions, 1 ); |
373 | 373 | // Some MediaWiki code is still transaction-less (?). |
— | — | @@ -385,11 +385,11 @@ |
386 | 386 | |
387 | 387 | $this->mOpened = true; |
388 | 388 | $this->applySchema(); |
389 | | - |
| 389 | + |
390 | 390 | wfProfileOut( __METHOD__ ); |
391 | 391 | return $this->mConn; |
392 | 392 | } |
393 | | - |
| 393 | + |
394 | 394 | /** |
395 | 395 | * Opens a cataloged database connection, sets mConn |
396 | 396 | */ |
— | — | @@ -397,7 +397,7 @@ |
398 | 398 | { |
399 | 399 | @$this->mConn = db2_pconnect( $dbName, $user, $password ); |
400 | 400 | } |
401 | | - |
| 401 | + |
402 | 402 | /** |
403 | 403 | * Opens an uncataloged database connection, sets mConn |
404 | 404 | */ |
— | — | @@ -411,10 +411,10 @@ |
412 | 412 | $str .= "PROTOCOL=TCPIP;"; |
413 | 413 | $str .= "UID=$user;"; |
414 | 414 | $str .= "PWD=$password;"; |
415 | | - |
| 415 | + |
416 | 416 | @$this->mConn = db2_pconnect( $str, $user, $password ); |
417 | 417 | } |
418 | | - |
| 418 | + |
419 | 419 | /** |
420 | 420 | * Closes a database connection, if it is open |
421 | 421 | * Returns success, true if already closed |
— | — | @@ -431,7 +431,7 @@ |
432 | 432 | return true; |
433 | 433 | } |
434 | 434 | } |
435 | | - |
| 435 | + |
436 | 436 | /** |
437 | 437 | * Returns a fresh instance of this class |
438 | 438 | * |
— | — | @@ -449,7 +449,7 @@ |
450 | 450 | return new DatabaseIbm_db2( $server, $user, $password, $dbName, |
451 | 451 | $failFunction, $flags ); |
452 | 452 | } |
453 | | - |
| 453 | + |
454 | 454 | /** |
455 | 455 | * Retrieves the most current database error |
456 | 456 | * Forces a database rollback |
— | — | @@ -465,10 +465,10 @@ |
466 | 466 | //$this->rollback(); |
467 | 467 | return $stmterr; |
468 | 468 | } |
469 | | - |
| 469 | + |
470 | 470 | return false; |
471 | 471 | } |
472 | | - |
| 472 | + |
473 | 473 | /** |
474 | 474 | * Get the last error number |
475 | 475 | * Return 0 if no error |
— | — | @@ -485,13 +485,13 @@ |
486 | 486 | } |
487 | 487 | return 0; |
488 | 488 | } |
489 | | - |
| 489 | + |
490 | 490 | /** |
491 | 491 | * Is a database connection open? |
492 | | - * @return |
| 492 | + * @return |
493 | 493 | */ |
494 | 494 | public function isOpen() { return $this->mOpened; } |
495 | | - |
| 495 | + |
496 | 496 | /** |
497 | 497 | * The DBMS-dependent part of query() |
498 | 498 | * @param $sql String: SQL query. |
— | — | @@ -501,7 +501,7 @@ |
502 | 502 | /*private*/ |
503 | 503 | public function doQuery( $sql ) { |
504 | 504 | $this->applySchema(); |
505 | | - |
| 505 | + |
506 | 506 | $ret = db2_exec( $this->mConn, $sql, $this->mStmtOptions ); |
507 | 507 | if( $ret == FALSE ) { |
508 | 508 | $error = db2_stmt_errormsg(); |
— | — | @@ -514,7 +514,7 @@ |
515 | 515 | $this->mAffectedRows = null; // Not calculated until asked for |
516 | 516 | return $ret; |
517 | 517 | } |
518 | | - |
| 518 | + |
519 | 519 | /** |
520 | 520 | * @return string Version information from the database |
521 | 521 | */ |
— | — | @@ -522,7 +522,7 @@ |
523 | 523 | $info = db2_server_info( $this->mConn ); |
524 | 524 | return $info->DBMS_VER; |
525 | 525 | } |
526 | | - |
| 526 | + |
527 | 527 | /** |
528 | 528 | * Queries whether a given table exists |
529 | 529 | * @return boolean |
— | — | @@ -535,17 +535,17 @@ |
536 | 536 | EOF; |
537 | 537 | $res = $this->query( $sql ); |
538 | 538 | if ( !$res ) return false; |
539 | | - |
| 539 | + |
540 | 540 | // If the table exists, there should be one of it |
541 | 541 | @$row = $this->fetchRow( $res ); |
542 | 542 | $count = $row[0]; |
543 | 543 | if ( $count == '1' or $count == 1 ) { |
544 | 544 | return true; |
545 | 545 | } |
546 | | - |
| 546 | + |
547 | 547 | return false; |
548 | 548 | } |
549 | | - |
| 549 | + |
550 | 550 | /** |
551 | 551 | * Fetch the next row from the given result object, in object form. |
552 | 552 | * Fields can be retrieved with $row->fieldname, with fields acting like |
— | — | @@ -586,25 +586,25 @@ |
587 | 587 | } |
588 | 588 | return $row; |
589 | 589 | } |
590 | | - |
| 590 | + |
591 | 591 | /** |
592 | 592 | * Override if introduced to base Database class |
593 | 593 | */ |
594 | 594 | public function initial_setup() { |
595 | 595 | // do nothing |
596 | 596 | } |
597 | | - |
| 597 | + |
598 | 598 | /** |
599 | 599 | * Create tables, stored procedures, and so on |
600 | 600 | */ |
601 | 601 | public function setup_database() { |
602 | 602 | try { |
603 | 603 | // TODO: switch to root login if available |
604 | | - |
| 604 | + |
605 | 605 | // Switch into the correct namespace |
606 | 606 | $this->applySchema(); |
607 | 607 | $this->begin(); |
608 | | - |
| 608 | + |
609 | 609 | $res = $this->sourceFile( "../maintenance/ibm_db2/tables.sql" ); |
610 | 610 | if ( $res !== true ) { |
611 | 611 | print " <b>FAILED</b>: " . htmlspecialchars( $res ) . "</li>"; |
— | — | @@ -618,16 +618,16 @@ |
619 | 619 | print "<li>Foreign keys done</li>"; |
620 | 620 | } |
621 | 621 | $res = null; |
622 | | - |
| 622 | + |
623 | 623 | // TODO: populate interwiki links |
624 | | - |
| 624 | + |
625 | 625 | if ( $this->lastError() ) { |
626 | 626 | $this->installPrint( |
627 | 627 | "Errors encountered during table creation -- rolled back" ); |
628 | 628 | $this->installPrint( "Please install again" ); |
629 | 629 | $this->rollback(); |
630 | 630 | } |
631 | | - else { |
| 631 | + else { |
632 | 632 | $this->commit(); |
633 | 633 | } |
634 | 634 | } |
— | — | @@ -660,7 +660,7 @@ |
661 | 661 | return "'$s'"; |
662 | 662 | } |
663 | 663 | } |
664 | | - |
| 664 | + |
665 | 665 | /** |
666 | 666 | * Verifies that a DB2 column/field type is numeric |
667 | 667 | * @return bool true if numeric |
— | — | @@ -680,7 +680,7 @@ |
681 | 681 | } |
682 | 682 | return false; |
683 | 683 | } |
684 | | - |
| 684 | + |
685 | 685 | /** |
686 | 686 | * Alias for addQuotes() |
687 | 687 | * @param $s String: string to escape |
— | — | @@ -688,7 +688,7 @@ |
689 | 689 | */ |
690 | 690 | public function strencode( $s ) { |
691 | 691 | // Bloody useless function |
692 | | - // Prepends backslashes to \x00, \n, \r, \, ', " and \x1a. |
| 692 | + // Prepends backslashes to \x00, \n, \r, \, ', " and \x1a. |
693 | 693 | // But also necessary |
694 | 694 | $s = db2_escape_string( $s ); |
695 | 695 | // Wide characters are evil -- some of them look like ' |
— | — | @@ -699,7 +699,7 @@ |
700 | 700 | $s = str_replace( $from, $to, $s ); // DB2 expects '', not \' escaping |
701 | 701 | return $s; |
702 | 702 | } |
703 | | - |
| 703 | + |
704 | 704 | /** |
705 | 705 | * Switch into the database schema |
706 | 706 | */ |
— | — | @@ -709,39 +709,39 @@ |
710 | 710 | $this->begin(); |
711 | 711 | $this->doQuery( "SET SCHEMA = $this->mSchema" ); |
712 | 712 | $this->commit(); |
713 | | - } |
| 713 | + } |
714 | 714 | } |
715 | | - |
| 715 | + |
716 | 716 | /** |
717 | 717 | * Start a transaction (mandatory) |
718 | 718 | */ |
719 | 719 | public function begin( $fname = 'DatabaseIbm_db2::begin' ) { |
720 | 720 | // BEGIN is implicit for DB2 |
721 | 721 | // However, it requires that AutoCommit be off. |
722 | | - |
| 722 | + |
723 | 723 | // Some MediaWiki code is still transaction-less (?). |
724 | 724 | // The strategy is to keep AutoCommit on for that code |
725 | 725 | // but switch it off whenever a transaction is begun. |
726 | 726 | db2_autocommit( $this->mConn, DB2_AUTOCOMMIT_OFF ); |
727 | | - |
| 727 | + |
728 | 728 | $this->mTrxLevel = 1; |
729 | 729 | } |
730 | | - |
| 730 | + |
731 | 731 | /** |
732 | 732 | * End a transaction |
733 | 733 | * Must have a preceding begin() |
734 | 734 | */ |
735 | 735 | public function commit( $fname = 'DatabaseIbm_db2::commit' ) { |
736 | 736 | db2_commit( $this->mConn ); |
737 | | - |
| 737 | + |
738 | 738 | // Some MediaWiki code is still transaction-less (?). |
739 | 739 | // The strategy is to keep AutoCommit on for that code |
740 | 740 | // but switch it off whenever a transaction is begun. |
741 | 741 | db2_autocommit( $this->mConn, DB2_AUTOCOMMIT_ON ); |
742 | | - |
| 742 | + |
743 | 743 | $this->mTrxLevel = 0; |
744 | 744 | } |
745 | | - |
| 745 | + |
746 | 746 | /** |
747 | 747 | * Cancel a transaction |
748 | 748 | */ |
— | — | @@ -752,7 +752,7 @@ |
753 | 753 | db2_autocommit( $this->mConn, DB2_AUTOCOMMIT_ON ); |
754 | 754 | $this->mTrxLevel = 0; |
755 | 755 | } |
756 | | - |
| 756 | + |
757 | 757 | /** |
758 | 758 | * Makes an encoded list of strings from an array |
759 | 759 | * $mode: |
— | — | @@ -768,7 +768,7 @@ |
769 | 769 | throw new DBUnexpectedError( $this, |
770 | 770 | 'DatabaseBase::makeList called with incorrect parameters' ); |
771 | 771 | } |
772 | | - |
| 772 | + |
773 | 773 | // if this is for a prepared UPDATE statement |
774 | 774 | // (this should be promoted to the parent class |
775 | 775 | // once other databases use prepared statements) |
— | — | @@ -785,14 +785,14 @@ |
786 | 786 | } |
787 | 787 | } |
788 | 788 | $list .= ''; |
789 | | - |
| 789 | + |
790 | 790 | return $list; |
791 | 791 | } |
792 | | - |
| 792 | + |
793 | 793 | // otherwise, call the usual function |
794 | 794 | return parent::makeList( $a, $mode ); |
795 | 795 | } |
796 | | - |
| 796 | + |
797 | 797 | /** |
798 | 798 | * Construct a LIMIT query with optional offset |
799 | 799 | * This is used for query pages |
— | — | @@ -815,17 +815,17 @@ |
816 | 816 | } |
817 | 817 | return "$sql FETCH FIRST $limit ROWS ONLY "; |
818 | 818 | } |
819 | | - |
| 819 | + |
820 | 820 | /** |
821 | 821 | * Handle reserved keyword replacement in table names |
822 | | - * @return |
| 822 | + * @return |
823 | 823 | * @param $name Object |
824 | 824 | */ |
825 | 825 | public function tableName( $name ) { |
826 | 826 | // we want maximum compatibility with MySQL schema |
827 | 827 | return $name; |
828 | 828 | } |
829 | | - |
| 829 | + |
830 | 830 | /** |
831 | 831 | * Generates a timestamp in an insertable format |
832 | 832 | * @return string timestamp value |
— | — | @@ -855,7 +855,7 @@ |
856 | 856 | */ |
857 | 857 | return null; |
858 | 858 | } |
859 | | - |
| 859 | + |
860 | 860 | /** |
861 | 861 | * This must be called after nextSequenceVal |
862 | 862 | * @return Last sequence value used as a primary key |
— | — | @@ -863,7 +863,7 @@ |
864 | 864 | public function insertId() { |
865 | 865 | return $this->mInsertId; |
866 | 866 | } |
867 | | - |
| 867 | + |
868 | 868 | /** |
869 | 869 | * Updates the mInsertId property with the value of the last insert |
870 | 870 | * into a generated column |
— | — | @@ -877,7 +877,7 @@ |
878 | 878 | $this->mInsertId = db2_last_insert_id( $this->mConn ); |
879 | 879 | } |
880 | 880 | } |
881 | | - |
| 881 | + |
882 | 882 | /** |
883 | 883 | * INSERT wrapper, inserts an array into a table |
884 | 884 | * |
— | — | @@ -905,7 +905,7 @@ |
906 | 906 | if ( !( isset( $args[0] ) && is_array( $args[0] ) ) ) { |
907 | 907 | $args = array( $args ); |
908 | 908 | } |
909 | | - |
| 909 | + |
910 | 910 | // prevent insertion of NULL into primary key columns |
911 | 911 | list( $args, $primaryKeys ) = $this->removeNullPrimaryKeys( $table, $args ); |
912 | 912 | // if there's only one primary key |
— | — | @@ -914,7 +914,7 @@ |
915 | 915 | if ( count( $primaryKeys ) == 1 ) { |
916 | 916 | $primaryKey = $primaryKeys[0]; |
917 | 917 | } |
918 | | - |
| 918 | + |
919 | 919 | // get column names |
920 | 920 | $keys = array_keys( $args[0] ); |
921 | 921 | $key_count = count( $keys ); |
— | — | @@ -939,7 +939,7 @@ |
940 | 940 | //$this->installPrint( "$sql" ); |
941 | 941 | //$this->installPrint( print_r( $args, true )); |
942 | 942 | $stmt = $this->prepare( $sql ); |
943 | | - |
| 943 | + |
944 | 944 | // start a transaction/enter transaction mode |
945 | 945 | $this->begin(); |
946 | 946 | |
— | — | @@ -962,24 +962,24 @@ |
963 | 963 | // For future use, we may want to track the number of actual inserts |
964 | 964 | // Right now, insert (all writes) simply return true/false |
965 | 965 | $numrowsinserted = 0; |
966 | | - |
| 966 | + |
967 | 967 | // always return true |
968 | 968 | $res = true; |
969 | | - |
| 969 | + |
970 | 970 | foreach ( $args as $row ) { |
971 | 971 | $overhead = "SAVEPOINT $ignore ON ROLLBACK RETAIN CURSORS"; |
972 | 972 | db2_exec( $this->mConn, $overhead, $this->mStmtOptions ); |
973 | | - |
974 | | - |
| 973 | + |
| 974 | + |
975 | 975 | $this->execute( $stmt, $row ); |
976 | | - |
| 976 | + |
977 | 977 | if ( !$res2 ) { |
978 | 978 | $this->installPrint( "Last error:" ); |
979 | 979 | $this->installPrint( $this->lastError() ); |
980 | 980 | } |
981 | 981 | // get the last inserted value into a generated column |
982 | 982 | $this->calcInsertId( $table, $primaryKey, $stmt ); |
983 | | - |
| 983 | + |
984 | 984 | $errNum = $this->lastErrno(); |
985 | 985 | if ( $errNum ) { |
986 | 986 | db2_exec( $this->mConn, "ROLLBACK TO SAVEPOINT $ignore", |
— | — | @@ -991,7 +991,7 @@ |
992 | 992 | $numrowsinserted++; |
993 | 993 | } |
994 | 994 | } |
995 | | - |
| 995 | + |
996 | 996 | $olde = error_reporting( $olde ); |
997 | 997 | // Set the affected row count for the whole operation |
998 | 998 | $this->mAffectedRows = $numrowsinserted; |
— | — | @@ -999,14 +999,14 @@ |
1000 | 1000 | // commit either way |
1001 | 1001 | $this->commit(); |
1002 | 1002 | $this->freePrepared( $stmt ); |
1003 | | - |
| 1003 | + |
1004 | 1004 | return $res; |
1005 | 1005 | } |
1006 | | - |
| 1006 | + |
1007 | 1007 | /** |
1008 | 1008 | * Given a table name and a hash of columns with values |
1009 | 1009 | * Removes primary key columns from the hash where the value is NULL |
1010 | | - * |
| 1010 | + * |
1011 | 1011 | * @param $table String: name of the table |
1012 | 1012 | * @param $args Array of hashes of column names with values |
1013 | 1013 | * @return Array: tuple( filtered array of columns, array of primary keys ) |
— | — | @@ -1036,7 +1036,7 @@ |
1037 | 1037 | // return modified hash |
1038 | 1038 | return array( $args, $keys ); |
1039 | 1039 | } |
1040 | | - |
| 1040 | + |
1041 | 1041 | /** |
1042 | 1042 | * UPDATE wrapper, takes a condition array and a SET array |
1043 | 1043 | * |
— | — | @@ -1065,10 +1065,10 @@ |
1066 | 1066 | // if not, convert to simple array first |
1067 | 1067 | $result = $this->execute( $stmt, $values ); |
1068 | 1068 | $this->freePrepared( $stmt ); |
1069 | | - |
| 1069 | + |
1070 | 1070 | return $result; |
1071 | 1071 | } |
1072 | | - |
| 1072 | + |
1073 | 1073 | /** |
1074 | 1074 | * DELETE query wrapper |
1075 | 1075 | * |
— | — | @@ -1085,10 +1085,10 @@ |
1086 | 1086 | $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND ); |
1087 | 1087 | } |
1088 | 1088 | $result = $this->query( $sql, $fname ); |
1089 | | - |
| 1089 | + |
1090 | 1090 | return $result; |
1091 | 1091 | } |
1092 | | - |
| 1092 | + |
1093 | 1093 | /** |
1094 | 1094 | * Returns the number of rows affected by the last query or 0 |
1095 | 1095 | * @return Integer: the number of rows affected by the last query |
— | — | @@ -1102,7 +1102,7 @@ |
1103 | 1103 | return 0; |
1104 | 1104 | return db2_num_rows( $this->mLastResult ); |
1105 | 1105 | } |
1106 | | - |
| 1106 | + |
1107 | 1107 | /** |
1108 | 1108 | * Simulates REPLACE with a DELETE followed by INSERT |
1109 | 1109 | * @param $table Object |
— | — | @@ -1162,7 +1162,7 @@ |
1163 | 1163 | $this->query( $sql, $fname ); |
1164 | 1164 | } |
1165 | 1165 | } |
1166 | | - |
| 1166 | + |
1167 | 1167 | /** |
1168 | 1168 | * Returns the number of rows in the result set |
1169 | 1169 | * Has to be called right after the corresponding select query |
— | — | @@ -1180,7 +1180,7 @@ |
1181 | 1181 | return 0; |
1182 | 1182 | } |
1183 | 1183 | } |
1184 | | - |
| 1184 | + |
1185 | 1185 | /** |
1186 | 1186 | * Moves the row pointer of the result set |
1187 | 1187 | * @param $res Object: result set |
— | — | @@ -1193,11 +1193,11 @@ |
1194 | 1194 | } |
1195 | 1195 | return db2_fetch_row( $res, $row ); |
1196 | 1196 | } |
1197 | | - |
| 1197 | + |
1198 | 1198 | ### |
1199 | | - # Fix notices in Block.php |
| 1199 | + # Fix notices in Block.php |
1200 | 1200 | ### |
1201 | | - |
| 1201 | + |
1202 | 1202 | /** |
1203 | 1203 | * Frees memory associated with a statement resource |
1204 | 1204 | * @param $res Object: statement resource to free |
— | — | @@ -1211,7 +1211,7 @@ |
1212 | 1212 | throw new DBUnexpectedError( $this, "Unable to free DB2 result\n" ); |
1213 | 1213 | } |
1214 | 1214 | } |
1215 | | - |
| 1215 | + |
1216 | 1216 | /** |
1217 | 1217 | * Returns the number of columns in a resource |
1218 | 1218 | * @param $res Object: statement resource |
— | — | @@ -1223,7 +1223,7 @@ |
1224 | 1224 | } |
1225 | 1225 | return db2_num_fields( $res ); |
1226 | 1226 | } |
1227 | | - |
| 1227 | + |
1228 | 1228 | /** |
1229 | 1229 | * Returns the nth column name |
1230 | 1230 | * @param $res Object: statement resource |
— | — | @@ -1236,7 +1236,7 @@ |
1237 | 1237 | } |
1238 | 1238 | return db2_field_name( $res, $n ); |
1239 | 1239 | } |
1240 | | - |
| 1240 | + |
1241 | 1241 | /** |
1242 | 1242 | * SELECT wrapper |
1243 | 1243 | * |
— | — | @@ -1259,7 +1259,7 @@ |
1260 | 1260 | { |
1261 | 1261 | $res = parent::select( $table, $vars, $conds, $fname, $options, |
1262 | 1262 | $join_conds ); |
1263 | | - |
| 1263 | + |
1264 | 1264 | // We must adjust for offset |
1265 | 1265 | if ( isset( $options['LIMIT'] ) ) { |
1266 | 1266 | if ( isset ( $options['OFFSET'] ) ) { |
— | — | @@ -1267,13 +1267,13 @@ |
1268 | 1268 | $offset = $options['OFFSET']; |
1269 | 1269 | } |
1270 | 1270 | } |
1271 | | - |
1272 | | - |
| 1271 | + |
| 1272 | + |
1273 | 1273 | // DB2 does not have a proper num_rows() function yet, so we must emulate |
1274 | 1274 | // DB2 9.5.4 and the corresponding ibm_db2 driver will introduce |
1275 | 1275 | // a working one |
1276 | 1276 | // TODO: Yay! |
1277 | | - |
| 1277 | + |
1278 | 1278 | // we want the count |
1279 | 1279 | $vars2 = array( 'count( * ) as num_rows' ); |
1280 | 1280 | // respecting just the limit option |
— | — | @@ -1285,20 +1285,20 @@ |
1286 | 1286 | if ( isset( $options['GROUP BY'] ) ) { |
1287 | 1287 | return $res; |
1288 | 1288 | } |
1289 | | - |
| 1289 | + |
1290 | 1290 | $res2 = parent::select( $table, $vars2, $conds, $fname, $options2, |
1291 | 1291 | $join_conds ); |
1292 | 1292 | $obj = $this->fetchObject( $res2 ); |
1293 | 1293 | $this->mNumRows = $obj->num_rows; |
1294 | | - |
1295 | | - |
| 1294 | + |
| 1295 | + |
1296 | 1296 | return $res; |
1297 | 1297 | } |
1298 | | - |
| 1298 | + |
1299 | 1299 | /** |
1300 | 1300 | * Handles ordering, grouping, and having options ('GROUP BY' => colname) |
1301 | 1301 | * Has limited support for per-column options (colnum => 'DISTINCT') |
1302 | | - * |
| 1302 | + * |
1303 | 1303 | * @private |
1304 | 1304 | * |
1305 | 1305 | * @param $options Associative array of options to be turned into |
— | — | @@ -1325,16 +1325,16 @@ |
1326 | 1326 | if ( isset( $options['ORDER BY'] ) ) { |
1327 | 1327 | $preLimitTail .= " ORDER BY {$options['ORDER BY']}"; |
1328 | 1328 | } |
1329 | | - |
| 1329 | + |
1330 | 1330 | if ( isset( $noKeyOptions['DISTINCT'] ) |
1331 | 1331 | || isset( $noKeyOptions['DISTINCTROW'] ) ) |
1332 | 1332 | { |
1333 | 1333 | $startOpts .= 'DISTINCT'; |
1334 | 1334 | } |
1335 | | - |
| 1335 | + |
1336 | 1336 | return array( $startOpts, '', $preLimitTail, $postLimitTail ); |
1337 | 1337 | } |
1338 | | - |
| 1338 | + |
1339 | 1339 | /** |
1340 | 1340 | * Returns link to IBM DB2 free download |
1341 | 1341 | * @return string wikitext of a link to the server software's web site |
— | — | @@ -1342,11 +1342,11 @@ |
1343 | 1343 | public static function getSoftwareLink() { |
1344 | 1344 | return "[http://www.ibm.com/db2/express/ IBM DB2]"; |
1345 | 1345 | } |
1346 | | - |
| 1346 | + |
1347 | 1347 | /** |
1348 | 1348 | * Get search engine class. All subclasses of this |
1349 | 1349 | * need to implement this if they wish to use searching. |
1350 | | - * |
| 1350 | + * |
1351 | 1351 | * @return String |
1352 | 1352 | */ |
1353 | 1353 | public function getSearchEngine() { |
— | — | @@ -1370,7 +1370,7 @@ |
1371 | 1371 | } |
1372 | 1372 | return false; |
1373 | 1373 | } |
1374 | | - |
| 1374 | + |
1375 | 1375 | /** |
1376 | 1376 | * Ping the server and try to reconnect if it there is no connection |
1377 | 1377 | * The connection may be closed and reopened while this happens |
— | — | @@ -1382,7 +1382,7 @@ |
1383 | 1383 | $this->close(); |
1384 | 1384 | $this->mConn = $this->openUncataloged( $this->mDBName, $this->mUser, |
1385 | 1385 | $this->mPassword, $this->mServer, $this->mPort ); |
1386 | | - |
| 1386 | + |
1387 | 1387 | return false; |
1388 | 1388 | } |
1389 | 1389 | ###################################### |
— | — | @@ -1399,12 +1399,12 @@ |
1400 | 1400 | /** |
1401 | 1401 | * Not implemented |
1402 | 1402 | * @return string $sql |
1403 | | - */ |
| 1403 | + */ |
1404 | 1404 | public function limitResultForUpdate( $sql, $num ) { |
1405 | 1405 | $this->installPrint( 'Not implemented for DB2: limitResultForUpdate()' ); |
1406 | 1406 | return $sql; |
1407 | 1407 | } |
1408 | | - |
| 1408 | + |
1409 | 1409 | /** |
1410 | 1410 | * Only useful with fake prepare like in base Database class |
1411 | 1411 | * @return string |
— | — | @@ -1413,11 +1413,11 @@ |
1414 | 1414 | $this->installPrint( 'Not useful for DB2: fillPreparedArg()' ); |
1415 | 1415 | return ''; |
1416 | 1416 | } |
1417 | | - |
| 1417 | + |
1418 | 1418 | ###################################### |
1419 | 1419 | # Reflection |
1420 | 1420 | ###################################### |
1421 | | - |
| 1421 | + |
1422 | 1422 | /** |
1423 | 1423 | * Returns information about an index |
1424 | 1424 | * If errors are explicitly ignored, returns NULL on failure |
— | — | @@ -1446,7 +1446,7 @@ |
1447 | 1447 | } |
1448 | 1448 | else return false; |
1449 | 1449 | } |
1450 | | - |
| 1450 | + |
1451 | 1451 | /** |
1452 | 1452 | * Returns an information object on a table column |
1453 | 1453 | * @param $table String: table name |
— | — | @@ -1456,7 +1456,7 @@ |
1457 | 1457 | public function fieldInfo( $table, $field ) { |
1458 | 1458 | return IBM_DB2Field::fromText( $this, $table, $field ); |
1459 | 1459 | } |
1460 | | - |
| 1460 | + |
1461 | 1461 | /** |
1462 | 1462 | * db2_field_type() wrapper |
1463 | 1463 | * @param $res Object: result of executed statement |
— | — | @@ -1469,7 +1469,7 @@ |
1470 | 1470 | } |
1471 | 1471 | return db2_field_type( $res, $index ); |
1472 | 1472 | } |
1473 | | - |
| 1473 | + |
1474 | 1474 | /** |
1475 | 1475 | * Verifies that an index was created as unique |
1476 | 1476 | * @param $table String: table name |
— | — | @@ -1498,7 +1498,7 @@ |
1499 | 1499 | return false; |
1500 | 1500 | |
1501 | 1501 | } |
1502 | | - |
| 1502 | + |
1503 | 1503 | /** |
1504 | 1504 | * Returns the size of a text field, or -1 for "unlimited" |
1505 | 1505 | * @param $table String: table name |
— | — | @@ -1518,7 +1518,7 @@ |
1519 | 1519 | $size = $row->size; |
1520 | 1520 | return $size; |
1521 | 1521 | } |
1522 | | - |
| 1522 | + |
1523 | 1523 | /** |
1524 | 1524 | * DELETE where the condition is a join |
1525 | 1525 | * @param $delTable String: deleting from this table |
— | — | @@ -1532,7 +1532,7 @@ |
1533 | 1533 | $conds, $fname = "DatabaseIbm_db2::deleteJoin" ) |
1534 | 1534 | { |
1535 | 1535 | if ( !$conds ) { |
1536 | | - throw new DBUnexpectedError( $this, |
| 1536 | + throw new DBUnexpectedError( $this, |
1537 | 1537 | 'Database::deleteJoin() called with empty $conds' ); |
1538 | 1538 | } |
1539 | 1539 | |
— | — | @@ -1541,8 +1541,8 @@ |
1542 | 1542 | $sql = <<<SQL |
1543 | 1543 | DELETE FROM $delTable |
1544 | 1544 | WHERE $delVar IN ( |
1545 | | - SELECT $joinVar FROM $joinTable |
1546 | | - |
| 1545 | + SELECT $joinVar FROM $joinTable |
| 1546 | + |
1547 | 1547 | SQL; |
1548 | 1548 | if ( $conds != '*' ) { |
1549 | 1549 | $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND ); |
— | — | @@ -1560,7 +1560,7 @@ |
1561 | 1561 | public function encodeBlob( $b ) { |
1562 | 1562 | return new IBM_DB2Blob( $b ); |
1563 | 1563 | } |
1564 | | - |
| 1564 | + |
1565 | 1565 | /** |
1566 | 1566 | * Description is left as an exercise for the reader |
1567 | 1567 | * @param $b IBM_DB2Blob: data to be decoded |
— | — | @@ -1569,7 +1569,7 @@ |
1570 | 1570 | public function decodeBlob( $b ) { |
1571 | 1571 | return "$b"; |
1572 | 1572 | } |
1573 | | - |
| 1573 | + |
1574 | 1574 | /** |
1575 | 1575 | * Convert into a list of string being concatenated |
1576 | 1576 | * @param $stringList Array: strings that need to be joined together |
— | — | @@ -1581,7 +1581,7 @@ |
1582 | 1582 | // Sample query: VALUES 'foo' CONCAT 'bar' CONCAT 'baz' |
1583 | 1583 | return implode( ' || ', $stringList ); |
1584 | 1584 | } |
1585 | | - |
| 1585 | + |
1586 | 1586 | /** |
1587 | 1587 | * Generates the SQL required to convert a DB2 timestamp into a Unix epoch |
1588 | 1588 | * @param $column String: name of timestamp column |
— | — | @@ -1591,11 +1591,11 @@ |
1592 | 1592 | // TODO |
1593 | 1593 | // see SpecialAncientpages |
1594 | 1594 | } |
1595 | | - |
| 1595 | + |
1596 | 1596 | ###################################### |
1597 | 1597 | # Prepared statements |
1598 | 1598 | ###################################### |
1599 | | - |
| 1599 | + |
1600 | 1600 | /** |
1601 | 1601 | * Intended to be compatible with the PEAR::DB wrapper functions. |
1602 | 1602 | * http://pear.php.net/manual/en/package.database.db.intro-execute.php |
— | — | @@ -1669,14 +1669,14 @@ |
1670 | 1670 | public function fillPrepared( $preparedQuery, $args ) { |
1671 | 1671 | reset( $args ); |
1672 | 1672 | $this->preparedArgs =& $args; |
1673 | | - |
| 1673 | + |
1674 | 1674 | foreach ( $args as $i => $arg ) { |
1675 | 1675 | db2_bind_param( $preparedQuery, $i+1, $args[$i] ); |
1676 | 1676 | } |
1677 | | - |
| 1677 | + |
1678 | 1678 | return $preparedQuery; |
1679 | 1679 | } |
1680 | | - |
| 1680 | + |
1681 | 1681 | /** |
1682 | 1682 | * Switches module between regular and install modes |
1683 | 1683 | */ |
— | — | @@ -1685,7 +1685,7 @@ |
1686 | 1686 | $this->mMode = $mode; |
1687 | 1687 | return $old; |
1688 | 1688 | } |
1689 | | - |
| 1689 | + |
1690 | 1690 | /** |
1691 | 1691 | * Bitwise negation of a column or value in SQL |
1692 | 1692 | * Same as (~field) in C |
— | — | @@ -1725,7 +1725,7 @@ |
1726 | 1726 | if ( !is_array( $maybeArray ) ) { |
1727 | 1727 | return array( $maybeArray ); |
1728 | 1728 | } |
1729 | | - |
| 1729 | + |
1730 | 1730 | return $maybeArray; |
1731 | 1731 | } |
1732 | 1732 | } |