From f0629baad714de705b5fa9a38a21607a33657862 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Fri, 11 Jul 2014 13:23:54 +1200 Subject: [PATCH 1/2] Removing reference to postgres, it doesn't belong in the mssql module. --- code/MSSQLDatabase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/MSSQLDatabase.php b/code/MSSQLDatabase.php index 6163987..98dce55 100644 --- a/code/MSSQLDatabase.php +++ b/code/MSSQLDatabase.php @@ -918,7 +918,7 @@ class MSSQLDatabase extends SS_Database { * @param string $tableName * @param string $indexName * @param string $prefix The optional prefix for the index. Defaults to "ix" for indexes. - * @return string The postgres name of the index + * @return string The name of the index */ function buildMSSQLIndexName($tableName, $indexName, $prefix = 'ix') { From aa3b934712fc172c8c0fbaf97a6b5809e23f2eba Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Fri, 11 Jul 2014 13:24:15 +1200 Subject: [PATCH 2/2] Fixing use of "bigint" and "decimal" for pure integer types. See https://github.com/silverstripe/silverstripe-mssql/issues/14 for more info. "bigint" doesn't work for PHP 32-bit, as the integer could get too big for PHP to be able to interpret the value as an integer type. In that case it would try to approximate it as a float, but that could lead to a bad assumption for identity columns. For compatibility, stick with standard "int" type which has a maximum value of 2147483647. Note that MySQLAdapter already has this maximum, so changing it to this keeps this database adapter consistent with MySQL. --- code/MSSQLDatabase.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/code/MSSQLDatabase.php b/code/MSSQLDatabase.php index 98dce55..9d20387 100644 --- a/code/MSSQLDatabase.php +++ b/code/MSSQLDatabase.php @@ -713,12 +713,13 @@ class MSSQLDatabase extends SS_Database { // Update the data_type field to be a complete column definition string for use by // SS_Database::requireField() switch($field['data_type']){ + case 'int': case 'bigint': case 'numeric': case 'float': case 'bit': - if($field['data_type'] != 'bigint' && $sizeSuffix = $field['numeric_precision']) { - $field['data_type'] .= "($sizeSuffix)"; + if($field['data_type'] != 'bigint' && $field['data_type'] != 'int' && $sizeSuffix = $field['numeric_precision']) { + $field['data_type'] .= "($sizeSuffix)"; } if($field['is_nullable'] == 'YES') { @@ -1156,8 +1157,7 @@ class MSSQLDatabase extends SS_Database { * @return string */ public function int($values) { - //We'll be using an 8 digit precision to keep it in line with the serial8 datatype for ID columns - return 'numeric(8) not null default ' . (int) $values['default']; + return 'int not null default ' . (int) $values['default']; } /** @@ -1213,17 +1213,17 @@ class MSSQLDatabase extends SS_Database { /** * 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($asDbValue=false, $hasAutoIncPK=true){ - if($asDbValue) - return 'bigint not null'; - else { - if($hasAutoIncPK) - return 'bigint identity(1,1)'; - else return 'bigint not null'; + if($asDbValue) { + return 'int not null'; + } else { + if($hasAutoIncPK) { + return 'int identity(1,1)'; + } else { + return 'int not null'; + } } }