Fixed DatabaseSqlite::tableName() to avoid prefixing system tables
authorMax Semenik <maxsem@users.mediawiki.org>
Sun, 19 Sep 2010 15:19:38 +0000 (15:19 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Sun, 19 Sep 2010 15:19:38 +0000 (15:19 +0000)
RELEASE-NOTES
includes/db/DatabaseSqlite.php
maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php

index eaf258d..178b8f8 100644 (file)
@@ -329,6 +329,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   instead of alterning focus between the two buttons.
 * (bug 24987) Special:ListUsers does not take external groups into account
 * (bug 20633) update.php has mixed language output
+* SQLite system table names are now never prefixed.
 
 === API changes in 1.17 ===
 * (bug 22738) Allow filtering by action type on query=logevent.
index 38fb388..e18a8e0 100644 (file)
@@ -266,6 +266,8 @@ class DatabaseSqlite extends DatabaseBase {
         * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
         */
        function tableName( $name ) {
+               // table names starting with sqlite_ are reserved
+               if ( strpos( $name, 'sqlite_' ) === 0 ) return $name;
                return str_replace( '`', '', parent::tableName( $name ) );
        }
 
index cbeaae4..e1a21f6 100644 (file)
@@ -17,22 +17,25 @@ class MockDatabaseSqlite extends DatabaseSqliteStandalone {
        }
 }
 
+/**
+ * @group sqlite
+ */
 class DatabaseSqliteTest extends PHPUnit_Framework_TestCase {
        var $db;
 
-       function setup() {
+       public function setup() {
                if ( !Sqlite::isPresent() ) {
                        $this->markTestSkipped( 'No SQLite support detected' );
                }
                $this->db = new MockDatabaseSqlite();
        }
 
-       function replaceVars( $sql ) {
+       private function replaceVars( $sql ) {
                // normalize spacing to hide implementation details
                return preg_replace( '/\s+/', ' ', $this->db->replaceVars( $sql ) );
        }
 
-       function testReplaceVars() {
+       public function testReplaceVars() {
                $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
 
                $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
@@ -58,6 +61,16 @@ class DatabaseSqliteTest extends PHPUnit_Framework_TestCase {
                        $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
                        );
        }
+       
+       public function testTableName() {
+               // @todo Moar!
+               $db = new DatabaseSqliteStandalone( ':memory:' );
+               $this->assertEquals( 'foo', $db->tableName( 'foo' ) );
+               $this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
+               $db->tablePrefix( 'foo' );
+               $this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
+               $this->assertEquals( 'foobar', $db->tableName( 'bar' ) );
+       }
 
        function testEntireSchema() {
                global $IP;
@@ -67,4 +80,4 @@ class DatabaseSqliteTest extends PHPUnit_Framework_TestCase {
                        $this->fail( $result );
                }
        }
-}
\ No newline at end of file
+}