From b71ac561c3019f74702080d09447bbe0531da81b Mon Sep 17 00:00:00 2001 From: zYne Date: Wed, 18 Apr 2007 11:11:07 +0000 Subject: [PATCH] enhanced error handling --- lib/Doctrine/DataDict/Firebird.php | 9 ++++++--- lib/Doctrine/DataDict/Informix.php | 5 ++++- lib/Doctrine/DataDict/Mssql.php | 6 +++++- lib/Doctrine/DataDict/Mysql.php | 6 +++--- lib/Doctrine/DataDict/Oracle.php | 5 ++++- lib/Doctrine/DataDict/Pgsql.php | 6 ++++-- lib/Doctrine/DataDict/Sqlite.php | 5 ++++- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/DataDict/Firebird.php b/lib/Doctrine/DataDict/Firebird.php index 6502cae69..9678a2d7d 100644 --- a/lib/Doctrine/DataDict/Firebird.php +++ b/lib/Doctrine/DataDict/Firebird.php @@ -57,6 +57,9 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict */ public function getNativeDeclaration($field) { + if ( ! isset($field['type'])) { + throw new Doctrine_DataDict_Exception('Missing column type.'); + } switch ($field['type']) { case 'varchar': case 'string': @@ -90,10 +93,10 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict return 'DOUBLE PRECISION'; case 'decimal': $length = !empty($field['length']) ? $field['length'] : 18; - return 'DECIMAL('.$length.','.$this->conn->options['decimal_places'].')'; - default: - throw new Doctrine_DataDict_Exception('Unknown field type '. $field['type']); + return 'DECIMAL(' . $length.',' . $this->conn->options['decimal_places'] . ')'; } + + throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.'); } /** * Maps a native array description of a field to a Doctrine datatype and length diff --git a/lib/Doctrine/DataDict/Informix.php b/lib/Doctrine/DataDict/Informix.php index b11d6cac8..d5e086132 100644 --- a/lib/Doctrine/DataDict/Informix.php +++ b/lib/Doctrine/DataDict/Informix.php @@ -56,6 +56,9 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict */ public function getNativeDeclaration($field) { + if ( ! isset($field['type'])) { + throw new Doctrine_DataDict_Exception('Missing column type.'); + } switch ($field['type']) { case 'char': case 'varchar': @@ -102,6 +105,6 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict case 'decimal': return 'DECIMAL'; } - return ''; + throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.'); } } diff --git a/lib/Doctrine/DataDict/Mssql.php b/lib/Doctrine/DataDict/Mssql.php index 57825685b..ca7e53e3a 100644 --- a/lib/Doctrine/DataDict/Mssql.php +++ b/lib/Doctrine/DataDict/Mssql.php @@ -59,6 +59,9 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict */ public function getNativeDeclaration($field) { + if ( ! isset($field['type'])) { + throw new Doctrine_DataDict_Exception('Missing column type.'); + } switch ($field['type']) { case 'array': case 'object': @@ -107,7 +110,8 @@ class Doctrine_DataDict_Mssql extends Doctrine_DataDict $length = !empty($field['length']) ? $field['length'] : 18; return 'DECIMAL('.$length.','.$this->conn->options['decimal_places'].')'; } - throw new Doctrine_DataDict_Exception('Unknown column type.'); + + throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.'); } /** * Maps a native array description of a field to a MDB2 datatype and length diff --git a/lib/Doctrine/DataDict/Mysql.php b/lib/Doctrine/DataDict/Mysql.php index 7415393a8..d8cd74160 100644 --- a/lib/Doctrine/DataDict/Mysql.php +++ b/lib/Doctrine/DataDict/Mysql.php @@ -135,7 +135,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict public function getNativeDeclaration($field) { if ( ! isset($field['type'])) { - $field['type'] = null; + throw new Doctrine_DataDict_Exception('Missing column type.'); } switch ($field['type']) { @@ -218,7 +218,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict $length = !empty($field['length']) ? $field['length'] : 18; return 'DECIMAL(' . $length . ',' . 0 . ')'; //$this->dbh->options['decimal_places'] . ')'; } - throw new Doctrine_DataDict_Exception('Unknown column type ' . $field['type'] . '.'); + throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.'); } /** * Maps a native array description of a field to a MDB2 datatype and length @@ -367,7 +367,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict $length = null; break; default: - throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType); + throw new Doctrine_DataDict_Exception('unknown database attribute type: ' . $dbType); } $length = ((int) $length == 0) ? null : (int) $length; diff --git a/lib/Doctrine/DataDict/Oracle.php b/lib/Doctrine/DataDict/Oracle.php index 5564e39d4..f97ca182f 100644 --- a/lib/Doctrine/DataDict/Oracle.php +++ b/lib/Doctrine/DataDict/Oracle.php @@ -55,6 +55,9 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict */ public function getNativeDeclaration(array $field) { + if ( ! isset($field['type'])) { + throw new Doctrine_DataDict_Exception('Missing column type.'); + } switch ($field['type']) { case 'string': case 'array': @@ -91,8 +94,8 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict case 'decimal': return 'NUMBER(*,'.$this->conn->options['decimal_places'].')'; default: - throw new Doctrine_DataDict_Exception('Unknown field type '. $field['type']); } + throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.'); } /** * Maps a native array description of a field to a doctrine datatype and length diff --git a/lib/Doctrine/DataDict/Pgsql.php b/lib/Doctrine/DataDict/Pgsql.php index be220225b..000f96fa0 100644 --- a/lib/Doctrine/DataDict/Pgsql.php +++ b/lib/Doctrine/DataDict/Pgsql.php @@ -360,6 +360,9 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict */ public function getNativeDeclaration(array $field) { + if ( ! isset($field['type'])) { + throw new Doctrine_DataDict_Exception('Missing column type.'); + } switch ($field['type']) { case 'char': case 'string': @@ -415,9 +418,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict case 'decimal': $length = !empty($field['length']) ? $field['length'] : 18; return 'NUMERIC(' . $length . ',' . $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES) . ')'; - default: - throw new Doctrine_DataDict_Exception('Unknown field type '. $field['type']); } + throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.'); } /** * Maps a native array description of a field to a portable Doctrine datatype and length diff --git a/lib/Doctrine/DataDict/Sqlite.php b/lib/Doctrine/DataDict/Sqlite.php index 19bdc36d8..f417653d1 100644 --- a/lib/Doctrine/DataDict/Sqlite.php +++ b/lib/Doctrine/DataDict/Sqlite.php @@ -57,6 +57,9 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict */ public function getNativeDeclaration(array $field) { + if ( ! isset($field['type'])) { + throw new Doctrine_DataDict_Exception('Missing column type.'); + } switch ($field['type']) { case 'text': case 'object': @@ -114,7 +117,7 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict $length = !empty($field['length']) ? $field['length'] : 18; return 'DECIMAL('.$length.','.$this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES).')'; } - throw new Doctrine_DataDict_Exception('Unknown datatype ' . $field['type']); + throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.'); } /** * Maps a native array description of a field to Doctrine datatype and length