* Migrated to a unique index for IP block conflict detection, like we did for MySQL some aeons ago.
* Modified DatabasePostgres to return a correct affected row count for INSERT IGNORE. Tested for single and multi.
* Fixed an unrelated bug: duplicate index rc_timestamp in tables.sql
* Tested for install and upgrade on PG 8.3.
No changelog because I'll backport it to 1.13.
var $mInsertId = NULL;
var $mLastResult = NULL;
var $numeric_version = NULL;
+ var $mAffectedRows = NULL;
function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false,
$failFunction = false, $flags = 0 )
function doQuery( $sql ) {
if (function_exists('mb_convert_encoding')) {
- return $this->mLastResult=pg_query( $this->mConn , mb_convert_encoding($sql,'UTF-8') );
+ $sql = mb_convert_encoding($sql,'UTF-8');
}
- return $this->mLastResult=pg_query( $this->mConn , $sql);
+ $this->mLastResult = pg_query( $this->mConn, $sql);
+ $this->mAffectedRows = NULL; // use pg_affected_rows(mLastResult)
+ return $this->mLastResult;
}
function queryIgnore( $sql, $fname = '' ) {
}
function affectedRows() {
- if( !isset( $this->mLastResult ) or ! $this->mLastResult )
+ if ( !is_null( $this->mAffectedRows ) ) {
+ // Forced result for simulated queries
+ return $this->mAffectedRows;
+ }
+ if( empty( $this->mLastResult ) )
return 0;
-
return pg_affected_rows( $this->mLastResult );
}
$sql .= '(' . $this->makeList( $args ) . ')';
$res = (bool)$this->query( $sql, $fname, $ignore );
-
if ( $ignore ) {
$bar = pg_last_error();
if ($bar != false) {
}
}
}
-
if ( $ignore ) {
$olde = error_reporting( $olde );
if ($didbegin) {
$this->commit();
}
+ // Set the affected row count for the whole operation
+ $this->mAffectedRows = $numrowsinserted;
+
// IGNORE always returns true
return true;
}
--- /dev/null
+DROP INDEX IF EXISTS ipb_address;
+CREATE UNIQUE INDEX ipb_address_unique ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only);
ipb_range_end TEXT,
ipb_deleted SMALLINT NOT NULL DEFAULT 0,
ipb_block_email SMALLINT NOT NULL DEFAULT 0
-
);
-CREATE INDEX ipb_address ON ipblocks (ipb_address);
+CREATE UNIQUE INDEX ipb_address_unique ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only);
CREATE INDEX ipb_user ON ipblocks (ipb_user);
CREATE INDEX ipb_range ON ipblocks (ipb_range_start,ipb_range_end);
rc_params TEXT
);
CREATE INDEX rc_timestamp ON recentchanges (rc_timestamp);
-CREATE INDEX rc_timestamp ON recentchanges (rc_timestamp) WHERE rc_bot = '0';
+CREATE INDEX rc_timestamp_bot ON recentchanges (rc_timestamp) WHERE rc_bot = '0';
CREATE INDEX rc_namespace_title ON recentchanges (rc_namespace, rc_title);
CREATE INDEX rc_cur_id ON recentchanges (rc_cur_id);
CREATE INDEX new_name_timestamp ON recentchanges (rc_new, rc_namespace, rc_timestamp);
$wgDatabase->query("CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)");
}
else
- echo "... index \"pagelink_unique_index\" aready exists\n";
+ echo "... index \"pagelink_unique_index\" already exists\n";
if (pg_fkey_deltype("revision_rev_user_fkey") == 'r') {
echo "... constraint \"revision_rev_user_fkey\" is ON DELETE RESTRICT\n";
dbsource(archive('patch-revision_rev_user_fkey.sql'));
}
+ # Fix ipb_address index
+ if (pg_index_exists('ipblocks', 'ipb_address_unique' )) {
+ echo "... have ipb_address_unique\n";
+ } else {
+ echo "Adding ipb_address_unique index\n";
+ dbsource(archive('patch-ipb_address_unique.sql'));
+ }
+
global $wgExtNewTables, $wgExtPGNewFields, $wgExtNewIndexes;
# Add missing extension tables
foreach ( $wgExtNewTables as $nt ) {