Fix INSERT options for PostgreSQL for INSERT+SELECT
authorsaper <saper@saper.info>
Mon, 18 Jun 2012 18:39:08 +0000 (20:39 +0200)
committersaper <saper@saper.info>
Mon, 18 Jun 2012 18:39:08 +0000 (20:39 +0200)
Fix handling of $insertOptions in
DatabasePostgres::insertSelect

Looks like this change:

https://gerrit.wikimedia.org/r/#/c/3962/
(or 646a9490f74f3841803299a4e4d2d5677c5f1bba)

mishandled badly INSERT IGNORE (instead of
silently broken support for it it introduced
PHP error).

Looks like we have no unit test to cover
the use of Database::insertSelect in the code.

Change-Id: I4f7d8c9bd9e413d8ffa23c1d0c0628a25c28d45c

includes/db/DatabasePostgres.php

index f0838bb..763ca52 100644 (file)
@@ -840,9 +840,22 @@ __INDEXATTR__;
        {
                $destTable = $this->tableName( $destTable );
 
-               if( is_array( $insertOptions ) ) {
-                       $insertOptions = implode( ' ', $insertOptions ); // FIXME: This is unused
+               if( !is_array( $insertOptions ) ) {
+                       $insertOptions = array( $insertOptions );
                }
+
+               /*
+                * If IGNORE is set, we use savepoints to emulate mysql's behavior
+                * Ignore LOW PRIORITY option, since it is MySQL-specific
+                */
+               $savepoint = null;
+               if ( in_array( 'IGNORE', $insertOptions ) ) {
+                       $savepoint = new SavepointPostgres( $this, 'mw' );
+                       $olde = error_reporting( 0 );
+                       $numrowsinserted = 0;
+                       $savepoint->savepoint();
+               }
+
                if( !is_array( $selectOptions ) ) {
                        $selectOptions = array( $selectOptions );
                }
@@ -853,15 +866,6 @@ __INDEXATTR__;
                        $srcTable = $this->tableName( $srcTable );
                }
 
-               // If IGNORE is set, we use savepoints to emulate mysql's behavior
-               $savepoint = null;
-               if ( in_array( 'IGNORE', $options ) ) {
-                       $savepoint = new SavepointPostgres( $this, 'mw' );
-                       $olde = error_reporting( 0 );
-                       $numrowsinserted = 0;
-                       $savepoint->savepoint();
-               }
-
                $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
                                " SELECT $startOpts " . implode( ',', $varMap ) .
                                " FROM $srcTable $useIndex";