function alterColumn($table, $column, $name, $notnull, $oldnotnull, $default, $olddefault, $type, $length, $array, $oldtype, $comment)
{
// Begin transaction
$status = $this->beginTransaction();
if ($status != 0) {
$this->rollbackTransaction();
return -6;
}
// Rename the column, if it has been changed
if ($column != $name) {
$status = $this->renameColumn($table, $column, $name);
if ($status != 0) {
$this->rollbackTransaction();
return -4;
}
}
$f_schema = $this->_schema;
$this->fieldClean($f_schema);
$this->fieldClean($name);
$this->fieldClean($table);
$this->fieldClean($column);
$toAlter = array();
// Create the command for changing nullability
if ($notnull != $oldnotnull) {
$toAlter[] = "ALTER COLUMN \"{$name}\" " . ($notnull ? 'SET' : 'DROP') . " NOT NULL";
}
// Add default, if it has changed
if ($default != $olddefault) {
if ($default == '') {
$toAlter[] = "ALTER COLUMN \"{$name}\" DROP DEFAULT";
} else {
$toAlter[] = "ALTER COLUMN \"{$name}\" SET DEFAULT {$default}";
}
}
// Add type, if it has changed
if ($length == '') {
$ftype = $type;
} else {
switch ($type) {
// Have to account for weird placing of length for with/without
// time zone types
case 'timestamp with time zone':
case 'timestamp without time zone':
$qual = substr($type, 9);
$ftype = "timestamp({$length}){$qual}";
break;
case 'time with time zone':
case 'time without time zone':
$qual = substr($type, 4);
$ftype = "time({$length}){$qual}";
break;
default:
$ftype = "{$type}({$length})";
}
}
// Add array qualifier, if requested
if ($array) {
$ftype .= '[]';
}
if ($ftype != $oldtype) {
$toAlter[] = "ALTER COLUMN \"{$name}\" TYPE {$ftype}";
}
// Attempt to process the batch alteration, if anything has been changed
if (!empty($toAlter)) {
// Initialise an empty SQL string
$sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" " . implode(',', $toAlter);
$status = $this->execute($sql);
if ($status != 0) {
$this->rollbackTransaction();
return -1;
}
}
// Update the comment on the column
$status = $this->setComment('COLUMN', $name, $table, $comment);
if ($status != 0) {
$this->rollbackTransaction();
return -5;
}
return $this->endTransaction();
}