Merge "mw.loader: Fixes for <script> and <link> loading."
[lhc/web/wiklou.git] / includes / db / DatabaseSqlite.php
index 952b497..d30d984 100644 (file)
@@ -79,11 +79,12 @@ class DatabaseSqlite extends DatabaseBase {
        /** Open an SQLite database and return a resource handle to it
         *  NOTE: only $dbName is used, the other parameters are irrelevant for SQLite databases
         *
-        * @param $server
-        * @param $user
-        * @param $pass
-        * @param $dbName
+        * @param string $server
+        * @param string $user
+        * @param string $pass
+        * @param string $dbName
         *
+        * @throws DBConnectionError
         * @return PDO
         */
        function open( $server, $user, $pass, $dbName ) {
@@ -103,6 +104,7 @@ class DatabaseSqlite extends DatabaseBase {
         *
         * @param $fileName string
         *
+        * @throws DBConnectionError
         * @return PDO|bool SQL connection or false if failed
         */
        function openFile( $fileName ) {
@@ -622,7 +624,7 @@ class DatabaseSqlite extends DatabaseBase {
         * @return string User-friendly database information
         */
        public function getServerInfo() {
-               return wfMsg( self::getFulltextSearchModule() ? 'sqlite-has-fts' : 'sqlite-no-fts', $this->getServerVersion() );
+               return wfMessage( self::getFulltextSearchModule() ? 'sqlite-has-fts' : 'sqlite-no-fts', $this->getServerVersion() )->text();
        }
 
        /**
@@ -645,7 +647,7 @@ class DatabaseSqlite extends DatabaseBase {
                return false;
        }
 
-       function begin( $fname = '' ) {
+       protected function doBegin( $fname = '' ) {
                if ( $this->mTrxLevel == 1 ) {
                        $this->commit( __METHOD__ );
                }
@@ -653,7 +655,7 @@ class DatabaseSqlite extends DatabaseBase {
                $this->mTrxLevel = 1;
        }
 
-       function commit( $fname = '' ) {
+       protected function doCommit( $fname = '' ) {
                if ( $this->mTrxLevel == 0 ) {
                        return;
                }
@@ -661,7 +663,7 @@ class DatabaseSqlite extends DatabaseBase {
                $this->mTrxLevel = 0;
        }
 
-       function rollback( $fname = '' ) {
+       protected function doRollback( $fname = '' ) {
                if ( $this->mTrxLevel == 0 ) {
                        return;
                }
@@ -703,6 +705,14 @@ class DatabaseSqlite extends DatabaseBase {
        function addQuotes( $s ) {
                if ( $s instanceof Blob ) {
                        return "x'" . bin2hex( $s->fetch() ) . "'";
+               } else if ( 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,
+                       // but doesn't. I have reported this to php.net as bug #63419:
+                       // https://bugs.php.net/bug.php?id=63419
+                       // There was already a similar report for SQLite3::escapeString, bug #62361:
+                       // https://bugs.php.net/bug.php?id=62361
+                       return "x'" . bin2hex( $s ) . "'";
                } else {
                        return $this->mConn->quote( $s );
                }