Jeroen De Dauw has submitted this change and it was merged.
Change subject: Implement SchemaReadException
......................................................................
Implement SchemaReadException
Change-Id: Ieb5c6463c005863756ba21c2e1df9f2cf822d3f4
---
M src/MySQL/MySQLTableDefinitionReader.php
M src/SQLite/SQLiteTableDefinitionReader.php
A src/Schema/SchemaReadException.php
M tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
M tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
5 files changed, 24 insertions(+), 13 deletions(-)
Approvals:
Jeroen De Dauw: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/MySQL/MySQLTableDefinitionReader.php
b/src/MySQL/MySQLTableDefinitionReader.php
index 5449326..f231dce 100644
--- a/src/MySQL/MySQLTableDefinitionReader.php
+++ b/src/MySQL/MySQLTableDefinitionReader.php
@@ -4,11 +4,11 @@
use RuntimeException;
use Wikibase\Database\QueryInterface\QueryInterface;
-use Wikibase\Database\QueryInterface\QueryInterfaceException;
use Wikibase\Database\QueryInterface\ResultIterator;
use Wikibase\Database\Schema\Definitions\FieldDefinition;
use Wikibase\Database\Schema\Definitions\IndexDefinition;
use Wikibase\Database\Schema\Definitions\TableDefinition;
+use Wikibase\Database\Schema\SchemaReadException;
use Wikibase\Database\Schema\TableDefinitionReader;
use Wikibase\Database\TableNameFormatter;
@@ -33,12 +33,12 @@
*
* @param string $tableName
*
- * @throws QueryInterfaceException
+ * @throws SchemaReadException
* @return TableDefinition
*/
public function readDefinition( $tableName ) {
if( !$this->queryInterface->tableExists( $tableName ) ) {
- throw new QueryInterfaceException( "Unknown table
{$tableName}" );
+ throw new SchemaReadException( "Unknown table
{$tableName}" );
}
$fields = $this->getFields( $tableName );
@@ -137,7 +137,6 @@
/**
* @param $tableName string
- * @throws QueryInterfaceException
* @return IndexDefinition[]
* @TODO support currently don't notice FULLTEXT or SPATIAL indexes
*/
diff --git a/src/SQLite/SQLiteTableDefinitionReader.php
b/src/SQLite/SQLiteTableDefinitionReader.php
index 604f227..b390e9f 100644
--- a/src/SQLite/SQLiteTableDefinitionReader.php
+++ b/src/SQLite/SQLiteTableDefinitionReader.php
@@ -4,11 +4,11 @@
use RuntimeException;
use Wikibase\Database\QueryInterface\QueryInterface;
-use Wikibase\Database\QueryInterface\QueryInterfaceException;
use Wikibase\Database\QueryInterface\ResultIterator;
use Wikibase\Database\Schema\Definitions\FieldDefinition;
use Wikibase\Database\Schema\Definitions\IndexDefinition;
use Wikibase\Database\Schema\Definitions\TableDefinition;
+use Wikibase\Database\Schema\SchemaReadException;
use Wikibase\Database\Schema\TableDefinitionReader;
/**
@@ -36,12 +36,12 @@
*
* @param string $tableName
*
- * @throws QueryInterfaceException
+ * @throws SchemaReadException
* @return TableDefinition
*/
public function readDefinition( $tableName ) {
if( !$this->queryInterface->tableExists( $tableName ) ){
- throw new QueryInterfaceException( "Unknown table
{$tableName}" );
+ throw new SchemaReadException( "Unknown table
{$tableName}" );
}
$fields = $this->getFields( $tableName );
@@ -54,13 +54,13 @@
/**
* Returns an array of all fields in the given table
* @param string $tableName
- * @throws QueryInterfaceException
+ * @throws SchemaReadException
* @return FieldDefinition[]
*/
private function getFields( $tableName ) {
$results = $this->doCreateQuery( $tableName );
if( iterator_count( $results ) > 1 ){
- throw new QueryInterfaceException( "More than one set
of fields returned for {$tableName}" );
+ throw new SchemaReadException( "More than one set of
fields returned for {$tableName}" );
}
$fields = array();
@@ -69,13 +69,13 @@
/** $createParts, 1 => tableName, 2 => fieldParts
(fields, keys, etc.) */
$matchedCreate = preg_match( '/CREATE TABLE ([^ ]+)
\(([^\)]+)\)/', $sql, $createParts );
if( $matchedCreate !== 1 ){
- throw new QueryInterfaceException( "Failed to
match CREATE TABLE regex with sql string: " . $sql );
+ throw new SchemaReadException( "Failed to match
CREATE TABLE regex with sql string: " . $sql );
}
foreach( explode( ',', $createParts[2] ) as $fieldSql )
{
$matchedParts = preg_match( '/([^ ]+) ([^ ]+)(
DEFAULT ([^ ]+))?( ((NOT )?NULL))?( (PRIMARY KEY AUTOINCREMENT))?/', $fieldSql,
$fieldParts );
if( $matchedParts !== 1 ){
- throw new QueryInterfaceException(
"Failed to match CREATE TABLE \$fieldSql regex with sql string: " . $fieldSql .
" - parsed from : ". $sql );
+ throw new SchemaReadException( "Failed
to match CREATE TABLE \$fieldSql regex with sql string: " . $fieldSql . " -
parsed from : ". $sql );
} else if( $fieldParts[0] !== 'PRIMARY KEY' ) {
$fields[] = $this->getField(
$fieldParts );
}
diff --git a/src/Schema/SchemaReadException.php
b/src/Schema/SchemaReadException.php
new file mode 100644
index 0000000..44a1fb1
--- /dev/null
+++ b/src/Schema/SchemaReadException.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace Wikibase\Database\Schema;
+
+/**
+ * @since 0.1
+ * @licence GNU GPL v2+
+ * @author Adam Shorland
+ */
+class SchemaReadException extends \Exception {
+
+}
\ No newline at end of file
diff --git a/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
b/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
index ce82402..f5e05e5 100644
--- a/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
+++ b/tests/phpunit/MySQL/MySQLTableDefinitionReaderTest.php
@@ -52,7 +52,7 @@
}
public function testReadNonExistentTable(){
- $this->setExpectedException(
'Wikibase\Database\QueryInterface\QueryInterfaceException' );
+ $this->setExpectedException(
'Wikibase\Database\Schema\SchemaReadException' );
$reader = $this->newInstance( array(), false );
$reader->readDefinition( 'dbNametableName' );
}
diff --git a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
index e8dca7e..73ed62f 100644
--- a/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
+++ b/tests/phpunit/SQLite/SQLiteTableDefinitionReaderTest.php
@@ -54,7 +54,7 @@
}
public function testReadNonExistentTable(){
- $this->setExpectedException(
'Wikibase\Database\QueryInterface\QueryInterfaceException' );
+ $this->setExpectedException(
'Wikibase\Database\Schema\SchemaReadException' );
$reader = $this->newInstance( array(), false );
$reader->readDefinition( 'fooBarImNotATable' );
}
--
To view, visit https://gerrit.wikimedia.org/r/92878
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ieb5c6463c005863756ba21c2e1df9f2cf822d3f4
Gerrit-PatchSet: 2
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