BUGFIX Checking for existence of constraint specs to avoid PHP notice errors on schema updates in PotgreSQLDatabase->alterTableAlterColumn() (regression from r113928)

This commit is contained in:
Ingo Schommer 2010-12-05 04:59:43 +00:00
parent d5915cd7d1
commit 99f2cb179e

View File

@ -670,22 +670,24 @@ class PostgreSQLDatabase extends SS_Database {
// SET check constraint (The constraint HAS to be dropped) // SET check constraint (The constraint HAS to be dropped)
$existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$tableName}_{$colName}_check';")->value(); $existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$tableName}_{$colName}_check';")->value();
//Take this new constraint and see what's outstanding from the target table: if(isset($matches[4])) {
$constraint_bits=explode('(', $matches[4]); //Take this new constraint and see what's outstanding from the target table:
$constraint_values=trim($constraint_bits[2], ')'); $constraint_bits=explode('(', $matches[4]);
$constraint_values_bits=explode(',', $constraint_values); $constraint_values=trim($constraint_bits[2], ')');
$default=trim($constraint_values_bits[0], " '"); $constraint_values_bits=explode(',', $constraint_values);
$default=trim($constraint_values_bits[0], " '");
//Now go and convert anything that's not in this list to 'Page'
//We have to run this as a query, not as part of the alteration queries due to the way they are constructed. //Now go and convert anything that's not in this list to 'Page'
$updateConstraint=''; //We have to run this as a query, not as part of the alteration queries due to the way they are constructed.
$updateConstraint.="UPDATE \"{$tableName}\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);"; $updateConstraint='';
if($this->hasTable("{$tableName}_Live")) $updateConstraint.="UPDATE \"{$tableName}\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
$updateConstraint.="UPDATE \"{$tableName}_Live\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);"; if($this->hasTable("{$tableName}_Live"))
if($this->hasTable("{$tableName}_versions")) $updateConstraint.="UPDATE \"{$tableName}_Live\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
$updateConstraint.="UPDATE \"{$tableName}_versions\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);"; if($this->hasTable("{$tableName}_versions"))
$updateConstraint.="UPDATE \"{$tableName}_versions\" SET \"$colName\"='$default' WHERE \"$colName\" NOT IN ($constraint_values);";
DB::query($updateConstraint);
DB::query($updateConstraint);
}
//First, delete any existing constraint on this column, even if it's no longer an enum //First, delete any existing constraint on this column, even if it's no longer an enum
if($existing_constraint) if($existing_constraint)