Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/92878


Change subject: Implement SchemaReadException
......................................................................

Implement SchemaReadException

Change-Id: Ieb5c6463c005863756ba21c2e1df9f2cf822d3f4
---
M src/MySQL/MySQLTableDefinitionReader.php
M src/SQLite/SQLiteTableDefinitionReader.php
A src/Schema/SchemaReadException.php
3 files changed, 21 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseDatabase 
refs/changes/78/92878/1

diff --git a/src/MySQL/MySQLTableDefinitionReader.php 
b/src/MySQL/MySQLTableDefinitionReader.php
index 5449326..bc6d532 100644
--- a/src/MySQL/MySQLTableDefinitionReader.php
+++ b/src/MySQL/MySQLTableDefinitionReader.php
@@ -4,7 +4,6 @@
 
 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;
@@ -33,12 +32,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 +136,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

-- 
To view, visit https://gerrit.wikimedia.org/r/92878
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb5c6463c005863756ba21c2e1df9f2cf822d3f4
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

Reply via email to