X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabaseSqlite.php;h=01772cf809b273706264a21b690586b0ecd81723;hp=9242414dfe0d785e6454edb934a4d34fc926d6e5;hb=faf7cc4a09848c538320bd2b9067b1a77c0a0183;hpb=598a250b71aee0ca14eb8661b139bb23cf8e5f40 diff --git a/includes/libs/rdbms/database/DatabaseSqlite.php b/includes/libs/rdbms/database/DatabaseSqlite.php index 9242414dfe..01772cf809 100644 --- a/includes/libs/rdbms/database/DatabaseSqlite.php +++ b/includes/libs/rdbms/database/DatabaseSqlite.php @@ -56,6 +56,9 @@ class DatabaseSqlite extends Database { /** @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 @@ -82,16 +85,7 @@ class DatabaseSqlite extends Database { 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'] ); } } @@ -302,6 +296,14 @@ class DatabaseSqlite extends Database { 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 * @@ -494,7 +496,7 @@ class DatabaseSqlite extends Database { /** * @return int */ - function affectedRows() { + protected function fetchAffectedRowCount() { return $this->mAffectedRows; } @@ -567,7 +569,7 @@ class DatabaseSqlite extends Database { /** * @param array $options - * @return string + * @return array */ protected function makeUpdateOptionsArray( $options ) { $options = parent::makeUpdateOptionsArray( $options ); @@ -790,7 +792,7 @@ class DatabaseSqlite extends Database { return "x'" . bin2hex( $s->fetch() ) . "'"; } elseif ( is_bool( $s ) ) { return (int)$s; - } elseif ( strpos( $s, "\0" ) !== false ) { + } elseif ( strpos( (string)$s, "\0" ) !== false ) { // SQLite doesn't support \0 in strings, so use the hex representation as a workaround. // This is a known limitation of SQLite's mprintf function which PDO // should work around, but doesn't. I have reported this to php.net as bug #63419: @@ -806,9 +808,9 @@ class DatabaseSqlite extends Database { 'For consistency all binary data should have been ' . 'first processed with self::encodeBlob()' ); - return "x'" . bin2hex( $s ) . "'"; + return "x'" . bin2hex( (string)$s ) . "'"; } else { - return $this->mConn->quote( $s ); + return $this->mConn->quote( (string)$s ); } } @@ -1033,6 +1035,17 @@ class DatabaseSqlite extends Database { 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 }