Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -2,16 +2,8 @@ |
3 | 3 | /** |
4 | 4 | * @ingroup Database |
5 | 5 | * @file |
6 | | - */ |
7 | | - |
8 | | -/** |
9 | 6 | * This is the Postgres database abstraction layer. |
10 | 7 | * |
11 | | - * As it includes more generic version for DB functions, |
12 | | - * than MySQL ones, some of them should be moved to parent |
13 | | - * Database class. |
14 | | - * |
15 | | - * @ingroup Database |
16 | 8 | */ |
17 | 9 | class PostgresField { |
18 | 10 | private $name, $tablename, $type, $nullable, $max_length; |
— | — | @@ -747,20 +739,26 @@ |
748 | 740 | $keys = array_keys( $args ); |
749 | 741 | } |
750 | 742 | |
| 743 | + // If IGNORE is set, we use savepoints to emulate mysql's behavior |
751 | 744 | $ignore = in_array( 'IGNORE', $options ) ? 'mw' : ''; |
| 745 | + |
| 746 | + // If we are not in a transaction, we need to be for savepoint trickery |
| 747 | + $didbegin = 0; |
752 | 748 | if ( $ignore ) { |
753 | | - $didbegin = 0; |
754 | 749 | if (! $this->mTrxLevel) { |
755 | 750 | $this->begin(); |
756 | 751 | $didbegin = 1; |
757 | 752 | } |
758 | | - pg_query($this->mConn, "SAVEPOINT $ignore"); |
759 | 753 | $olde = error_reporting( 0 ); |
| 754 | + // For future use, we may want to track the number of actual inserts |
| 755 | + // Right now, insert (all writes) simply return true/false |
| 756 | + $numrowsinserted = 0; |
760 | 757 | } |
| 758 | + |
761 | 759 | $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES '; |
762 | 760 | |
763 | 761 | if ( $multi ) { |
764 | | - if ( $wgDBversion >= 8.2 ) { |
| 762 | + if ( $wgDBversion >= 8.2 && !$ignore ) { |
765 | 763 | $first = true; |
766 | 764 | foreach ( $args as $row ) { |
767 | 765 | if ( $first ) { |
— | — | @@ -778,33 +776,63 @@ |
779 | 777 | foreach ( $args as $row ) { |
780 | 778 | $tempsql = $origsql; |
781 | 779 | $tempsql .= '(' . $this->makeList( $row ) . ')'; |
| 780 | + |
| 781 | + if ( $ignore ) { |
| 782 | + pg_query($this->mConn, "SAVEPOINT $ignore"); |
| 783 | + } |
| 784 | + |
782 | 785 | $tempres = (bool)$this->query( $tempsql, $fname, $ignore ); |
| 786 | + |
| 787 | + if ( $ignore ) { |
| 788 | + $bar = pg_last_error(); |
| 789 | + if ($bar != false) { |
| 790 | + pg_query( $this->mConn, "ROLLBACK TO $ignore" ); |
| 791 | + } |
| 792 | + else { |
| 793 | + pg_query( $this->mConn, "RELEASE $ignore" ); |
| 794 | + $numrowsinserted++; |
| 795 | + } |
| 796 | + } |
| 797 | + |
| 798 | + // If any of them fail, we fail overall for this function call |
| 799 | + // Note that this will be ignored if IGNORE is set |
783 | 800 | if (! $tempres) |
784 | 801 | $res = false; |
785 | 802 | } |
786 | 803 | } |
787 | 804 | } |
788 | 805 | else { |
| 806 | + // Not multi, just a lone insert |
| 807 | + if ( $ignore ) { |
| 808 | + pg_query($this->mConn, "SAVEPOINT $ignore"); |
| 809 | + } |
| 810 | + |
789 | 811 | $sql .= '(' . $this->makeList( $args ) . ')'; |
790 | 812 | $res = (bool)$this->query( $sql, $fname, $ignore ); |
| 813 | + |
| 814 | + if ( $ignore ) { |
| 815 | + $bar = pg_last_error(); |
| 816 | + if ($bar != false) { |
| 817 | + pg_query( $this->mConn, "ROLLBACK TO $ignore" ); |
| 818 | + } |
| 819 | + else { |
| 820 | + pg_query( $this->mConn, "RELEASE $ignore" ); |
| 821 | + $numrowsinserted++; |
| 822 | + } |
| 823 | + } |
791 | 824 | } |
792 | 825 | |
793 | 826 | if ( $ignore ) { |
794 | 827 | $olde = error_reporting( $olde ); |
795 | | - $bar = pg_last_error(); |
796 | | - if ($bar !== FALSE) { |
797 | | - pg_query( $this->mConn, "ROLLBACK TO $ignore" ); |
798 | | - } |
799 | | - else { |
800 | | - pg_query( $this->mConn, "RELEASE $ignore" ); |
801 | | - } |
802 | 828 | if ($didbegin) { |
803 | 829 | $this->commit(); |
804 | 830 | } |
805 | | - ## IGNORE always returns true |
| 831 | + |
| 832 | + // IGNORE always returns true |
806 | 833 | return true; |
807 | 834 | } |
808 | 835 | |
| 836 | + |
809 | 837 | return $res; |
810 | 838 | |
811 | 839 | } |