From c3fe42d1c3c07be748a12427f22cd8ba503a1aeb Mon Sep 17 00:00:00 2001 From: saper Date: Mon, 18 Jun 2012 20:39:08 +0200 Subject: [PATCH] Fix INSERT options for PostgreSQL for INSERT+SELECT 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 | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index f0838bb690..763ca52099 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -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"; -- 2.20.1