http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82860
Revision: 82860
Author: maxsem
Date: 2011-02-26 16:45:35 +0000 (Sat, 26 Feb 2011)
Log Message:
-----------
Follow-up r82856: instead of remembering magic table names, just analyse its
structure, added tests.
Modified Paths:
--------------
trunk/phase3/includes/db/DatabaseSqlite.php
trunk/phase3/tests/phpunit/includes/db/DatabaseSqliteTest.php
Modified: trunk/phase3/includes/db/DatabaseSqlite.php
===================================================================
--- trunk/phase3/includes/db/DatabaseSqlite.php 2011-02-26 16:31:03 UTC (rev
82859)
+++ trunk/phase3/includes/db/DatabaseSqlite.php 2011-02-26 16:45:35 UTC (rev
82860)
@@ -601,11 +601,12 @@
}
$sql = $obj->sql;
$sql = preg_replace( '/\b' . preg_quote( $oldName ) . '\b/',
$newName, $sql, 1 );
- if ( $temporary && strpos( $oldName, 'searchindex' ) === false
) {
- # For some reason TEMPORARY TABLE doesn't work with
searchindex
- # We need to explicitly look for searchindex rather
than VIRTUAL
- # because we don't want to clone the FTS subtables
either
- $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY
TABLE', $sql );
+ if ( $temporary ) {
+ if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/',
$sql ) ) {
+ wfDebug( "Table $oldName is virtual, can't
create a temporary duplicate.\n" );
+ } else {
+ $sql = str_replace( 'CREATE TABLE', 'CREATE
TEMPORARY TABLE', $sql );
+ }
}
return $this->query( $sql, $fname );
}
Modified: trunk/phase3/tests/phpunit/includes/db/DatabaseSqliteTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/db/DatabaseSqliteTest.php
2011-02-26 16:31:03 UTC (rev 82859)
+++ trunk/phase3/tests/phpunit/includes/db/DatabaseSqliteTest.php
2011-02-26 16:45:35 UTC (rev 82860)
@@ -75,7 +75,48 @@
$this->assertEquals( 'sqlite_master', $db->tableName(
'sqlite_master' ) );
$this->assertEquals( 'foobar', $db->tableName( 'bar' ) );
}
+
+ public function testDuplicateTableStructure() {
+ $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db->query( 'CREATE TABLE foo(foo, barfoo)' );
+ $db->duplicateTableStructure( 'foo', 'bar' );
+ $this->assertEquals( 'CREATE TABLE bar(foo, barfoo)',
+ $db->selectField( 'sqlite_master', 'sql', array( 'name'
=> 'bar' ) ),
+ 'Normal table duplication'
+ );
+
+ $db->duplicateTableStructure( 'foo', 'baz', true );
+ $this->assertEquals( 'CREATE TABLE baz(foo, barfoo)',
+ $db->selectField( 'sqlite_temp_master', 'sql', array(
'name' => 'baz' ) ),
+ 'Creation of temporary duplicate'
+ );
+ $this->assertEquals( 0,
+ $db->selectField( 'sqlite_master', 'COUNT(*)', array(
'name' => 'baz' ) ),
+ 'Create a temporary duplicate only'
+ );
+ }
+
+ public function testDuplicateTableStructureVirtual() {
+ $db = new DatabaseSqliteStandalone( ':memory:' );
+ if ( $db->getFulltextSearchModule() != 'FTS3' ) {
+ $this->markTestSkipped( 'FTS3 not supported, cannot
create virtual tables' );
+ }
+ $db->query( 'CREATE VIRTUAL TABLE foo USING FTS3(foobar)' );
+
+ $db->duplicateTableStructure( 'foo', 'bar' );
+ $this->assertEquals( 'CREATE VIRTUAL TABLE bar USING
FTS3(foobar)',
+ $db->selectField( 'sqlite_master', 'sql', array( 'name'
=> 'bar' ) ),
+ 'Duplication of virtual tables'
+ );
+
+ $db->duplicateTableStructure( 'foo', 'baz', true );
+ $this->assertEquals( 'CREATE VIRTUAL TABLE baz USING
FTS3(foobar)',
+ $db->selectField( 'sqlite_master', 'sql', array( 'name'
=> 'baz' ) ),
+ "Can't create temporary virtual tables, should fall
back to non-temporary duplication"
+ );
+ }
+
function testEntireSchema() {
global $IP;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs