jenkins-bot has submitted this change and it was merged.
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, 29 insertions(+), 7 deletions(-)
Approvals:
Jeroen De Dauw: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/MediaWiki/MWTableDefinitionReaderBuilder.php
b/src/MediaWiki/MWTableDefinitionReaderBuilder.php
index 715ebd3..37e9202 100644
--- a/src/MediaWiki/MWTableDefinitionReaderBuilder.php
+++ b/src/MediaWiki/MWTableDefinitionReaderBuilder.php
@@ -75,7 +75,8 @@
protected function newSQLiteTableDefinitionReader() {
return new SQLiteTableDefinitionReader(
$this->queryInterface,
- new SQLiteUnEscaper()
+ new SQLiteUnEscaper(),
+ new MediaWikiTableNameFormatter(
$this->connectionProvider )
);
}
diff --git a/src/SQLite/SQLiteTableDefinitionReader.php
b/src/SQLite/SQLiteTableDefinitionReader.php
index 00cfaae..d986f44 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\SchemaReadingException;
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 SchemaReadingException( "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 9979979..40c222e 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(){
@@ -158,4 +169,4 @@
return $argLists;
}
-}
\ No newline at end of file
+}
--
To view, visit https://gerrit.wikimedia.org/r/92909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia6520d217ebb6bfb2fa45e9af299c932e335d46d
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/WikibaseDatabase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits