From b117becef59fa23a20851848a00cb2ad9a2bdd31 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 21 Oct 2009 02:15:29 +0000 Subject: [PATCH] API CHANGE: Change the way that Database::requireField() gets field type information from the underlying database driver. (from r82793) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89708 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Database.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/core/model/Database.php b/core/model/Database.php index 18a7b7dce..c68e11d26 100755 --- a/core/model/Database.php +++ b/core/model/Database.php @@ -406,13 +406,13 @@ abstract class Database { //on how they are structured. This needs to be tidied up. $fieldValue = null; $newTable = false; - + Profiler::mark('requireField'); // backwards compatibility patch for pre 2.4 requireField() calls $spec_orig=$spec; + if(!is_string($spec)) { - // TODO: This is tempororary $spec['parts']['name'] = $field; $spec_orig['parts']['name'] = $field; //Convert the $spec array into a database-specific string @@ -431,13 +431,12 @@ abstract class Database { if(!$newTable && !isset($this->fieldList[$table])) { $this->fieldList[$table] = $this->fieldList($table); } - - // Get the value of this field. - if(is_array($spec)){ - $specValue=$spec['data_type']; - if(isset($spec['precision'])) - $specValue.='(' . $spec['precision'] . ')'; - } else $specValue=$spec; + + if(is_array($spec)) { + $specValue = DB::getConn()->$spec_orig['type']($spec_orig['parts']); + } else { + $specValue = $spec; + } // We need to get db-specific versions of the ID column: if($spec_orig==DB::getConn()->IdColumn() || $spec_orig==DB::getConn()->IdColumn(true)) @@ -500,7 +499,7 @@ abstract class Database { Profiler::mark('alterField'); $this->transAlterField($table, $field, $spec_orig); Profiler::unmark('alterField'); - Database::alteration_message("Field $table.$field: changed to $spec_orig (from {$fieldValue})","changed"); + Database::alteration_message("Field $table.$field: changed to $specValue (from {$fieldValue})","changed"); } Profiler::unmark('requireField'); } @@ -892,4 +891,4 @@ abstract class Query implements Iterator { abstract function seek($rowNum); } -?> \ No newline at end of file +?>