fix for bug [ 1027089 ] ALTER TABLE ... ADD COLUMN ... DEFAULT doesn't work

postgres cant add a column with a default in one go
This commit is contained in:
Ralf Becker 2004-09-19 08:26:45 +00:00
parent 2fc3edccc2
commit 28ed51f49f

View File

@ -112,6 +112,33 @@ class ADODB2_postgres extends ADODB_DataDict {
}
}
/**
* Adding a new Column
*
* reimplementation of the default function as postgres does NOT allow to set the default in the same statement
*
* @param string $tabname table-name
* @param string $flds column-names and types for the changed columns
* @return array with SQL strings
*/
function AddColumnSQL($tabname, $flds)
{
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey) = $this->_GenFields($flds);
$alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' ';
foreach($lines as $v) {
if (preg_match('/^([^ ]+) .*(DEFAULT [^ ]+)/',$v,$matches)) {
list(,$colname,$default) = $matches;
$sql[] = $alter . str_replace($default,'',$v);
$sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET ' . $default;
} else {
$sql[] = $alter . $v;
}
}
return $sql;
}
/**
* Change the definition of one column
*