X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabasePostgres.php;h=5bf845b1afd4190ca2274ea2e3bf51ff627dd1ef;hb=7babd362babcbf7f20adb8e12edb4f4bc1d4249f;hp=672b3458ca90ba85e51ede28db09d6856e9be123;hpb=3090dea5b555983d770dc252b02528752d6cfc7b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php index 672b3458ca..5bf845b1af 100644 --- a/includes/libs/rdbms/database/DatabasePostgres.php +++ b/includes/libs/rdbms/database/DatabasePostgres.php @@ -384,7 +384,7 @@ class DatabasePostgres extends Database { } } - public function affectedRows() { + protected function fetchAffectedRowCount() { if ( !is_null( $this->mAffectedRows ) ) { // Forced result for simulated queries return $this->mAffectedRows; @@ -532,26 +532,30 @@ __INDEXATTR__; unset( $options[$forUpdateKey] ); $options['FOR UPDATE'] = []; - // All tables not in $join_conds are good - foreach ( $table as $alias => $name ) { - if ( is_numeric( $alias ) ) { + $toCheck = $table; + reset( $toCheck ); + while ( $toCheck ) { + $alias = key( $toCheck ); + $name = $toCheck[$alias]; + unset( $toCheck[$alias] ); + + $hasAlias = !is_numeric( $alias ); + if ( !$hasAlias && is_string( $name ) ) { $alias = $name; } - if ( !isset( $join_conds[$alias] ) ) { - $options['FOR UPDATE'][] = $alias; - } - } - foreach ( $join_conds as $table_cond => $join_cond ) { - if ( 0 === preg_match( '/^(?:LEFT|RIGHT|FULL)(?: OUTER)? JOIN$/i', $join_cond[0] ) ) { - $options['FOR UPDATE'][] = $table_cond; + if ( !isset( $join_conds[$alias] ) || + !preg_match( '/^(?:LEFT|RIGHT|FULL)(?: OUTER)? JOIN$/i', $join_conds[$alias][0] ) + ) { + if ( is_array( $name ) ) { + // It's a parenthesized group, process all the tables inside the group. + $toCheck = array_merge( $toCheck, $name ); + } else { + // Quote alias names so $this->tableName() won't mangle them + $options['FOR UPDATE'][] = $hasAlias ? $this->addIdentifierQuotes( $alias ) : $alias; + } } } - - // Quote alias names so $this->tableName() won't mangle them - $options['FOR UPDATE'] = array_map( function ( $name ) use ( $table ) { - return isset( $table[$name] ) ? $this->addIdentifierQuotes( $name ) : $name; - }, $options['FOR UPDATE'] ); } if ( isset( $options['ORDER BY'] ) && $options['ORDER BY'] == 'NULL' ) { @@ -597,6 +601,7 @@ __INDEXATTR__; } // If IGNORE is set, we use savepoints to emulate mysql's behavior + // @todo If PostgreSQL 9.5+, we could use ON CONFLICT DO NOTHING instead $savepoint = $olde = null; $numrowsinserted = 0; if ( in_array( 'IGNORE', $options ) ) { @@ -710,39 +715,17 @@ __INDEXATTR__; } /* - * If IGNORE is set, we use savepoints to emulate mysql's behavior - * Ignore LOW PRIORITY option, since it is MySQL-specific + * If IGNORE is set, use the non-native version. + * @todo If PostgreSQL 9.5+, we could use ON CONFLICT DO NOTHING */ - $savepoint = $olde = null; - $numrowsinserted = 0; if ( in_array( 'IGNORE', $insertOptions ) ) { - $savepoint = new SavepointPostgres( $this, 'mw', $this->queryLogger ); - $olde = error_reporting( 0 ); - $savepoint->savepoint(); + return $this->nonNativeInsertSelect( + $destTable, $srcTable, $varMap, $conds, $fname, $insertOptions, $selectOptions, $selectJoinConds + ); } - $res = parent::nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname, + return parent::nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname, $insertOptions, $selectOptions, $selectJoinConds ); - - if ( $savepoint ) { - $bar = pg_result_error( $this->mLastResult ); - if ( $bar != false ) { - $savepoint->rollback(); - } else { - $savepoint->release(); - $numrowsinserted++; - } - error_reporting( $olde ); - $savepoint->commit(); - - // Set the affected row count for the whole operation - $this->mAffectedRows = $numrowsinserted; - - // IGNORE always returns true - return true; - } - - return $res; } public function tableName( $name, $format = 'quoted' ) { @@ -1196,7 +1179,7 @@ SQL; public function strencode( $s ) { // Should not be called by us - return pg_escape_string( $this->getBindingHandle(), $s ); + return pg_escape_string( $this->getBindingHandle(), (string)$s ); } public function addQuotes( $s ) { @@ -1217,7 +1200,7 @@ SQL; return 'DEFAULT'; } - return "'" . pg_escape_string( $conn, $s ) . "'"; + return "'" . pg_escape_string( $conn, (string)$s ) . "'"; } /**