r37062 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37061‎ | r37062 | r37063 >
Date:15:57, 4 July 2008
Author:greg
Status:old
Tags:
Comment:
Properly handle the 'IGNORE' option passed to the insert funtion:
rather than just turning off errors, do some savepoint trickery
so we end at the same state as when we started, to emulate
MySQL's INSERT...IGNORE. Bug 14708.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -747,10 +747,16 @@
748748 $keys = array_keys( $args );
749749 }
750750
751 - $ignore = in_array( 'IGNORE', $options ) ? 1 : 0;
752 - if ( $ignore )
 751+ $ignore = in_array( 'IGNORE', $options ) ? 'mw' : '';
 752+ if ( $ignore ) {
 753+ $didbegin = 0;
 754+ if (! $this->mTrxLevel) {
 755+ $this->begin();
 756+ $didbegin = 1;
 757+ }
 758+ pg_query($this->mConn, "SAVEPOINT $ignore");
753759 $olde = error_reporting( 0 );
754 -
 760+ }
755761 $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES ';
756762
757763 if ( $multi ) {
@@ -785,6 +791,17 @@
786792
787793 if ( $ignore ) {
788794 $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+ if ($didbegin) {
 803+ $this->commit();
 804+ }
 805+ ## IGNORE always returns true
789806 return true;
790807 }
791808
Index: trunk/phase3/RELEASE-NOTES
@@ -412,6 +412,7 @@
413413 generates a log entry.
414414 * (bug 14088) Excessively long block expiry times are rejected as invalid,
415415 keeps the log page from being distorted.
 416+* (bug 14708) Emulate INSERT...IGNORE with standard SQL for Postgres backend.
416417
417418 === API changes in 1.13 ===
418419

Status & tagging log