From 2da7f1fe204a2e89f103e3733ef53a61699fd75d Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Sun, 19 Sep 2010 15:19:38 +0000 Subject: [PATCH] Fixed DatabaseSqlite::tableName() to avoid prefixing system tables --- RELEASE-NOTES | 1 + includes/db/DatabaseSqlite.php | 2 ++ .../includes/db/DatabaseSqliteTest.php | 21 +++++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index eaf258dd69..178b8f80a6 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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. diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 38fb388f63..e18a8e060d 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -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 ) ); } diff --git a/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php b/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php index cbeaae4b78..e1a21f6fc4 100644 --- a/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -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 +} -- 2.20.1