Commit 07e73880 authored by beberlei's avatar beberlei

[2.0] DDC-92 - Completly removed DoctrineException in DBAL package

parent 639718e9
...@@ -6,7 +6,7 @@ class DBALException extends \Exception ...@@ -6,7 +6,7 @@ class DBALException extends \Exception
{ {
public static function notSupported($method) public static function notSupported($method)
{ {
return new self("Operation '$method' is not supported."); return new self("Operation '$method' is not supported by platform.");
} }
public static function invalidPlatformSpecified() public static function invalidPlatformSpecified()
...@@ -47,4 +47,27 @@ class DBALException extends \Exception ...@@ -47,4 +47,27 @@ class DBALException extends \Exception
return new self("The given 'driverClass' ".$driverClass." has to implement the ". return new self("The given 'driverClass' ".$driverClass." has to implement the ".
"\Doctrine\DBAL\Driver interface."); "\Doctrine\DBAL\Driver interface.");
} }
/**
* @param string $tableName
* @return DBALException
*/
public static function invalidTableName($tableName)
{
return new self("Invalid table name specified: ".$tableName);
}
/**
* @param string $tableName
* @return DBALException
*/
public static function noColumnsSpecifiedForTable($tableName)
{
return new self("No columns specified for table ".$tableName);
}
public static function limitOffsetInvalid()
{
return new self("Invalid Offset in Limit Query, it has to be larger or equal to 0.");
}
} }
\ No newline at end of file
...@@ -582,6 +582,10 @@ abstract class AbstractPlatform ...@@ -582,6 +582,10 @@ abstract class AbstractPlatform
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSql() has to be integer."); throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSql() has to be integer.");
} }
if (count($table->getColumns()) == 0) {
throw DBALException::noColumnsSpecifiedForTable($table->getName());
}
$tableName = $table->getName(); $tableName = $table->getName();
$options = $table->getOptions(); $options = $table->getOptions();
$options['uniqueConstraints'] = array(); $options['uniqueConstraints'] = array();
...@@ -692,7 +696,7 @@ abstract class AbstractPlatform ...@@ -692,7 +696,7 @@ abstract class AbstractPlatform
* Gets the SQL to create a sequence on this platform. * Gets the SQL to create a sequence on this platform.
* *
* @param \Doctrine\DBAL\Schema\Sequence $sequence * @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException * @throws DBALException
*/ */
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence) public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{ {
...@@ -1573,7 +1577,7 @@ abstract class AbstractPlatform ...@@ -1573,7 +1577,7 @@ abstract class AbstractPlatform
*/ */
public function getTimeTypeDeclarationSql(array $fieldDeclaration) public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{ {
throw DoctrineException::getTimeTypeDeclarationNotSupported($this); throw DBALException::notSupported(__METHOD__);
} }
/** /**
......
...@@ -21,9 +21,8 @@ ...@@ -21,9 +21,8 @@
namespace Doctrine\DBAL\Platforms; namespace Doctrine\DBAL\Platforms;
use \Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\DBALException;
use Doctrine\Common\DoctrineException;
/** /**
* The MsSqlPlatform provides the behavior, features and SQL dialect of the * The MsSqlPlatform provides the behavior, features and SQL dialect of the
...@@ -54,7 +53,7 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -54,7 +53,7 @@ class MsSqlPlatform extends AbstractPlatform
$offset = intval($offset); $offset = intval($offset);
if ($offset < 0) { if ($offset < 0) {
throw \Doctrine\Common\DoctrineException::limitOffsetInvalid($offset); throw DBALException::limitOffsetInvalid($offset);
} }
$orderby = stristr($query, 'ORDER BY'); $orderby = stristr($query, 'ORDER BY');
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace Doctrine\DBAL\Platforms; namespace Doctrine\DBAL\Platforms;
use Doctrine\Common\DoctrineException, use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Schema\TableDiff; Doctrine\DBAL\Schema\TableDiff;
/** /**
...@@ -347,12 +347,6 @@ class MySqlPlatform extends AbstractPlatform ...@@ -347,12 +347,6 @@ class MySqlPlatform extends AbstractPlatform
*/ */
protected function _getCreateTableSql($tableName, array $columns, array $options = array()) protected function _getCreateTableSql($tableName, array $columns, array $options = array())
{ {
if ( ! $tableName) {
throw DoctrineException::missingTableName();
}
if (empty($columns)) {
throw DoctrineException::missingFieldsArrayForTable($tableName);
}
$queryFields = $this->getColumnDeclarationListSql($columns); $queryFields = $this->getColumnDeclarationListSql($columns);
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) { if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
...@@ -593,44 +587,6 @@ class MySqlPlatform extends AbstractPlatform ...@@ -593,44 +587,6 @@ class MySqlPlatform extends AbstractPlatform
return $unsigned . $autoinc; return $unsigned . $autoinc;
} }
/**
* Obtain DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
*
* @return string
* @override
*/
public function getIndexFieldDeclarationListSql(array $fields)
{
$declFields = array();
foreach ($fields as $fieldName => $field) {
$fieldString = $fieldName;
if (is_array($field)) {
if (isset($field['length'])) {
$fieldString .= '(' . $field['length'] . ')';
}
if (isset($field['sorting'])) {
$sort = strtoupper($field['sorting']);
switch ($sort) {
case 'ASC':
case 'DESC':
$fieldString .= ' ' . $sort;
break;
default:
throw DoctrineException::unknownIndexSortingOption($sort);
}
}
} else {
$fieldString = $field;
}
$declFields[] = $fieldString;
}
return implode(', ', $declFields);
}
/** /**
* Return the FOREIGN KEY query section dealing with non-standard options * Return the FOREIGN KEY query section dealing with non-standard options
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ... * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
......
...@@ -111,7 +111,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -111,7 +111,7 @@ class OraclePlatform extends AbstractPlatform
* in {@see listSequences()} * in {@see listSequences()}
* *
* @param \Doctrine\DBAL\Schema\Sequence $sequence * @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException * @return string
*/ */
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence) public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{ {
......
...@@ -387,7 +387,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -387,7 +387,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* Gets the SQL to create a sequence on this platform. * Gets the SQL to create a sequence on this platform.
* *
* @param \Doctrine\DBAL\Schema\Sequence $sequence * @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException * @return string
*/ */
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence) public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{ {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace Doctrine\DBAL\Platforms; namespace Doctrine\DBAL\Platforms;
use Doctrine\Common\DoctrineException; use Doctrine\DBAL\DBALException;
/** /**
* The SqlitePlatform class describes the specifics and dialects of the SQLite * The SqlitePlatform class describes the specifics and dialects of the SQLite
...@@ -267,13 +267,6 @@ class SqlitePlatform extends AbstractPlatform ...@@ -267,13 +267,6 @@ class SqlitePlatform extends AbstractPlatform
*/ */
protected function _getCreateTableSql($name, array $columns, array $options = array()) protected function _getCreateTableSql($name, array $columns, array $options = array())
{ {
if ( ! $name) {
throw DoctrineException::invalidTableName($name);
}
if (empty($columns)) {
throw DoctrineException::noFieldsSpecifiedForTable($name);
}
$queryFields = $this->getColumnDeclarationListSql($columns); $queryFields = $this->getColumnDeclarationListSql($columns);
$autoinc = false; $autoinc = false;
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use \Doctrine\DBAL\Types; use \Doctrine\DBAL\Types;
use \Doctrine\Common\DoctrineException;
use \Doctrine\DBAL\DBALException; use \Doctrine\DBAL\DBALException;
use \Doctrine\DBAL\Platforms\AbstractPlatform; use \Doctrine\DBAL\Platforms\AbstractPlatform;
......
...@@ -23,6 +23,7 @@ namespace Doctrine\DBAL\Schema; ...@@ -23,6 +23,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Schema\Visitor\Visitor; use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\DBALException;
/** /**
* Object Representation of a table * Object Representation of a table
...@@ -101,6 +102,10 @@ class Table extends AbstractAsset ...@@ -101,6 +102,10 @@ class Table extends AbstractAsset
*/ */
public function __construct($tableName, array $columns=array(), array $indexes=array(), array $fkConstraints=array(), $idGeneratorType=self::ID_NONE, array $options=array()) public function __construct($tableName, array $columns=array(), array $indexes=array(), array $fkConstraints=array(), $idGeneratorType=self::ID_NONE, array $options=array())
{ {
if (strlen($tableName) == 0) {
throw DBALException::invalidTableName($tableName);
}
$this->_setName($tableName); $this->_setName($tableName);
$this->_idGeneratorType = $idGeneratorType; $this->_idGeneratorType = $idGeneratorType;
......
...@@ -16,6 +16,14 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -16,6 +16,14 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->_platform = $this->createPlatform(); $this->_platform = $this->createPlatform();
} }
public function testCreateWithNoColumns()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$this->setExpectedException('Doctrine\DBAL\DBALException');
$sql = $this->_platform->getCreateTableSql($table);
}
public function testGeneratesTableCreationSql() public function testGeneratesTableCreationSql()
{ {
$table = new \Doctrine\DBAL\Schema\Table('test'); $table = new \Doctrine\DBAL\Schema\Table('test');
......
...@@ -14,6 +14,12 @@ use Doctrine\DBAL\Types\Type; ...@@ -14,6 +14,12 @@ use Doctrine\DBAL\Types\Type;
class TableTest extends \PHPUnit_Framework_TestCase class TableTest extends \PHPUnit_Framework_TestCase
{ {
public function testCreateWithInvalidTableName()
{
$this->setExpectedException('Doctrine\DBAL\DBALException');
$table = new \Doctrine\DBAL\Schema\Table('');
}
public function testGetName() public function testGetName()
{ {
$table = new Table("foo", array(), array(), array()); $table = new Table("foo", array(), array(), array());
......
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