fix for bug #488: Postgres errors when upgrading to 1.4 beta

This commit is contained in:
Ralf Becker
2007-05-12 16:58:47 +00:00
parent 32864e955a
commit 7f64e2d175
3 changed files with 68 additions and 26 deletions

View File

@ -210,18 +210,21 @@ class ADODB2_postgres extends ADODB_DataDict {
{
if ($dropflds && !is_array($dropflds)) $dropflds = explode(',',$dropflds);
$copyflds = array();
foreach($this->MetaColumns($tabname) as $fld) {
foreach(($meta=$this->MetaColumns($tabname)) as $fld) {
if (!$dropflds || !in_array($fld->name,$dropflds)) {
// we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one
if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i',$tableflds,$matches) &&
in_array($fld->type,array('varchar','char','text','bytea'))) {
$copyflds[] = "to_number($fld->name,'S9999999999999D99')";
} elseif (preg_match('/'.$fld->name.' ([\w]+)/i',$tableflds,$matches) &&
strtoupper($fld->type) != ($type = $this->ActualType($matches[1]))) {
$copyflds[] = "CAST($fld->name AS $type)";
} else {
$copyflds[] = $fld->name;
}
// identify the sequence name and the fld its on
if ($fld->primary_key && $fld->has_default &&
preg_match("/nextval\('([^']+)'::text\)/",$fld->default_value,$matches)) {
preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) {
$seq_name = $matches[1];
$seq_fld = $fld->name;
}