X-Git-Url: https://git.heureux-cyclage.org/w/index.php?a=blobdiff_plain;f=includes%2Fdb%2FDatabaseSqlite.php;h=06dfd845951b8d065fca3eb4c6bd80441ee3278d;hb=a443be2747d49938dd7beb2fa08d1aefcf15ed7b;hp=ed6c8481b1ac7e57d127a8f7cfdbd551ccc5893a;hpb=be7b10166a55fb58652ae5cd5aa6e099c8761e8b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index ed6c8481b1..06dfd84595 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -52,7 +52,7 @@ class DatabaseSqlite extends DatabaseBase { $this->mName = $dbName; parent::__construct( $server, $user, $password, $dbName, $flags ); // parent doesn't open when $user is false, but we can work with $dbName - if ( $dbName ) { + if ( $dbName && !$this->isOpen() ) { global $wgSharedDB; if ( $this->open( $server, $user, $password, $dbName ) && $wgSharedDB ) { $this->attachDatabase( $wgSharedDB ); @@ -68,7 +68,7 @@ class DatabaseSqlite extends DatabaseBase { } /** - * @todo: check if it should be true like parent class + * @todo Check if it should be true like parent class * * @return bool */ @@ -90,6 +90,7 @@ class DatabaseSqlite extends DatabaseBase { function open( $server, $user, $pass, $dbName ) { global $wgSQLiteDataDir; + $this->close(); $fileName = self::generateFileName( $wgSQLiteDataDir, $dbName ); if ( !is_readable( $fileName ) ) { $this->mConn = false; @@ -655,7 +656,11 @@ class DatabaseSqlite extends DatabaseBase { if ( $this->mTrxLevel == 1 ) { $this->commit( __METHOD__ ); } - $this->mConn->beginTransaction(); + try { + $this->mConn->beginTransaction(); + } catch ( PDOException $e ) { + throw new DBUnexpectedError( $this, 'Error in BEGIN query: ' . $e->getMessage() ); + } $this->mTrxLevel = 1; } @@ -663,7 +668,11 @@ class DatabaseSqlite extends DatabaseBase { if ( $this->mTrxLevel == 0 ) { return; } - $this->mConn->commit(); + try { + $this->mConn->commit(); + } catch ( PDOException $e ) { + throw new DBUnexpectedError( $this, 'Error in COMMIT query: ' . $e->getMessage() ); + } $this->mTrxLevel = 0; } @@ -709,6 +718,8 @@ class DatabaseSqlite extends DatabaseBase { function addQuotes( $s ) { if ( $s instanceof Blob ) { return "x'" . bin2hex( $s->fetch() ) . "'"; + } elseif ( is_bool( $s ) ) { + return (int)$s; } elseif ( strpos( $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, @@ -792,6 +803,9 @@ class DatabaseSqlite extends DatabaseBase { $s = preg_replace( '/\(\d+\)/', '', $s ); // No FULLTEXT $s = preg_replace( '/\bfulltext\b/i', '', $s ); + } elseif ( preg_match( '/^\s*DROP INDEX/i', $s ) ) { + // DROP INDEX is database-wide, not table-specific, so no ON clause. + $s = preg_replace( '/\sON\s+[^\s]*/i', '', $s ); } return $s; }