r82860 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82859‎ | r82860 | r82861 >
Date:16:45, 26 February 2011
Author:maxsem
Status:resolved
Tags:
Comment:
Follow-up r82856: instead of remembering magic table names, just analyse its structure, added tests.
Modified paths:
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/db/DatabaseSqliteTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/db/DatabaseSqliteTest.php
@@ -75,7 +75,48 @@
7676 $this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
7777 $this->assertEquals( 'foobar', $db->tableName( 'bar' ) );
7878 }
 79+
 80+ public function testDuplicateTableStructure() {
 81+ $db = new DatabaseSqliteStandalone( ':memory:' );
 82+ $db->query( 'CREATE TABLE foo(foo, barfoo)' );
7983
 84+ $db->duplicateTableStructure( 'foo', 'bar' );
 85+ $this->assertEquals( 'CREATE TABLE bar(foo, barfoo)',
 86+ $db->selectField( 'sqlite_master', 'sql', array( 'name' => 'bar' ) ),
 87+ 'Normal table duplication'
 88+ );
 89+
 90+ $db->duplicateTableStructure( 'foo', 'baz', true );
 91+ $this->assertEquals( 'CREATE TABLE baz(foo, barfoo)',
 92+ $db->selectField( 'sqlite_temp_master', 'sql', array( 'name' => 'baz' ) ),
 93+ 'Creation of temporary duplicate'
 94+ );
 95+ $this->assertEquals( 0,
 96+ $db->selectField( 'sqlite_master', 'COUNT(*)', array( 'name' => 'baz' ) ),
 97+ 'Create a temporary duplicate only'
 98+ );
 99+ }
 100+
 101+ public function testDuplicateTableStructureVirtual() {
 102+ $db = new DatabaseSqliteStandalone( ':memory:' );
 103+ if ( $db->getFulltextSearchModule() != 'FTS3' ) {
 104+ $this->markTestSkipped( 'FTS3 not supported, cannot create virtual tables' );
 105+ }
 106+ $db->query( 'CREATE VIRTUAL TABLE foo USING FTS3(foobar)' );
 107+
 108+ $db->duplicateTableStructure( 'foo', 'bar' );
 109+ $this->assertEquals( 'CREATE VIRTUAL TABLE bar USING FTS3(foobar)',
 110+ $db->selectField( 'sqlite_master', 'sql', array( 'name' => 'bar' ) ),
 111+ 'Duplication of virtual tables'
 112+ );
 113+
 114+ $db->duplicateTableStructure( 'foo', 'baz', true );
 115+ $this->assertEquals( 'CREATE VIRTUAL TABLE baz USING FTS3(foobar)',
 116+ $db->selectField( 'sqlite_master', 'sql', array( 'name' => 'baz' ) ),
 117+ "Can't create temporary virtual tables, should fall back to non-temporary duplication"
 118+ );
 119+ }
 120+
80121 function testEntireSchema() {
81122 global $IP;
82123
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -601,11 +601,12 @@
602602 }
603603 $sql = $obj->sql;
604604 $sql = preg_replace( '/\b' . preg_quote( $oldName ) . '\b/', $newName, $sql, 1 );
605 - if ( $temporary && strpos( $oldName, 'searchindex' ) === false ) {
606 - # For some reason TEMPORARY TABLE doesn't work with searchindex
607 - # We need to explicitly look for searchindex rather than VIRTUAL
608 - # because we don't want to clone the FTS subtables either
609 - $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $sql );
 605+ if ( $temporary ) {
 606+ if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/', $sql ) ) {
 607+ wfDebug( "Table $oldName is virtual, can't create a temporary duplicate.\n" );
 608+ } else {
 609+ $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $sql );
 610+ }
610611 }
611612 return $this->query( $sql, $fname );
612613 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r82862Case insensitivity for r82860maxsem17:04, 26 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82856Add TEMPORARY TABLE support to Sqlitebtongminh14:30, 26 February 2011

Status & tagging log