Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92909
Change subject: Format table name when reading sqlite definition
......................................................................
Format table name when reading sqlite definition
Change-Id: Ia6520d217ebb6bfb2fa45e9af299c932e335d46d
---
M src/MediaWiki/MWTableDefinitionReaderBuilder.php
M src/SQLite/SQLiteTableDefinitionReader.php
M tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
3 files changed, 27 insertions(+), 8 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseDatabase
refs/changes/09/92909/1
diff --git a/src/MediaWiki/MWTableDefinitionReaderBuilder.php
b/src/MediaWiki/MWTableDefinitionReaderBuilder.php
index 715ebd3..f9962b9 100644
--- a/src/MediaWiki/MWTableDefinitionReaderBuilder.php
+++ b/src/MediaWiki/MWTableDefinitionReaderBuilder.php
@@ -73,9 +73,7 @@
}
protected function newSQLiteTableDefinitionReader() {
- return new SQLiteTableDefinitionReader(
- $this->queryInterface,
- new SQLiteUnEscaper()
+ return new SQLiteTableDefinitionReader( $this->queryInterface,
new SQLiteUnEscaper(), new MediaWikiTableNameFormatter(
$this->connectionProvider )
);
}
diff --git a/src/SQLite/SQLiteTableDefinitionReader.php
b/src/SQLite/SQLiteTableDefinitionReader.php
index 6e2244d..35c226e 100644
--- a/src/SQLite/SQLiteTableDefinitionReader.php
+++ b/src/SQLite/SQLiteTableDefinitionReader.php
@@ -10,6 +10,7 @@
use Wikibase\Database\Schema\Definitions\TableDefinition;
use Wikibase\Database\Schema\SchemaReadException;
use Wikibase\Database\Schema\TableDefinitionReader;
+use Wikibase\Database\TableNameFormatter;
/**
* @since 0.1
@@ -21,14 +22,21 @@
protected $queryInterface;
protected $unEscaper;
+ protected $tableNameFormatter;
/**
* @param QueryInterface $queryInterface
* @param SQLiteUnEscaper $unEscaper
+ * @param TableNameFormatter $tableNameFormatter
*/
- public function __construct( QueryInterface $queryInterface,
SQLiteUnEscaper $unEscaper ) {
+ public function __construct(
+ QueryInterface $queryInterface,
+ SQLiteUnEscaper $unEscaper,
+ TableNameFormatter $tableNameFormatter
+ ) {
$this->queryInterface = $queryInterface;
$this->unEscaper = $unEscaper;
+ $this->tableNameFormatter = $tableNameFormatter;
}
/**
@@ -44,9 +52,11 @@
throw new SchemaReadException( "Unknown table
{$tableName}" );
}
- $fields = $this->getFields( $tableName );
- $indexes = $this->getIndexes( $tableName );
- $keys = $this->getPrimaryKeys( $tableName );
+ $formattedTableName =
$this->tableNameFormatter->formatTableName( $tableName );
+
+ $fields = $this->getFields( $formattedTableName );
+ $indexes = $this->getIndexes( $formattedTableName );
+ $keys = $this->getPrimaryKeys( $formattedTableName );
return new TableDefinition( $tableName, $fields, array_merge(
$indexes, $keys ) );
}
diff --git a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
index 73ed62f..4cac89e 100644
--- a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
+++ b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
@@ -44,13 +44,24 @@
return substr( $value, 1, -1 );
} ) );
+ $mockTableNameFormatter = $this->getMock(
'Wikibase\Database\TableNameFormatter' );
+ $mockTableNameFormatter->expects( $this->any() )
+ ->method( 'formatTableName' )
+ ->will( $this->returnCallback( function( $tableName ) {
+ return 'prefix_' . $tableName;
+ } ) );
+
foreach( $results as $key => $result ){
$mockQueryInterface->expects( $this->at( $key + 1 ) )
->method( 'select' )
->will( $this->returnValue( new ResultIterator(
$result ) ) );
}
- return new SQLiteTableDefinitionReader( $mockQueryInterface,
$mockUnEscaper );
+ return new SQLiteTableDefinitionReader(
+ $mockQueryInterface,
+ $mockUnEscaper,
+ $mockTableNameFormatter
+ );
}
public function testReadNonExistentTable(){
--
To view, visit https://gerrit.wikimedia.org/r/92909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6520d217ebb6bfb2fa45e9af299c932e335d46d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseDatabase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits