From 57dcdaa8be6f77130251f404d8845dfb3988f074 Mon Sep 17 00:00:00 2001 From: Geoff Munn Date: Tue, 17 Feb 2009 03:54:10 +0000 Subject: [PATCH] API CHANGE: 'Year' datatype now uses abstracted array structure git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@71942 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/MySQLDatabase.php | 8 +++++++- core/model/fieldtypes/Year.php | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/model/MySQLDatabase.php b/core/model/MySQLDatabase.php index 80668a494..03cdd2012 100644 --- a/core/model/MySQLDatabase.php +++ b/core/model/MySQLDatabase.php @@ -468,7 +468,7 @@ class MySQLDatabase extends Database { //For reference, this is what typically gets passed to this function: //$parts=Array('datatype'=>'decimal', 'precision'=>"$this->wholeSize,$this->decimalSize"); //DB::requireField($this->tableName, $this->name, "decimal($this->wholeSize,$this->decimalSize)"); - + // Avoid empty strings being put in the db if($values['precision'] == '') { $precision = 1; @@ -580,6 +580,12 @@ class MySQLDatabase extends Database { return 'varchar(' . $values['precision'] . ') character set utf8 collate utf8_general_ci'; } + /* + * Return the MySQL-proprietary 'Year' datatype + */ + public function year($values){ + return 'year(4)'; + } /** * This returns the column which is the primary key for each table * In Postgres, it is a SERIAL8, which is the equivalent of an auto_increment diff --git a/core/model/fieldtypes/Year.php b/core/model/fieldtypes/Year.php index a30fa458a..8dc6a06c9 100644 --- a/core/model/fieldtypes/Year.php +++ b/core/model/fieldtypes/Year.php @@ -13,7 +13,9 @@ class Year extends DBField { function requireField() { - DB::requireField($this->tableName, $this->name, "year(4)"); + $parts=Array('datatype'=>'year', 'precision'=>4); + $values=Array('type'=>'year', 'parts'=>$parts); + DB::requireField($this->tableName, $this->name, $values); } public function scaffoldFormField($title = null, $params = null) {