MINOR Removed redundant code from various MSSQLDatabase methods - it is now more inline with MySQLDatabase

This commit is contained in:
Sean Harvey 2010-02-03 07:50:29 +00:00
parent b8b85a12a2
commit de7068d591

View File

@ -828,19 +828,11 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function boolean($values, $asDbValue=false){ public function boolean($values) {
//Annoyingly, we need to do a good ol' fashioned switch here: //Annoyingly, we need to do a good ol' fashioned switch here:
($values['default']) ? $default='1' : $default='0'; ($values['default']) ? $default='1' : $default='0';
if($asDbValue) {
return array(
'data_type'=>'bit',
'default' => $default
);
} else {
return 'bit not null default ' . $default; return 'bit not null default ' . $default;
} }
}
/** /**
* Return a date type-formatted string. * Return a date type-formatted string.
@ -848,15 +840,9 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function date($values, $asDbValue=false){ public function date($values) {
if($asDbValue) {
return array(
'data_type' => 'decimal',
);
} else {
return 'datetime null'; return 'datetime null';
} }
}
/** /**
* Return a decimal type-formatted string * Return a decimal type-formatted string
@ -864,7 +850,7 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function decimal($values, $asDbValue=false){ public function decimal($values) {
// Avoid empty strings being put in the db // Avoid empty strings being put in the db
if($values['precision'] == '') { if($values['precision'] == '') {
$precision = 1; $precision = 1;
@ -877,12 +863,8 @@ class MSSQLDatabase extends SS_Database {
$defaultValue = $values['default']; $defaultValue = $values['default'];
} }
if($asDbValue) {
return array('data_type'=>'decimal', 'numeric_precision'=>'9,2');
} else {
return 'decimal(' . $precision . ') not null default ' . $defaultValue; return 'decimal(' . $precision . ') not null default ' . $defaultValue;
} }
}
/** /**
* Return a enum type-formatted string * Return a enum type-formatted string
@ -890,25 +872,17 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function enum($values, $asDbValue=false){ public function enum($values) {
// Enums are a bit different. We'll be creating a varchar(255) with a constraint of all the // Enums are a bit different. We'll be creating a varchar(255) with a constraint of all the
// usual enum options. // usual enum options.
// NOTE: In this one instance, we are including the table name in the values array // NOTE: In this one instance, we are including the table name in the values array
$maxLength = max(array_map('strlen', $values['enums'])); $maxLength = max(array_map('strlen', $values['enums']));
if($asDbValue) {
return array(
'data_type'=>'varchar',
'default' => $values['default'],
'character_maximum_length'=>$maxLength,
);
} else {
return "varchar($maxLength) not null default '" . $values['default'] return "varchar($maxLength) not null default '" . $values['default']
. "' check(\"" . $values['name'] . "\" in ('" . implode("','", $values['enums']) . "' check(\"" . $values['name'] . "\" in ('" . implode("','", $values['enums'])
. "'))"; . "'))";
} }
}
/** /**
* Return a float type-formatted string. * Return a float type-formatted string.
@ -916,10 +890,8 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function float($values, $asDbValue=false){ public function float($values) {
if($asDbValue) return 'float';
return Array('data_type'=>'float');
else return 'float';
} }
/** /**
@ -928,12 +900,9 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function int($values, $asDbValue=false){ public function int($values) {
//We'll be using an 8 digit precision to keep it in line with the serial8 datatype for ID columns //We'll be using an 8 digit precision to keep it in line with the serial8 datatype for ID columns
if($asDbValue) return 'numeric(8) not null default ' . (int) $values['default'];
return Array('data_type'=>'numeric', 'numeric_precision'=>'8', 'default'=>(int)$values['default']);
else
return 'numeric(8) not null default ' . (int)$values['default'];
} }
/** /**
@ -943,10 +912,7 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function ss_datetime($values, $asDbValue=false){ public function ss_datetime($values) {
if($asDbValue)
return Array('data_type'=>'datetime');
else
return 'datetime null'; return 'datetime null';
} }
@ -956,16 +922,9 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function text($values, $asDbValue=false){ public function text($values) {
if($asDbValue) {
return array(
'data_type'=>'varchar',
'character_maximum_length' => -1,
);
} else {
return 'varchar(max) null'; return 'varchar(max) null';
} }
}
/** /**
* Return a time type-formatted string. * Return a time type-formatted string.
@ -983,10 +942,7 @@ class MSSQLDatabase extends SS_Database {
* @params array $values Contains a tokenised list of info about this data type * @params array $values Contains a tokenised list of info about this data type
* @return string * @return string
*/ */
public function varchar($values, $asDbValue=false){ public function varchar($values) {
if($asDbValue)
return Array('data_type'=>'varchar', 'character_maximum_length'=>$values['precision']);
else
return 'varchar(' . $values['precision'] . ') null'; return 'varchar(' . $values['precision'] . ') null';
} }
@ -994,10 +950,8 @@ class MSSQLDatabase extends SS_Database {
* Return a 4 digit numeric type. * Return a 4 digit numeric type.
* @return string * @return string
*/ */
public function year($values, $asDbValue=false){ public function year($values) {
if($asDbValue) return 'numeric(4)';
return Array('data_type'=>'numeric', 'numeric_precision'=>'4');
else return 'numeric(4)';
} }
function escape_character($escape=false){ function escape_character($escape=false){