r73327 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73326‎ | r73327 | r73328 >
Date:15:19, 19 September 2010
Author:maxsem
Status:ok
Tags:
Comment:
Fixed DatabaseSqlite::tableName() to avoid prefixing system tables
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/phpunit/includes/db/DatabaseSqliteTest.php
@@ -17,22 +17,25 @@
1818 }
1919 }
2020
 21+/**
 22+ * @group sqlite
 23+ */
2124 class DatabaseSqliteTest extends PHPUnit_Framework_TestCase {
2225 var $db;
2326
24 - function setup() {
 27+ public function setup() {
2528 if ( !Sqlite::isPresent() ) {
2629 $this->markTestSkipped( 'No SQLite support detected' );
2730 }
2831 $this->db = new MockDatabaseSqlite();
2932 }
3033
31 - function replaceVars( $sql ) {
 34+ private function replaceVars( $sql ) {
3235 // normalize spacing to hide implementation details
3336 return preg_replace( '/\s+/', ' ', $this->db->replaceVars( $sql ) );
3437 }
3538
36 - function testReplaceVars() {
 39+ public function testReplaceVars() {
3740 $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
3841
3942 $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
@@ -58,6 +61,16 @@
5962 $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
6063 );
6164 }
 65+
 66+ public function testTableName() {
 67+ // @todo Moar!
 68+ $db = new DatabaseSqliteStandalone( ':memory:' );
 69+ $this->assertEquals( 'foo', $db->tableName( 'foo' ) );
 70+ $this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
 71+ $db->tablePrefix( 'foo' );
 72+ $this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
 73+ $this->assertEquals( 'foobar', $db->tableName( 'bar' ) );
 74+ }
6275
6376 function testEntireSchema() {
6477 global $IP;
@@ -67,4 +80,4 @@
6881 $this->fail( $result );
6982 }
7083 }
71 -}
\ No newline at end of file
 84+}
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -266,6 +266,8 @@
267267 * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
268268 */
269269 function tableName( $name ) {
 270+ // table names starting with sqlite_ are reserved
 271+ if ( strpos( $name, 'sqlite_' ) === 0 ) return $name;
270272 return str_replace( '`', '', parent::tableName( $name ) );
271273 }
272274
Index: trunk/phase3/RELEASE-NOTES
@@ -329,6 +329,7 @@
330330 instead of alterning focus between the two buttons.
331331 * (bug 24987) Special:ListUsers does not take external groups into account
332332 * (bug 20633) update.php has mixed language output
 333+* SQLite system table names are now never prefixed.
333334
334335 === API changes in 1.17 ===
335336 * (bug 22738) Allow filtering by action type on query=logevent.

Status & tagging log