Unverified Commit 8002ccc9 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #4160 from morozov/some-missing-exceptions

Add some missing @throws annotations and fix thrown exceptions
parents d415d040 06a8fac5
...@@ -35,6 +35,10 @@ The following classes have been renamed: ...@@ -35,6 +35,10 @@ The following classes have been renamed:
3. The `PDOSqlsrv\Connection` and `PDOSqlsrv\Statement` classes have been made final and no longer extend the corresponding PDO classes. 3. The `PDOSqlsrv\Connection` and `PDOSqlsrv\Statement` classes have been made final and no longer extend the corresponding PDO classes.
4. The `SQLSrv\LastInsertId` class has been made final. 4. The `SQLSrv\LastInsertId` class has been made final.
## BC BREAK: Changes in wrapper-level exceptions
1. `DBALException::invalidTableName()` has been replaced with the `InvalidTableName` class.
## BC BREAK: Changes in driver-level exception handling ## BC BREAK: Changes in driver-level exception handling
1. The `convertException()` method has been removed from the `Driver` interface. The logic of exception conversion has been moved to the `ExceptionConverter` interface. The drivers now must implement the `getExceptionConverter()` method. 1. The `convertException()` method has been removed from the `Driver` interface. The logic of exception conversion has been moved to the `ExceptionConverter` interface. The drivers now must implement the `getExceptionConverter()` method.
......
...@@ -215,7 +215,7 @@ class Connection ...@@ -215,7 +215,7 @@ class Connection
{ {
$platform = $this->getDatabasePlatform(); $platform = $this->getDatabasePlatform();
$query = $platform->getDummySelectSQL($platform->getCurrentDatabaseExpression()); $query = $platform->getDummySelectSQL($platform->getCurrentDatabaseExpression());
$database = $this->query($query)->fetchOne(); $database = $this->fetchOne($query);
assert(is_string($database) || $database === null); assert(is_string($database) || $database === null);
...@@ -344,7 +344,7 @@ class Connection ...@@ -344,7 +344,7 @@ class Connection
* *
* @return string|null * @return string|null
* *
* @throws Exception * @throws DBALException
*/ */
private function getDatabasePlatformVersion() private function getDatabasePlatformVersion()
{ {
...@@ -401,6 +401,8 @@ class Connection ...@@ -401,6 +401,8 @@ class Connection
* Returns the database server version if the underlying driver supports it. * Returns the database server version if the underlying driver supports it.
* *
* @return string|null * @return string|null
*
* @throws DBALException
*/ */
private function getServerVersion() private function getServerVersion()
{ {
...@@ -408,7 +410,11 @@ class Connection ...@@ -408,7 +410,11 @@ class Connection
// Automatic platform version detection. // Automatic platform version detection.
if ($connection instanceof ServerInfoAwareConnection) { if ($connection instanceof ServerInfoAwareConnection) {
try {
return $connection->getServerVersion(); return $connection->getServerVersion();
} catch (DriverException $e) {
throw $this->convertException($e);
}
} }
// Unable to detect platform version. // Unable to detect platform version.
...@@ -622,6 +628,8 @@ class Connection ...@@ -622,6 +628,8 @@ class Connection
* @param int $level The level to set. * @param int $level The level to set.
* *
* @return int * @return int
*
* @throws DBALException
*/ */
public function setTransactionIsolation($level) public function setTransactionIsolation($level)
{ {
...@@ -634,6 +642,8 @@ class Connection ...@@ -634,6 +642,8 @@ class Connection
* Gets the currently active transaction isolation level. * Gets the currently active transaction isolation level.
* *
* @return int The current transaction isolation level. * @return int The current transaction isolation level.
*
* @throws DBALException
*/ */
public function getTransactionIsolation() public function getTransactionIsolation()
{ {
...@@ -1131,10 +1141,16 @@ class Connection ...@@ -1131,10 +1141,16 @@ class Connection
* @param string|null $seqName Name of the sequence object from which the ID should be returned. * @param string|null $seqName Name of the sequence object from which the ID should be returned.
* *
* @return string A string representation of the last inserted ID. * @return string A string representation of the last inserted ID.
*
* @throws DBALException
*/ */
public function lastInsertId($seqName = null) public function lastInsertId($seqName = null)
{ {
try {
return $this->getWrappedConnection()->lastInsertId($seqName); return $this->getWrappedConnection()->lastInsertId($seqName);
} catch (DriverException $e) {
throw $this->convertException($e);
}
} }
/** /**
...@@ -1178,7 +1194,7 @@ class Connection ...@@ -1178,7 +1194,7 @@ class Connection
* *
* @return void * @return void
* *
* @throws ConnectionException * @throws DBALException
*/ */
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
{ {
...@@ -1216,6 +1232,8 @@ class Connection ...@@ -1216,6 +1232,8 @@ class Connection
/** /**
* @return bool * @return bool
*
* @throws DBALException
*/ */
public function beginTransaction() public function beginTransaction()
{ {
...@@ -1252,8 +1270,7 @@ class Connection ...@@ -1252,8 +1270,7 @@ class Connection
/** /**
* @return bool * @return bool
* *
* @throws ConnectionException If the commit failed due to no active transaction or * @throws DBALException
* because the transaction was marked for rollback only.
*/ */
public function commit() public function commit()
{ {
...@@ -1305,6 +1322,8 @@ class Connection ...@@ -1305,6 +1322,8 @@ class Connection
/** /**
* Commits all current nesting transactions. * Commits all current nesting transactions.
*
* @throws DBALException
*/ */
private function commitAll(): void private function commitAll(): void
{ {
...@@ -1326,7 +1345,7 @@ class Connection ...@@ -1326,7 +1345,7 @@ class Connection
* *
* @return bool * @return bool
* *
* @throws ConnectionException If the rollback operation failed. * @throws DBALException
*/ */
public function rollBack() public function rollBack()
{ {
...@@ -1378,7 +1397,7 @@ class Connection ...@@ -1378,7 +1397,7 @@ class Connection
* *
* @return void * @return void
* *
* @throws ConnectionException * @throws DBALException
*/ */
public function createSavepoint($savepoint) public function createSavepoint($savepoint)
{ {
...@@ -1386,7 +1405,7 @@ class Connection ...@@ -1386,7 +1405,7 @@ class Connection
throw ConnectionException::savepointsNotSupported(); throw ConnectionException::savepointsNotSupported();
} }
$this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint)); $this->executeUpdate($this->platform->createSavePoint($savepoint));
} }
/** /**
...@@ -1396,7 +1415,7 @@ class Connection ...@@ -1396,7 +1415,7 @@ class Connection
* *
* @return void * @return void
* *
* @throws ConnectionException * @throws DBALException
*/ */
public function releaseSavepoint($savepoint) public function releaseSavepoint($savepoint)
{ {
...@@ -1408,7 +1427,7 @@ class Connection ...@@ -1408,7 +1427,7 @@ class Connection
return; return;
} }
$this->getWrappedConnection()->exec($this->platform->releaseSavePoint($savepoint)); $this->executeUpdate($this->platform->releaseSavePoint($savepoint));
} }
/** /**
...@@ -1418,7 +1437,7 @@ class Connection ...@@ -1418,7 +1437,7 @@ class Connection
* *
* @return void * @return void
* *
* @throws ConnectionException * @throws DBALException
*/ */
public function rollbackSavepoint($savepoint) public function rollbackSavepoint($savepoint)
{ {
...@@ -1426,13 +1445,15 @@ class Connection ...@@ -1426,13 +1445,15 @@ class Connection
throw ConnectionException::savepointsNotSupported(); throw ConnectionException::savepointsNotSupported();
} }
$this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint)); $this->executeUpdate($this->platform->rollbackSavePoint($savepoint));
} }
/** /**
* Gets the wrapped driver connection. * Gets the wrapped driver connection.
* *
* @return DriverConnection * @return DriverConnection
*
* @throws DBALException
*/ */
public function getWrappedConnection() public function getWrappedConnection()
{ {
...@@ -1504,6 +1525,8 @@ class Connection ...@@ -1504,6 +1525,8 @@ class Connection
* @param string $type The name of the DBAL mapping type. * @param string $type The name of the DBAL mapping type.
* *
* @return mixed The converted value. * @return mixed The converted value.
*
* @throws DBALException
*/ */
public function convertToDatabaseValue($value, $type) public function convertToDatabaseValue($value, $type)
{ {
...@@ -1518,6 +1541,8 @@ class Connection ...@@ -1518,6 +1541,8 @@ class Connection
* @param string $type The name of the DBAL mapping type. * @param string $type The name of the DBAL mapping type.
* *
* @return mixed The converted type. * @return mixed The converted type.
*
* @throws DBALException
*/ */
public function convertToPHPValue($value, $type) public function convertToPHPValue($value, $type)
{ {
...@@ -1531,6 +1556,8 @@ class Connection ...@@ -1531,6 +1556,8 @@ class Connection
* @param DriverStatement $stmt The statement to bind the values to. * @param DriverStatement $stmt The statement to bind the values to.
* @param mixed[] $params The map/list of named/positional parameters. * @param mixed[] $params The map/list of named/positional parameters.
* @param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types). * @param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types).
*
* @throws DBALException
*/ */
private function _bindTypedValues(DriverStatement $stmt, array $params, array $types): void private function _bindTypedValues(DriverStatement $stmt, array $params, array $types): void
{ {
...@@ -1572,6 +1599,8 @@ class Connection ...@@ -1572,6 +1599,8 @@ class Connection
* @param int|string|null $type The type to bind (PDO or DBAL). * @param int|string|null $type The type to bind (PDO or DBAL).
* *
* @return mixed[] [0] => the (escaped) value, [1] => the binding type. * @return mixed[] [0] => the (escaped) value, [1] => the binding type.
*
* @throws DBALException
*/ */
private function getBindingInfo($value, $type) private function getBindingInfo($value, $type)
{ {
......
...@@ -98,6 +98,7 @@ class PrimaryReadReplicaConnection extends Connection ...@@ -98,6 +98,7 @@ class PrimaryReadReplicaConnection extends Connection
* *
* @param mixed[] $params * @param mixed[] $params
* *
* @throws DBALException
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null) public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null)
......
...@@ -126,16 +126,6 @@ class DBALException extends Exception ...@@ -126,16 +126,6 @@ class DBALException extends Exception
return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.'); return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.');
} }
/**
* @param string $tableName
*
* @return DBALException
*/
public static function invalidTableName($tableName)
{
return new self('Invalid table name specified: ' . $tableName);
}
/** /**
* @param string $tableName * @param string $tableName
* *
......
...@@ -60,6 +60,8 @@ final class Connection implements ServerInfoAwareConnection ...@@ -60,6 +60,8 @@ final class Connection implements ServerInfoAwareConnection
} }
/** /**
* {@inheritDoc}
*
* @return Statement * @return Statement
*/ */
public function prepare(string $sql): StatementInterface public function prepare(string $sql): StatementInterface
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Event\Listeners; namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber; use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
...@@ -44,6 +45,8 @@ class OracleSessionInit implements EventSubscriber ...@@ -44,6 +45,8 @@ class OracleSessionInit implements EventSubscriber
/** /**
* @return void * @return void
*
* @throws DBALException
*/ */
public function postConnect(ConnectionEventArgs $args) public function postConnect(ConnectionEventArgs $args)
{ {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Event\Listeners; namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber; use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
...@@ -24,11 +25,12 @@ class SQLSessionInit implements EventSubscriber ...@@ -24,11 +25,12 @@ class SQLSessionInit implements EventSubscriber
/** /**
* @return void * @return void
*
* @throws DBALException
*/ */
public function postConnect(ConnectionEventArgs $args) public function postConnect(ConnectionEventArgs $args)
{ {
$conn = $args->getConnection(); $args->getConnection()->executeUpdate($this->sql);
$conn->exec($this->sql);
} }
/** /**
......
...@@ -2165,6 +2165,8 @@ abstract class AbstractPlatform ...@@ -2165,6 +2165,8 @@ abstract class AbstractPlatform
* a string that defines the complete column * a string that defines the complete column
* *
* @return string DBMS specific SQL code portion that should be used to declare the column. * @return string DBMS specific SQL code portion that should be used to declare the column.
*
* @throws DBALException
*/ */
public function getColumnDeclarationSQL($name, array $field) public function getColumnDeclarationSQL($name, array $field)
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Platforms; namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
...@@ -694,6 +695,8 @@ SQL ...@@ -694,6 +695,8 @@ SQL
/** /**
* @return string[] * @return string[]
*
* @throws DBALException
*/ */
private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $index) private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $index)
{ {
...@@ -733,6 +736,8 @@ SQL ...@@ -733,6 +736,8 @@ SQL
* @param TableDiff $diff The table diff to gather the SQL for. * @param TableDiff $diff The table diff to gather the SQL for.
* *
* @return string[] * @return string[]
*
* @throws DBALException
*/ */
private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff)
{ {
......
...@@ -963,6 +963,8 @@ class SqlitePlatform extends AbstractPlatform ...@@ -963,6 +963,8 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* @return string[]|false * @return string[]|false
*
* @throws DBALException
*/ */
private function getSimpleAlterTableSQL(TableDiff $diff) private function getSimpleAlterTableSQL(TableDiff $diff)
{ {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Query; namespace Doctrine\DBAL\Query;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\CompositeExpression;
...@@ -202,6 +203,8 @@ class QueryBuilder ...@@ -202,6 +203,8 @@ class QueryBuilder
* for insert, update and delete statements. * for insert, update and delete statements.
* *
* @return Result|int * @return Result|int
*
* @throws DBALException
*/ */
public function execute() public function execute()
{ {
...@@ -1159,6 +1162,8 @@ class QueryBuilder ...@@ -1159,6 +1162,8 @@ class QueryBuilder
/** /**
* @return string[] * @return string[]
*
* @throws QueryException
*/ */
private function getFromClauses() private function getFromClauses()
{ {
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs; use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs;
use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs; use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs;
...@@ -93,6 +92,8 @@ abstract class AbstractSchemaManager ...@@ -93,6 +92,8 @@ abstract class AbstractSchemaManager
* Lists the available databases for this connection. * Lists the available databases for this connection.
* *
* @return string[] * @return string[]
*
* @throws DBALException
*/ */
public function listDatabases() public function listDatabases()
{ {
...@@ -107,6 +108,8 @@ abstract class AbstractSchemaManager ...@@ -107,6 +108,8 @@ abstract class AbstractSchemaManager
* Returns a list of all namespaces in the current database. * Returns a list of all namespaces in the current database.
* *
* @return string[] * @return string[]
*
* @throws DBALException
*/ */
public function listNamespaceNames() public function listNamespaceNames()
{ {
...@@ -123,6 +126,8 @@ abstract class AbstractSchemaManager ...@@ -123,6 +126,8 @@ abstract class AbstractSchemaManager
* @param string|null $database * @param string|null $database
* *
* @return Sequence[] * @return Sequence[]
*
* @throws DBALException
*/ */
public function listSequences($database = null) public function listSequences($database = null)
{ {
...@@ -151,6 +156,8 @@ abstract class AbstractSchemaManager ...@@ -151,6 +156,8 @@ abstract class AbstractSchemaManager
* @param string|null $database * @param string|null $database
* *
* @return Column[] * @return Column[]
*
* @throws DBALException
*/ */
public function listTableColumns($table, $database = null) public function listTableColumns($table, $database = null)
{ {
...@@ -173,6 +180,8 @@ abstract class AbstractSchemaManager ...@@ -173,6 +180,8 @@ abstract class AbstractSchemaManager
* @param string $table The name of the table. * @param string $table The name of the table.
* *
* @return Index[] * @return Index[]
*
* @throws DBALException
*/ */
public function listTableIndexes($table) public function listTableIndexes($table)
{ {
...@@ -191,6 +200,8 @@ abstract class AbstractSchemaManager ...@@ -191,6 +200,8 @@ abstract class AbstractSchemaManager
* @param string|string[] $tableNames * @param string|string[] $tableNames
* *
* @return bool * @return bool
*
* @throws DBALException
*/ */
public function tablesExist($tableNames) public function tablesExist($tableNames)
{ {
...@@ -203,6 +214,8 @@ abstract class AbstractSchemaManager ...@@ -203,6 +214,8 @@ abstract class AbstractSchemaManager
* Returns a list of all tables in the current database. * Returns a list of all tables in the current database.
* *
* @return string[] * @return string[]
*
* @throws DBALException
*/ */
public function listTableNames() public function listTableNames()
{ {
...@@ -236,6 +249,8 @@ abstract class AbstractSchemaManager ...@@ -236,6 +249,8 @@ abstract class AbstractSchemaManager
* Lists the tables for this connection. * Lists the tables for this connection.
* *
* @return Table[] * @return Table[]
*
* @throws DBALException
*/ */
public function listTables() public function listTables()
{ {
...@@ -253,6 +268,8 @@ abstract class AbstractSchemaManager ...@@ -253,6 +268,8 @@ abstract class AbstractSchemaManager
* @param string $tableName * @param string $tableName
* *
* @return Table * @return Table
*
* @throws DBALException
*/ */
public function listTableDetails($tableName) public function listTableDetails($tableName)
{ {
...@@ -271,6 +288,8 @@ abstract class AbstractSchemaManager ...@@ -271,6 +288,8 @@ abstract class AbstractSchemaManager
* Lists the views this connection has. * Lists the views this connection has.
* *
* @return View[] * @return View[]
*
* @throws DBALException
*/ */
public function listViews() public function listViews()
{ {
...@@ -288,6 +307,8 @@ abstract class AbstractSchemaManager ...@@ -288,6 +307,8 @@ abstract class AbstractSchemaManager
* @param string|null $database * @param string|null $database
* *
* @return ForeignKeyConstraint[] * @return ForeignKeyConstraint[]
*
* @throws DBALException
*/ */
public function listTableForeignKeys($table, $database = null) public function listTableForeignKeys($table, $database = null)
{ {
...@@ -311,6 +332,8 @@ abstract class AbstractSchemaManager ...@@ -311,6 +332,8 @@ abstract class AbstractSchemaManager
* @param string $database The name of the database to drop. * @param string $database The name of the database to drop.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropDatabase($database) public function dropDatabase($database)
{ {
...@@ -323,6 +346,8 @@ abstract class AbstractSchemaManager ...@@ -323,6 +346,8 @@ abstract class AbstractSchemaManager
* @param string $tableName The name of the table to drop. * @param string $tableName The name of the table to drop.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropTable($tableName) public function dropTable($tableName)
{ {
...@@ -336,6 +361,8 @@ abstract class AbstractSchemaManager ...@@ -336,6 +361,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table The name of the table. * @param Table|string $table The name of the table.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropIndex($index, $table) public function dropIndex($index, $table)
{ {
...@@ -352,6 +379,8 @@ abstract class AbstractSchemaManager ...@@ -352,6 +379,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table The name of the table. * @param Table|string $table The name of the table.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropConstraint(Constraint $constraint, $table) public function dropConstraint(Constraint $constraint, $table)
{ {
...@@ -365,6 +394,8 @@ abstract class AbstractSchemaManager ...@@ -365,6 +394,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table The name of the table with the foreign key. * @param Table|string $table The name of the table with the foreign key.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropForeignKey($foreignKey, $table) public function dropForeignKey($foreignKey, $table)
{ {
...@@ -377,6 +408,8 @@ abstract class AbstractSchemaManager ...@@ -377,6 +408,8 @@ abstract class AbstractSchemaManager
* @param string $name The name of the sequence to drop. * @param string $name The name of the sequence to drop.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropSequence($name) public function dropSequence($name)
{ {
...@@ -389,6 +422,8 @@ abstract class AbstractSchemaManager ...@@ -389,6 +422,8 @@ abstract class AbstractSchemaManager
* @param string $name The name of the view. * @param string $name The name of the view.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropView($name) public function dropView($name)
{ {
...@@ -403,6 +438,8 @@ abstract class AbstractSchemaManager ...@@ -403,6 +438,8 @@ abstract class AbstractSchemaManager
* @param string $database The name of the database to create. * @param string $database The name of the database to create.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function createDatabase($database) public function createDatabase($database)
{ {
...@@ -413,6 +450,8 @@ abstract class AbstractSchemaManager ...@@ -413,6 +450,8 @@ abstract class AbstractSchemaManager
* Creates a new table. * Creates a new table.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function createTable(Table $table) public function createTable(Table $table)
{ {
...@@ -427,7 +466,7 @@ abstract class AbstractSchemaManager ...@@ -427,7 +466,7 @@ abstract class AbstractSchemaManager
* *
* @return void * @return void
* *
* @throws ConnectionException If something fails at database level. * @throws DBALException
*/ */
public function createSequence($sequence) public function createSequence($sequence)
{ {
...@@ -440,6 +479,8 @@ abstract class AbstractSchemaManager ...@@ -440,6 +479,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table * @param Table|string $table
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function createConstraint(Constraint $constraint, $table) public function createConstraint(Constraint $constraint, $table)
{ {
...@@ -452,6 +493,8 @@ abstract class AbstractSchemaManager ...@@ -452,6 +493,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table The name of the table on which the index is to be created. * @param Table|string $table The name of the table on which the index is to be created.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function createIndex(Index $index, $table) public function createIndex(Index $index, $table)
{ {
...@@ -465,6 +508,8 @@ abstract class AbstractSchemaManager ...@@ -465,6 +508,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table The name of the table on which the foreign key is to be created. * @param Table|string $table The name of the table on which the foreign key is to be created.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
{ {
...@@ -475,6 +520,8 @@ abstract class AbstractSchemaManager ...@@ -475,6 +520,8 @@ abstract class AbstractSchemaManager
* Creates a new view. * Creates a new view.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function createView(View $view) public function createView(View $view)
{ {
...@@ -492,6 +539,8 @@ abstract class AbstractSchemaManager ...@@ -492,6 +539,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table * @param Table|string $table
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropAndCreateConstraint(Constraint $constraint, $table) public function dropAndCreateConstraint(Constraint $constraint, $table)
{ {
...@@ -505,6 +554,8 @@ abstract class AbstractSchemaManager ...@@ -505,6 +554,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table The name of the table on which the index is to be created. * @param Table|string $table The name of the table on which the index is to be created.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropAndCreateIndex(Index $index, $table) public function dropAndCreateIndex(Index $index, $table)
{ {
...@@ -519,6 +570,8 @@ abstract class AbstractSchemaManager ...@@ -519,6 +570,8 @@ abstract class AbstractSchemaManager
* @param Table|string $table The name of the table on which the foreign key is to be created. * @param Table|string $table The name of the table on which the foreign key is to be created.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
{ {
...@@ -531,7 +584,7 @@ abstract class AbstractSchemaManager ...@@ -531,7 +584,7 @@ abstract class AbstractSchemaManager
* *
* @return void * @return void
* *
* @throws ConnectionException If something fails at database level. * @throws DBALException
*/ */
public function dropAndCreateSequence(Sequence $sequence) public function dropAndCreateSequence(Sequence $sequence)
{ {
...@@ -543,6 +596,8 @@ abstract class AbstractSchemaManager ...@@ -543,6 +596,8 @@ abstract class AbstractSchemaManager
* Drops and creates a new table. * Drops and creates a new table.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropAndCreateTable(Table $table) public function dropAndCreateTable(Table $table)
{ {
...@@ -556,6 +611,8 @@ abstract class AbstractSchemaManager ...@@ -556,6 +611,8 @@ abstract class AbstractSchemaManager
* @param string $database The name of the database to create. * @param string $database The name of the database to create.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropAndCreateDatabase($database) public function dropAndCreateDatabase($database)
{ {
...@@ -567,6 +624,8 @@ abstract class AbstractSchemaManager ...@@ -567,6 +624,8 @@ abstract class AbstractSchemaManager
* Drops and creates a new view. * Drops and creates a new view.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function dropAndCreateView(View $view) public function dropAndCreateView(View $view)
{ {
...@@ -580,6 +639,8 @@ abstract class AbstractSchemaManager ...@@ -580,6 +639,8 @@ abstract class AbstractSchemaManager
* Alters an existing tables schema. * Alters an existing tables schema.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function alterTable(TableDiff $tableDiff) public function alterTable(TableDiff $tableDiff)
{ {
...@@ -597,6 +658,8 @@ abstract class AbstractSchemaManager ...@@ -597,6 +658,8 @@ abstract class AbstractSchemaManager
* @param string $newName The new name of the table. * @param string $newName The new name of the table.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
public function renameTable($name, $newName) public function renameTable($name, $newName)
{ {
...@@ -700,6 +763,8 @@ abstract class AbstractSchemaManager ...@@ -700,6 +763,8 @@ abstract class AbstractSchemaManager
* @param mixed[][] $sequences * @param mixed[][] $sequences
* *
* @return Sequence[] * @return Sequence[]
*
* @throws DBALException
*/ */
protected function _getPortableSequencesList($sequences) protected function _getPortableSequencesList($sequences)
{ {
...@@ -734,6 +799,8 @@ abstract class AbstractSchemaManager ...@@ -734,6 +799,8 @@ abstract class AbstractSchemaManager
* @param mixed[][] $tableColumns * @param mixed[][] $tableColumns
* *
* @return Column[] * @return Column[]
*
* @throws DBALException
*/ */
protected function _getPortableTableColumnList($table, $database, $tableColumns) protected function _getPortableTableColumnList($table, $database, $tableColumns)
{ {
...@@ -773,6 +840,8 @@ abstract class AbstractSchemaManager ...@@ -773,6 +840,8 @@ abstract class AbstractSchemaManager
* @param mixed[] $tableColumn * @param mixed[] $tableColumn
* *
* @return Column * @return Column
*
* @throws DBALException
*/ */
abstract protected function _getPortableTableColumnDefinition($tableColumn); abstract protected function _getPortableTableColumnDefinition($tableColumn);
...@@ -783,6 +852,8 @@ abstract class AbstractSchemaManager ...@@ -783,6 +852,8 @@ abstract class AbstractSchemaManager
* @param string|null $tableName * @param string|null $tableName
* *
* @return Index[] * @return Index[]
*
* @throws DBALException
*/ */
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null) protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
{ {
...@@ -959,6 +1030,8 @@ abstract class AbstractSchemaManager ...@@ -959,6 +1030,8 @@ abstract class AbstractSchemaManager
* @param string[]|string $sql * @param string[]|string $sql
* *
* @return void * @return void
*
* @throws DBALException
*/ */
protected function _execSql($sql) protected function _execSql($sql)
{ {
...@@ -971,6 +1044,8 @@ abstract class AbstractSchemaManager ...@@ -971,6 +1044,8 @@ abstract class AbstractSchemaManager
* Creates a schema instance for the current database. * Creates a schema instance for the current database.
* *
* @return Schema * @return Schema
*
* @throws DBALException
*/ */
public function createSchema() public function createSchema()
{ {
...@@ -995,6 +1070,8 @@ abstract class AbstractSchemaManager ...@@ -995,6 +1070,8 @@ abstract class AbstractSchemaManager
* Creates the configuration for this schema. * Creates the configuration for this schema.
* *
* @return SchemaConfig * @return SchemaConfig
*
* @throws DBALException
*/ */
public function createSchemaConfig() public function createSchemaConfig()
{ {
...@@ -1031,6 +1108,8 @@ abstract class AbstractSchemaManager ...@@ -1031,6 +1108,8 @@ abstract class AbstractSchemaManager
* returns the name of the currently connected database. * returns the name of the currently connected database.
* *
* @return string[] * @return string[]
*
* @throws DBALException
*/ */
public function getSchemaSearchPaths() public function getSchemaSearchPaths()
{ {
......
...@@ -58,6 +58,8 @@ class Column extends AbstractAsset ...@@ -58,6 +58,8 @@ class Column extends AbstractAsset
* *
* @param string $columnName * @param string $columnName
* @param mixed[] $options * @param mixed[] $options
*
* @throws SchemaException
*/ */
public function __construct($columnName, Type $type, array $options = []) public function __construct($columnName, Type $type, array $options = [])
{ {
...@@ -70,6 +72,8 @@ class Column extends AbstractAsset ...@@ -70,6 +72,8 @@ class Column extends AbstractAsset
* @param mixed[] $options * @param mixed[] $options
* *
* @return Column * @return Column
*
* @throws SchemaException
*/ */
public function setOptions(array $options) public function setOptions(array $options)
{ {
......
...@@ -22,6 +22,8 @@ class Comparator ...@@ -22,6 +22,8 @@ class Comparator
{ {
/** /**
* @return SchemaDiff * @return SchemaDiff
*
* @throws SchemaException
*/ */
public static function compareSchemas(Schema $fromSchema, Schema $toSchema) public static function compareSchemas(Schema $fromSchema, Schema $toSchema)
{ {
...@@ -38,6 +40,8 @@ class Comparator ...@@ -38,6 +40,8 @@ class Comparator
* stored in $toSchema. * stored in $toSchema.
* *
* @return SchemaDiff * @return SchemaDiff
*
* @throws SchemaException
*/ */
public function compare(Schema $fromSchema, Schema $toSchema) public function compare(Schema $fromSchema, Schema $toSchema)
{ {
...@@ -188,6 +192,8 @@ class Comparator ...@@ -188,6 +192,8 @@ class Comparator
* If there are no differences this method returns the boolean false. * If there are no differences this method returns the boolean false.
* *
* @return TableDiff|false * @return TableDiff|false
*
* @throws SchemaException
*/ */
public function diffTable(Table $table1, Table $table2) public function diffTable(Table $table1, Table $table2)
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
...@@ -37,6 +38,8 @@ class DB2SchemaManager extends AbstractSchemaManager ...@@ -37,6 +38,8 @@ class DB2SchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @throws DBALException
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition($tableColumn)
{ {
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Schema\Exception;
use Doctrine\DBAL\Schema\SchemaException;
use function sprintf;
/**
* @psalm-immutable
*/
final class InvalidTableName extends SchemaException
{
public static function new(string $tableName): self
{
return new self(sprintf('Invalid table name specified "%s".', $tableName));
}
}
...@@ -297,6 +297,8 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -297,6 +297,8 @@ class OracleSchemaManager extends AbstractSchemaManager
* @param string $table * @param string $table
* *
* @return bool * @return bool
*
* @throws DBALException
*/ */
public function dropAutoincrement($table) public function dropAutoincrement($table)
{ {
...@@ -347,6 +349,8 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -347,6 +349,8 @@ class OracleSchemaManager extends AbstractSchemaManager
* @param string $user The name of the user to kill sessions for. * @param string $user The name of the user to kill sessions for.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
private function killUserSessions($user) private function killUserSessions($user)
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
...@@ -39,6 +40,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -39,6 +40,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
* Gets all the existing schema names. * Gets all the existing schema names.
* *
* @return string[] * @return string[]
*
* @throws DBALException
*/ */
public function getSchemaNames() public function getSchemaNames()
{ {
...@@ -46,11 +49,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -46,11 +49,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
} }
/** /**
* Returns an array of schema search paths. * {@inheritDoc}
*
* This is a PostgreSQL only function.
*
* @return string[]
*/ */
public function getSchemaSearchPaths() public function getSchemaSearchPaths()
{ {
......
...@@ -319,6 +319,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -319,6 +319,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager
* @param string $database The name of the database to close currently active connections for. * @param string $database The name of the database to close currently active connections for.
* *
* @return void * @return void
*
* @throws DBALException
*/ */
private function closeActiveDatabaseConnections($database) private function closeActiveDatabaseConnections($database)
{ {
...@@ -334,6 +336,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -334,6 +336,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* @param string $tableName * @param string $tableName
*
* @throws DBALException
*/ */
public function listTableDetails($tableName): Table public function listTableDetails($tableName): Table
{ {
......
...@@ -58,6 +58,8 @@ class Schema extends AbstractAsset ...@@ -58,6 +58,8 @@ class Schema extends AbstractAsset
* @param Table[] $tables * @param Table[] $tables
* @param Sequence[] $sequences * @param Sequence[] $sequences
* @param string[] $namespaces * @param string[] $namespaces
*
* @throws SchemaException
*/ */
public function __construct( public function __construct(
array $tables = [], array $tables = [],
...@@ -316,6 +318,8 @@ class Schema extends AbstractAsset ...@@ -316,6 +318,8 @@ class Schema extends AbstractAsset
* @param string $tableName * @param string $tableName
* *
* @return Table * @return Table
*
* @throws SchemaException
*/ */
public function createTable($tableName) public function createTable($tableName)
{ {
...@@ -336,6 +340,8 @@ class Schema extends AbstractAsset ...@@ -336,6 +340,8 @@ class Schema extends AbstractAsset
* @param string $newTableName * @param string $newTableName
* *
* @return Schema * @return Schema
*
* @throws SchemaException
*/ */
public function renameTable($oldTableName, $newTableName) public function renameTable($oldTableName, $newTableName)
{ {
...@@ -354,6 +360,8 @@ class Schema extends AbstractAsset ...@@ -354,6 +360,8 @@ class Schema extends AbstractAsset
* @param string $tableName * @param string $tableName
* *
* @return Schema * @return Schema
*
* @throws SchemaException
*/ */
public function dropTable($tableName) public function dropTable($tableName)
{ {
...@@ -372,6 +380,8 @@ class Schema extends AbstractAsset ...@@ -372,6 +380,8 @@ class Schema extends AbstractAsset
* @param int $initialValue * @param int $initialValue
* *
* @return Sequence * @return Sequence
*
* @throws SchemaException
*/ */
public function createSequence($sequenceName, $allocationSize = 1, $initialValue = 1) public function createSequence($sequenceName, $allocationSize = 1, $initialValue = 1)
{ {
...@@ -422,6 +432,8 @@ class Schema extends AbstractAsset ...@@ -422,6 +432,8 @@ class Schema extends AbstractAsset
/** /**
* @return string[] * @return string[]
*
* @throws SchemaException
*/ */
public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform)
{ {
...@@ -433,6 +445,8 @@ class Schema extends AbstractAsset ...@@ -433,6 +445,8 @@ class Schema extends AbstractAsset
/** /**
* @return string[] * @return string[]
*
* @throws SchemaException
*/ */
public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform)
{ {
......
...@@ -501,6 +501,9 @@ CREATE\sTABLE # Match "CREATE TABLE" ...@@ -501,6 +501,9 @@ CREATE\sTABLE # Match "CREATE TABLE"
return $comment === '' ? null : $comment; return $comment === '' ? null : $comment;
} }
/**
* @throws DBALException
*/
private function getCreateTableSQL(string $table): string private function getCreateTableSQL(string $table): string
{ {
$sql = $this->_conn->fetchOne( $sql = $this->_conn->fetchOne(
...@@ -528,6 +531,8 @@ SQL ...@@ -528,6 +531,8 @@ SQL
} }
/** /**
* {@inheritDoc}
*
* @param string $tableName * @param string $tableName
*/ */
public function listTableDetails($tableName): Table public function listTableDetails($tableName): Table
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Schema\Synchronizer; namespace Doctrine\DBAL\Schema\Synchronizer;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Throwable; use Throwable;
/** /**
...@@ -37,6 +38,8 @@ abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer ...@@ -37,6 +38,8 @@ abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer
* @param string[] $sql * @param string[] $sql
* *
* @return void * @return void
*
* @throws DBALException
*/ */
protected function processSql(array $sql) protected function processSql(array $sql)
{ {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Exception\InvalidTableName;
use Doctrine\DBAL\Schema\Visitor\Visitor; use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
...@@ -51,12 +52,12 @@ class Table extends AbstractAsset ...@@ -51,12 +52,12 @@ class Table extends AbstractAsset
* @param int $idGeneratorType * @param int $idGeneratorType
* @param mixed[] $options * @param mixed[] $options
* *
* @throws DBALException * @throws SchemaException
*/ */
public function __construct($tableName, array $columns = [], array $indexes = [], array $fkConstraints = [], $idGeneratorType = 0, array $options = []) public function __construct($tableName, array $columns = [], array $indexes = [], array $fkConstraints = [], $idGeneratorType = 0, array $options = [])
{ {
if (strlen($tableName) === 0) { if (strlen($tableName) === 0) {
throw DBALException::invalidTableName($tableName); throw InvalidTableName::new($tableName);
} }
$this->_setName($tableName); $this->_setName($tableName);
...@@ -103,6 +104,8 @@ class Table extends AbstractAsset ...@@ -103,6 +104,8 @@ class Table extends AbstractAsset
* @param string|false $indexName * @param string|false $indexName
* *
* @return self * @return self
*
* @throws SchemaException
*/ */
public function setPrimaryKey(array $columnNames, $indexName = false) public function setPrimaryKey(array $columnNames, $indexName = false)
{ {
...@@ -127,6 +130,8 @@ class Table extends AbstractAsset ...@@ -127,6 +130,8 @@ class Table extends AbstractAsset
* @param mixed[] $options * @param mixed[] $options
* *
* @return self * @return self
*
* @throws SchemaException
*/ */
public function addIndex(array $columnNames, $indexName = null, array $flags = [], array $options = []) public function addIndex(array $columnNames, $indexName = null, array $flags = [], array $options = [])
{ {
...@@ -145,6 +150,8 @@ class Table extends AbstractAsset ...@@ -145,6 +150,8 @@ class Table extends AbstractAsset
* Drops the primary key from this table. * Drops the primary key from this table.
* *
* @return void * @return void
*
* @throws SchemaException
*/ */
public function dropPrimaryKey() public function dropPrimaryKey()
{ {
...@@ -181,6 +188,8 @@ class Table extends AbstractAsset ...@@ -181,6 +188,8 @@ class Table extends AbstractAsset
* @param mixed[] $options * @param mixed[] $options
* *
* @return self * @return self
*
* @throws SchemaException
*/ */
public function addUniqueIndex(array $columnNames, $indexName = null, array $options = []) public function addUniqueIndex(array $columnNames, $indexName = null, array $options = [])
{ {
...@@ -292,6 +301,8 @@ class Table extends AbstractAsset ...@@ -292,6 +301,8 @@ class Table extends AbstractAsset
* @param mixed[] $options * @param mixed[] $options
* *
* @return Column * @return Column
*
* @throws SchemaException
*/ */
public function addColumn($columnName, $typeName, array $options = []) public function addColumn($columnName, $typeName, array $options = [])
{ {
...@@ -309,6 +320,8 @@ class Table extends AbstractAsset ...@@ -309,6 +320,8 @@ class Table extends AbstractAsset
* @param mixed[] $options * @param mixed[] $options
* *
* @return self * @return self
*
* @throws SchemaException
*/ */
public function changeColumn($columnName, array $options) public function changeColumn($columnName, array $options)
{ {
...@@ -345,6 +358,8 @@ class Table extends AbstractAsset ...@@ -345,6 +358,8 @@ class Table extends AbstractAsset
* @param string|null $name * @param string|null $name
* *
* @return self * @return self
*
* @throws SchemaException
*/ */
public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $name = null) public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $name = null)
{ {
...@@ -451,6 +466,8 @@ class Table extends AbstractAsset ...@@ -451,6 +466,8 @@ class Table extends AbstractAsset
/** /**
* @return void * @return void
*
* @throws SchemaException
*/ */
protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint)
{ {
...@@ -744,6 +761,8 @@ class Table extends AbstractAsset ...@@ -744,6 +761,8 @@ class Table extends AbstractAsset
/** /**
* @return void * @return void
*
* @throws SchemaException
*/ */
public function visit(Visitor $visitor) public function visit(Visitor $visitor)
{ {
......
...@@ -6,6 +6,7 @@ use Doctrine\DBAL\Schema\Column; ...@@ -6,6 +6,7 @@ use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
...@@ -16,6 +17,8 @@ interface Visitor ...@@ -16,6 +17,8 @@ interface Visitor
{ {
/** /**
* @return void * @return void
*
* @throws SchemaException
*/ */
public function acceptSchema(Schema $schema); public function acceptSchema(Schema $schema);
...@@ -31,6 +34,8 @@ interface Visitor ...@@ -31,6 +34,8 @@ interface Visitor
/** /**
* @return void * @return void
*
* @throws SchemaException
*/ */
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint); public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint);
......
...@@ -95,27 +95,34 @@ class Statement ...@@ -95,27 +95,34 @@ class Statement
* @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance. * @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance.
* *
* @return bool TRUE on success, FALSE on failure. * @return bool TRUE on success, FALSE on failure.
*
* @throws DBALException
*/ */
public function bindValue($name, $value, $type = ParameterType::STRING) public function bindValue($name, $value, $type = ParameterType::STRING)
{ {
$this->params[$name] = $value; $this->params[$name] = $value;
$this->types[$name] = $type; $this->types[$name] = $type;
$bindingType = ParameterType::STRING;
if ($type !== null) { if ($type !== null) {
if (is_string($type)) { if (is_string($type)) {
$type = Type::getType($type); $type = Type::getType($type);
} }
$bindingType = $type;
if ($type instanceof Type) { if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->platform); $value = $type->convertToDatabaseValue($value, $this->platform);
$bindingType = $type->getBindingType(); $bindingType = $type->getBindingType();
} else { }
$bindingType = $type;
} }
try {
return $this->stmt->bindValue($name, $value, $bindingType); return $this->stmt->bindValue($name, $value, $bindingType);
} catch (Exception $e) {
throw $this->conn->convertException($e);
} }
return $this->stmt->bindValue($name, $value);
} }
/** /**
...@@ -130,13 +137,19 @@ class Statement ...@@ -130,13 +137,19 @@ class Statement
* so that PHP allocates enough memory to hold the returned value. * so that PHP allocates enough memory to hold the returned value.
* *
* @return bool TRUE on success, FALSE on failure. * @return bool TRUE on success, FALSE on failure.
*
* @throws DBALException
*/ */
public function bindParam($name, &$var, $type = ParameterType::STRING, $length = null) public function bindParam($name, &$var, $type = ParameterType::STRING, $length = null)
{ {
$this->params[$name] = $var; $this->params[$name] = $var;
$this->types[$name] = $type; $this->types[$name] = $type;
try {
return $this->stmt->bindParam($name, $var, $type, $length); return $this->stmt->bindParam($name, $var, $type, $length);
} catch (Exception $e) {
throw $this->conn->convertException($e);
}
} }
/** /**
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Tools\Console\Command; namespace Doctrine\DBAL\Tools\Console\Command;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\Keywords\DB2Keywords; use Doctrine\DBAL\Platforms\Keywords\DB2Keywords;
use Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords; use Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords;
use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords;
...@@ -113,6 +114,8 @@ EOT ...@@ -113,6 +114,8 @@ EOT
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @throws DBALException
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Tools\Console\Command; namespace Doctrine\DBAL\Tools\Console\Command;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Tools\Console\ConnectionProvider; use Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\DBAL\Tools\Dumper; use Doctrine\DBAL\Tools\Dumper;
use LogicException; use LogicException;
...@@ -57,6 +58,8 @@ EOT ...@@ -57,6 +58,8 @@ EOT
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @throws DBALException
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
......
...@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Tools\Console; ...@@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Tools\Console;
use Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand; use Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand;
use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
use Exception;
use PackageVersions\Versions; use PackageVersions\Versions;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
...@@ -19,6 +20,8 @@ class ConsoleRunner ...@@ -19,6 +20,8 @@ class ConsoleRunner
* @param Command[] $commands * @param Command[] $commands
* *
* @return void * @return void
*
* @throws Exception
*/ */
public static function run(ConnectionProvider $connectionProvider, $commands = []) public static function run(ConnectionProvider $connectionProvider, $commands = [])
{ {
......
...@@ -64,6 +64,8 @@ abstract class Type ...@@ -64,6 +64,8 @@ abstract class Type
* @param AbstractPlatform $platform The currently used database platform. * @param AbstractPlatform $platform The currently used database platform.
* *
* @return mixed The database representation of the value. * @return mixed The database representation of the value.
*
* @throws ConversionException
*/ */
public function convertToDatabaseValue($value, AbstractPlatform $platform) public function convertToDatabaseValue($value, AbstractPlatform $platform)
{ {
...@@ -78,6 +80,8 @@ abstract class Type ...@@ -78,6 +80,8 @@ abstract class Type
* @param AbstractPlatform $platform The currently used database platform. * @param AbstractPlatform $platform The currently used database platform.
* *
* @return mixed The PHP representation of the value. * @return mixed The PHP representation of the value.
*
* @throws ConversionException
*/ */
public function convertToPHPValue($value, AbstractPlatform $platform) public function convertToPHPValue($value, AbstractPlatform $platform)
{ {
......
...@@ -17,7 +17,7 @@ class SQLSessionInitTest extends TestCase ...@@ -17,7 +17,7 @@ class SQLSessionInitTest extends TestCase
{ {
$connectionMock = $this->createMock(Connection::class); $connectionMock = $this->createMock(Connection::class);
$connectionMock->expects(self::once()) $connectionMock->expects(self::once())
->method('exec') ->method('executeUpdate')
->with(self::equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'")); ->with(self::equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'"));
$eventArgs = new ConnectionEventArgs($connectionMock); $eventArgs = new ConnectionEventArgs($connectionMock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment