From 040913369d26b292723420b761bb9fa23b7aacd7 Mon Sep 17 00:00:00 2001 From: Geoff Munn Date: Fri, 13 Feb 2009 02:37:58 +0000 Subject: [PATCH] API CHANGE: The standard ID column is now database-specific git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@71824 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Database.php | 5 +++-- core/model/MySQLDatabase.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/model/Database.php b/core/model/Database.php index a4ee06694..9bf40e304 100755 --- a/core/model/Database.php +++ b/core/model/Database.php @@ -236,8 +236,9 @@ abstract class Database extends Object { $this->checkAndRepairTable($table); } - $this->requireField($table, "ID", "int(11) not null auto_increment"); - + //DB ABSTRACTION: we need to convert this to a db-specific version: + $this->requireField($table, 'ID', DB::getConn()->IdColumn()); + // Create custom fields if($fieldSchema) { foreach($fieldSchema as $fieldName => $fieldSpec) { diff --git a/core/model/MySQLDatabase.php b/core/model/MySQLDatabase.php index 756000eb4..912c94b74 100644 --- a/core/model/MySQLDatabase.php +++ b/core/model/MySQLDatabase.php @@ -573,6 +573,16 @@ class MySQLDatabase extends Database { return 'varchar(' . $values['precision'] . ') character set utf8 collate utf8_general_ci'; } + /** + * 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 + * + * @return string + */ + function IdColumn(){ + return 'int(11) not null auto_increment'; + } + /** * Returns true if the given table is exists in the current database * NOTE: Experimental; introduced for db-abstraction and may changed before 2.4 is released.