Fix total breakage of SQLite web upgrade
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseSqlite.php
index d0d62e9..f282b17 100644 (file)
@@ -120,7 +120,7 @@ class DatabaseSqlite extends Database {
        protected function doInitConnection() {
                if ( $this->dbPath !== null ) {
                        // Standalone .sqlite file mode.
-                       $this->openFile( $this->dbPath );
+                       $this->openFile( $this->dbPath, $this->connectionParams['dbname'] );
                } elseif ( $this->dbDir !== null ) {
                        // Stock wiki mode using standard file names per DB
                        if ( strlen( $this->connectionParams['dbname'] ) ) {
@@ -173,11 +173,7 @@ class DatabaseSqlite extends Database {
                        $this->conn = false;
                        throw new DBConnectionError( $this, "SQLite database not accessible" );
                }
-               $this->openFile( $fileName );
-
-               if ( $this->conn ) {
-                       $this->dbName = $dbName;
-               }
+               $this->openFile( $fileName, $dbName );
 
                return (bool)$this->conn;
        }
@@ -186,10 +182,11 @@ class DatabaseSqlite extends Database {
         * Opens a database file
         *
         * @param string $fileName
+        * @param string $dbName
         * @throws DBConnectionError
         * @return PDO|bool SQL connection or false if failed
         */
-       protected function openFile( $fileName ) {
+       protected function openFile( $fileName, $dbName ) {
                $err = false;
 
                $this->dbPath = $fileName;
@@ -211,6 +208,7 @@ class DatabaseSqlite extends Database {
 
                $this->opened = is_object( $this->conn );
                if ( $this->opened ) {
+                       $this->dbName = $dbName;
                        # Set error codes only, don't raise exceptions
                        $this->conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
                        # Enforce LIKE to be case sensitive, just like MySQL
@@ -222,10 +220,6 @@ class DatabaseSqlite extends Database {
                return false;
        }
 
-       public function selectDB( $db ) {
-               return false; // doesn't make sense
-       }
-
        /**
         * @return string SQLite DB file path
         * @since 1.25
@@ -716,13 +710,6 @@ class DatabaseSqlite extends Database {
                return $this->lastErrno() == 5; // SQLITE_BUSY
        }
 
-       /**
-        * @return bool
-        */
-       function wasErrorReissuable() {
-               return $this->lastErrno() == 17; // SQLITE_SCHEMA;
-       }
-
        /**
         * @return bool
         */
@@ -730,6 +717,18 @@ class DatabaseSqlite extends Database {
                return $this->lastErrno() == 8; // SQLITE_READONLY;
        }
 
+       public function wasConnectionError( $errno ) {
+               return $errno == 17; // SQLITE_SCHEMA;
+       }
+
+       protected function wasKnownStatementRollbackError() {
+               // ON CONFLICT ROLLBACK clauses make it so that SQLITE_CONSTRAINT error is
+               // ambiguous with regard to whether it implies a ROLLBACK or an ABORT happened.
+               // https://sqlite.org/lang_createtable.html#uniqueconst
+               // https://sqlite.org/lang_conflict.html
+               return false;
+       }
+
        /**
         * @return string Wikitext of a link to the server software's web site
         */
@@ -1076,6 +1075,16 @@ class DatabaseSqlite extends Database {
                }
        }
 
+       public function resetSequenceForTable( $table, $fname = __METHOD__ ) {
+               $encTable = $this->addIdentifierQuotes( 'sqlite_sequence' );
+               $encName = $this->addQuotes( $this->tableName( $table, 'raw' ) );
+               $this->query( "DELETE FROM $encTable WHERE name = $encName", $fname );
+       }
+
+       public function databasesAreIndependent() {
+               return true;
+       }
+
        /**
         * @return string
         */