1
0
mirror of synced 2024-12-12 22:36:02 +03:00

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

This commit is contained in:
beberlei 2010-02-19 22:33:54 +00:00
parent 639718e95c
commit 07e73880f5
11 changed files with 56 additions and 63 deletions

View File

@ -6,7 +6,7 @@ class DBALException extends \Exception
{
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()
@ -47,4 +47,27 @@ class DBALException extends \Exception
return new self("The given 'driverClass' ".$driverClass." has to implement the ".
"\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.");
}
}

View File

@ -582,6 +582,10 @@ abstract class AbstractPlatform
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();
$options = $table->getOptions();
$options['uniqueConstraints'] = array();
@ -692,7 +696,7 @@ abstract class AbstractPlatform
* Gets the SQL to create a sequence on this platform.
*
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException
* @throws DBALException
*/
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{
@ -1573,7 +1577,7 @@ abstract class AbstractPlatform
*/
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
{
throw DoctrineException::getTimeTypeDeclarationNotSupported($this);
throw DBALException::notSupported(__METHOD__);
}
/**

View File

@ -21,9 +21,8 @@
namespace Doctrine\DBAL\Platforms;
use \Doctrine\DBAL\Schema\TableDiff;
use Doctrine\Common\DoctrineException;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\DBALException;
/**
* The MsSqlPlatform provides the behavior, features and SQL dialect of the
@ -54,7 +53,7 @@ class MsSqlPlatform extends AbstractPlatform
$offset = intval($offset);
if ($offset < 0) {
throw \Doctrine\Common\DoctrineException::limitOffsetInvalid($offset);
throw DBALException::limitOffsetInvalid($offset);
}
$orderby = stristr($query, 'ORDER BY');

View File

@ -21,7 +21,7 @@
namespace Doctrine\DBAL\Platforms;
use Doctrine\Common\DoctrineException,
use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Schema\TableDiff;
/**
@ -347,12 +347,6 @@ class MySqlPlatform extends AbstractPlatform
*/
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);
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
@ -593,44 +587,6 @@ class MySqlPlatform extends AbstractPlatform
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
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ...

View File

@ -111,7 +111,7 @@ class OraclePlatform extends AbstractPlatform
* in {@see listSequences()}
*
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException
* @return string
*/
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{

View File

@ -387,7 +387,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* Gets the SQL to create a sequence on this platform.
*
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @throws DoctrineException
* @return string
*/
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
{

View File

@ -21,7 +21,7 @@
namespace Doctrine\DBAL\Platforms;
use Doctrine\Common\DoctrineException;
use Doctrine\DBAL\DBALException;
/**
* The SqlitePlatform class describes the specifics and dialects of the SQLite
@ -267,13 +267,6 @@ class SqlitePlatform extends AbstractPlatform
*/
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);
$autoinc = false;

View File

@ -22,7 +22,6 @@
namespace Doctrine\DBAL\Schema;
use \Doctrine\DBAL\Types;
use \Doctrine\Common\DoctrineException;
use \Doctrine\DBAL\DBALException;
use \Doctrine\DBAL\Platforms\AbstractPlatform;

View File

@ -23,6 +23,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\DBALException;
/**
* Object Representation of a table
@ -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())
{
if (strlen($tableName) == 0) {
throw DBALException::invalidTableName($tableName);
}
$this->_setName($tableName);
$this->_idGeneratorType = $idGeneratorType;

View File

@ -16,6 +16,14 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$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()
{
$table = new \Doctrine\DBAL\Schema\Table('test');

View File

@ -14,6 +14,12 @@ use Doctrine\DBAL\Types\Type;
class TableTest extends \PHPUnit_Framework_TestCase
{
public function testCreateWithInvalidTableName()
{
$this->setExpectedException('Doctrine\DBAL\DBALException');
$table = new \Doctrine\DBAL\Schema\Table('');
}
public function testGetName()
{
$table = new Table("foo", array(), array(), array());