return $this->__call( __FUNCTION__, func_get_args() );
}
+ public function databasesAreIndependent() {
+ return $this->__call( __FUNCTION__, func_get_args() );
+ }
+
public function selectDB( $db ) {
return $this->__call( __FUNCTION__, func_get_args() );
}
return $field;
}
+ public function databasesAreIndependent() {
+ return false;
+ }
+
public function selectDB( $db ) {
# Stub. Shouldn't cause serious problems if it's not overridden, but
# if your database engine supports a concept similar to MySQL's
$this->mDBname = $dbName;
$connectVars = [
- 'dbname' => $dbName,
+ // pg_connect() user $user as the default database. Since a database is *required*,
+ // at least pick a "don't care" database that is more likely to exist. This case
+ // arrises when LoadBalancer::getConnection( $i, [], '' ) is used.
+ 'dbname' => strlen( $dbName ) ? $dbName : 'postgres',
'user' => $user,
'password' => $password
];
return $this->mConn;
}
+ public function databasesAreIndependent() {
+ return true;
+ }
+
/**
* Postgres doesn't support selectDB in the same way MySQL does. So if the
* DB name doesn't match the open connection, open a new one
* @param string $db
* @return bool
+ * @throws DBUnexpectedError
*/
public function selectDB( $db ) {
if ( $this->mDBname !== $db ) {
*/
public function buildStringCast( $field );
+ /**
+ * Returns true if DBs are assumed to be on potentially different servers
+ *
+ * In systems like mysql/mariadb, different databases can easily be referenced on a single
+ * connection merely by name, even in a single query via JOIN. On the other hand, Postgres
+ * treats databases as fully separate, only allowing mechanisms like postgres_fdw to
+ * effectively "mount" foreign DBs. This is true even among DBs on the same server.
+ *
+ * @return bool
+ * @since 1.29
+ */
+ public function databasesAreIndependent();
+
/**
* Change the current database
*
* @param string $db
* @return bool Success or failure
+ * @throws DBConnectionError If databasesAreIndependent() is true and an error occurs
*/
public function selectDB( $db );
$this->watchPages( $otherUser, [ $target ] );
+ $reloadedUser = User::newFromName( $otherUser->getName() );
+ $this->assertEquals( '1234567890', $reloadedUser->getOption( 'watchlisttoken' ) );
+
$result = $this->doListWatchlistRequest( [
'wlowner' => $otherUser->getName(),
'wltoken' => '1234567890',
"Correct full table name"
);
- \MediaWiki\suppressWarnings();
- $this->assertFalse( $db->selectDB( 'garbage-db' ) );
- \MediaWiki\restoreWarnings();
-
$this->assertEquals(
$this->quoteTable( $db, 'garbage-db' ) . '.' . $this->quoteTable( $db, 'page' ),
$db->tableName( 'garbage-db.page' ),
"Correct full table name"
);
+ if ( $db->databasesAreIndependent() ) {
+ try {
+ $e = null;
+ $db->selectDB( 'garbage-db' );
+ } catch ( \Wikimedia\Rdbms\DBConnectionError $e ) {
+ // expected
+ }
+ $this->assertInstanceOf( '\Wikimedia\Rdbms\DBConnectionError', $e );
+ $this->assertFalse( $db->isOpen() );
+ } else {
+ \MediaWiki\suppressWarnings();
+ $this->assertFalse( $db->selectDB( 'garbage-db' ) );
+ \MediaWiki\restoreWarnings();
+ }
+
$factory->closeAll();
$factory->destroy();
}