/** @var FSLockManager (hopefully on the same server as the DB) */
protected $lockMgr;
+ /** @var array List of shared database already attached to this connection */
+ private $alreadyAttached = [];
+
/**
* Additional params include:
* - dbDirectory : directory containing the DB and the lock file directory
parent::__construct( $p );
// Super doesn't open when $user is false, but we can work with $dbName
if ( $p['dbname'] && !$this->isOpen() ) {
- if ( $this->open( $p['host'], $p['user'], $p['password'], $p['dbname'] ) ) {
- $done = [];
- foreach ( $this->tableAliases as $params ) {
- if ( isset( $done[$params['dbname']] ) ) {
- continue;
- }
- $this->attachDatabase( $params['dbname'] );
- $done[$params['dbname']] = 1;
- }
- }
+ $this->open( $p['host'], $p['user'], $p['password'], $p['dbname'] );
}
}
return parent::isWriteQuery( $sql ) && !preg_match( '/^(ATTACH|PRAGMA)\b/i', $sql );
}
+ protected function isTransactableQuery( $sql ) {
+ return parent::isTransactableQuery( $sql ) && !in_array(
+ $this->getQueryVerb( $sql ),
+ [ 'ATTACH', 'PRAGMA' ],
+ true
+ );
+ }
+
/**
* SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result
*
return $this->query( $sql, $fName );
}
+ public function setTableAliases( array $aliases ) {
+ parent::setTableAliases( $aliases );
+ foreach ( $this->tableAliases as $params ) {
+ if ( isset( $this->alreadyAttached[$params['dbname']] ) ) {
+ continue;
+ }
+ $this->attachDatabase( $params['dbname'] );
+ $this->alreadyAttached[$params['dbname']] = true;
+ }
+ }
+
protected function requiresDatabaseUser() {
return false; // just a file
}