Merge pull request #16 from halkyon/int_fix

Fixing use of "bigint" and "decimal" for pure integer types.
This commit is contained in:
Sean Harvey 2014-07-15 09:25:31 +12:00
commit 14bd3016b9

View File

@ -713,11 +713,12 @@ class MSSQLDatabase extends SS_Database {
// Update the data_type field to be a complete column definition string for use by // Update the data_type field to be a complete column definition string for use by
// SS_Database::requireField() // SS_Database::requireField()
switch($field['data_type']){ switch($field['data_type']){
case 'int':
case 'bigint': case 'bigint':
case 'numeric': case 'numeric':
case 'float': case 'float':
case 'bit': case 'bit':
if($field['data_type'] != 'bigint' && $sizeSuffix = $field['numeric_precision']) { if($field['data_type'] != 'bigint' && $field['data_type'] != 'int' && $sizeSuffix = $field['numeric_precision']) {
$field['data_type'] .= "($sizeSuffix)"; $field['data_type'] .= "($sizeSuffix)";
} }
@ -918,7 +919,7 @@ class MSSQLDatabase extends SS_Database {
* @param string $tableName * @param string $tableName
* @param string $indexName * @param string $indexName
* @param string $prefix The optional prefix for the index. Defaults to "ix" for indexes. * @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') { function buildMSSQLIndexName($tableName, $indexName, $prefix = 'ix') {
@ -1156,8 +1157,7 @@ class MSSQLDatabase extends SS_Database {
* @return string * @return string
*/ */
public function int($values) { 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 'int not null default ' . (int) $values['default'];
return 'numeric(8) 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 * 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 * @return string
*/ */
function IdColumn($asDbValue=false, $hasAutoIncPK=true){ function IdColumn($asDbValue=false, $hasAutoIncPK=true){
if($asDbValue) if($asDbValue) {
return 'bigint not null'; return 'int not null';
else { } else {
if($hasAutoIncPK) if($hasAutoIncPK) {
return 'bigint identity(1,1)'; return 'int identity(1,1)';
else return 'bigint not null'; } else {
return 'int not null';
}
} }
} }