r38310 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38309‎ | r38310 | r38311 >
Date:17:04, 31 July 2008
Author:simetrical
Status:old
Tags:
Comment:
(bug 14990) Don't hardcode MySQL backticks in table names for parser tests. Instead, switch the database prefix back and forth. This doesn't seem to either trash my wiki or change how well the parser tests run, but if you run this on Wikipedia without testing please don't blame me if it drops all tables on the master. :)

Of course, $wgDBprefix is not meant to be changed a few dozen times every time a script is run, but I don't think it will cause problems. If it does, an alternative would be supporting a $prefix parameter to Database::tableName().
Modified paths:
  • /trunk/phase3/maintenance/parserTests.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.inc
@@ -484,6 +484,7 @@
485485 throw new MWException( 'setupDatabase should be called before setupGlobals' );
486486 }
487487 $this->databaseSetupDone = true;
 488+ $this->oldTablePrefix = $wgDBprefix;
488489
489490 # CREATE TEMPORARY TABLE breaks if there is more than one server
490491 if ( wfGetLB()->getServerCount() != 1 ) {
@@ -504,19 +505,28 @@
505506 $def = '';
506507 }
507508 foreach ($tables as $tbl) {
 509+ # Clean up from previous aborted run. So that table escaping
 510+ # works correctly across DB engines, we need to change the pre-
 511+ # fix back and forth so tableName() works right.
 512+ $this->changePrefix( $this->oldTablePrefix );
508513 $oldTableName = $db->tableName( $tbl );
509 - # Clean up from previous aborted run
510 - if ( $db->tableExists( "`parsertest_$tbl`" ) ) {
511 - $db->query("DROP TABLE `parsertest_$tbl`");
 514+ $this->changePrefix( 'parsertest_' );
 515+ $newTableName = $db->tableName( $tbl );
 516+
 517+ if ( $db->tableExists( $tbl ) ) {
 518+ $db->query("DROP TABLE $newTableName");
512519 }
513520 # Create new table
514 - $db->query("CREATE $temporary TABLE `parsertest_$tbl` (LIKE $oldTableName $def)");
 521+ $db->query("CREATE $temporary TABLE $newTableName (LIKE $oldTableName $def)");
515522 }
516523 } else {
517524 # Hack for MySQL versions < 4.1, which don't support
518525 # "CREATE TABLE ... LIKE". Note that
519526 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
520527 # would not create the indexes we need....
 528+ #
 529+ # Note that we don't bother changing around the prefixes here be-
 530+ # cause we know we're using MySQL anyway.
521531 foreach ($tables as $tbl) {
522532 $oldTableName = $db->tableName( $tbl );
523533 $res = $db->query("SHOW CREATE TABLE $oldTableName");
@@ -532,9 +542,11 @@
533543 }
534544 }
535545
 546+ $this->changePrefix( 'parsertest_' );
 547+
536548 # Hack: insert a few Wikipedia in-project interwiki prefixes,
537549 # for testing inter-language links
538 - $db->insert( '`parsertest_interwiki`', array(
 550+ $db->insert( 'interwiki', array(
539551 array( 'iw_prefix' => 'Wikipedia',
540552 'iw_url' => 'http://en.wikipedia.org/wiki/$1',
541553 'iw_local' => 0 ),
@@ -556,7 +568,7 @@
557569 ) );
558570
559571 # Hack: Insert an image to work with
560 - $db->insert( '`parsertest_image`', array(
 572+ $db->insert( 'image', array(
561573 'img_name' => 'Foobar.jpg',
562574 'img_size' => 12345,
563575 'img_description' => 'Some lame file',
@@ -573,11 +585,7 @@
574586 ) );
575587
576588 # Update certain things in site_stats
577 - $db->insert( '`parsertest_site_stats`', array( 'ss_row_id' => 1, 'ss_images' => 1, 'ss_good_articles' => 1 ) );
578 -
579 - # Change the table prefix
580 - $this->oldTablePrefix = $wgDBprefix;
581 - $this->changePrefix( 'parsertest_' );
 589+ $db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 1, 'ss_good_articles' => 1 ) );
582590 }
583591
584592 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r48455(bug 14990) Parser tests works again with PostgreSQL...ialex20:21, 16 March 2009

Status & tagging log