Also clean up and align the mysql subclass versions of the method.
Enforce that raw "USE" queries are not passed in, since they would
break the tracking (even before this change).
Change-Id: I11c9145c6c0525f27a4ec8d94c500a22a712b320
}
/**
+ * Error out if the DB is not in a valid state for a query via query()
+ *
* @param string $sql
* @param string $fname
* @throws DBTransactionStateError
*/
private function assertTransactionStatus( $sql, $fname ) {
- if ( $this->getQueryVerb( $sql ) === 'ROLLBACK' ) { // transaction/savepoint
+ $verb = $this->getQueryVerb( $sql );
+ if ( $verb === 'USE' ) {
+ throw new DBUnexpectedError( $this, "Got USE query; use selectDomain() instead." );
+ }
+
+ if ( $verb === 'ROLLBACK' ) { // transaction/savepoint
return;
}
}
protected function doSelectDomain( DatabaseDomain $domain ) {
- $encDatabase = $this->addIdentifierQuotes( $domain->getDatabase() );
- $this->query( "USE $encDatabase" );
+ if ( $domain->getSchema() !== null ) {
+ throw new DBExpectedError( $this, __CLASS__ . ": domain schemas are not supported." );
+ }
+
+ $database = $domain->getDatabase();
+ if ( $database !== $this->getDBname() ) {
+ $encDatabase = $this->addIdentifierQuotes( $database );
+ $res = $this->doQuery( "USE $encDatabase" );
+ if ( !$res ) {
+ throw new DBExpectedError( $this, "Could not select database '$database'." );
+ }
+ }
// Update that domain fields on success (no exception thrown)
$this->currentDomain = $domain;
}
function doSelectDomain( DatabaseDomain $domain ) {
- $conn = $this->getBindingHandle();
-
if ( $domain->getSchema() !== null ) {
throw new DBExpectedError( $this, __CLASS__ . ": domain schemas are not supported." );
}
$database = $domain->getDatabase();
- if ( !$conn->select_db( $database ) ) {
- throw new DBExpectedError( $this, "Could not select database '$database'." );
+ if ( $database !== $this->getDBname() ) {
+ $conn = $this->getBindingHandle();
+ if ( !$conn->select_db( $database ) ) {
+ throw new DBExpectedError( $this, "Could not select database '$database'." );
+ }
}
// Update that domain fields on success (no exception thrown)