mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 06:05:53 +00:00
API CHANGE Renamed EnumValuesFromConstraint() to enumValuesFromCheckClause() as it's more specific to what the method is actually doing, which is parsing a constraint clause
This commit is contained in:
parent
14cf1d243c
commit
ecea643f76
@ -550,21 +550,20 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
and c.name = '$colName'")->value();
|
and c.name = '$colName'")->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the actual enum fields from the constraint value:
|
* Get enum values from a constraint check clause.
|
||||||
|
* @param string $clause Check clause to parse values from
|
||||||
|
* @return array Enum values
|
||||||
*/
|
*/
|
||||||
protected function EnumValuesFromConstraint($constraint){
|
protected function enumValuesFromCheckClause($clause) {
|
||||||
$segments=preg_split('/ +OR *\[/i', $constraint);
|
$segments = preg_split('/ +OR *\[/i', $clause);
|
||||||
$constraints=Array();
|
$constraints = array();
|
||||||
foreach($segments as $this_segment){
|
foreach($segments as $segment) {
|
||||||
$bits=preg_split('/ *= */', $this_segment);
|
$bits = preg_split('/ *= */', $segment);
|
||||||
|
for($i = 1; $i < sizeof($bits); $i += 2) {
|
||||||
for($i=1; $i<sizeof($bits); $i+=2)
|
|
||||||
array_unshift($constraints, substr(rtrim($bits[$i], ')'), 1, -1));
|
array_unshift($constraints, substr(rtrim($bits[$i], ')'), 1, -1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $constraints;
|
return $constraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,9 +724,14 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
//Check to see if there's a constraint attached to this column:
|
//Check to see if there's a constraint attached to this column:
|
||||||
$clause = $this->getConstraintCheckClause($table, $field['column_name']);
|
$clause = $this->getConstraintCheckClause($table, $field['column_name']);
|
||||||
if($clause) {
|
if($clause) {
|
||||||
$constraints=$this->EnumValuesFromConstraint($clause);
|
$constraints = $this->enumValuesFromCheckClause($clause);
|
||||||
$default=substr($field['column_default'], 2, -2);
|
$default = substr($field['column_default'], 2, -2);
|
||||||
$field['data_type']=$this->enum(Array('default'=>$default, 'name'=>$field['column_name'], 'enums'=>$constraints, 'table'=>$table));
|
$field['data_type'] = $this->enum(array(
|
||||||
|
'default' => $default,
|
||||||
|
'name' => $field['column_name'],
|
||||||
|
'enums' => $constraints,
|
||||||
|
'table' => $table
|
||||||
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1110,8 +1114,9 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
// Get the enum of all page types from the SiteTree table
|
// Get the enum of all page types from the SiteTree table
|
||||||
$clause = $this->getConstraintCheckClause($tableName, $fieldName);
|
$clause = $this->getConstraintCheckClause($tableName, $fieldName);
|
||||||
if($clause) {
|
if($clause) {
|
||||||
$classes = $this->EnumValuesFromConstraint($clause);
|
$classes = $this->enumValuesFromCheckClause($clause);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $classes;
|
return $classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user