diff --git a/phpgwapi/inc/class.db.inc.php b/phpgwapi/inc/class.db.inc.php index c39bcc56c9..2baf96b23b 100644 --- a/phpgwapi/inc/class.db.inc.php +++ b/phpgwapi/inc/class.db.inc.php @@ -793,6 +793,26 @@ if (is_array($str)) $this->halt('db::db_addslashes('.print_r($str,True).",'$type return array(); } + /** + * Returns an array containing column names that are the primary keys of $tablename. + * + * @return array of columns + */ + function pkey_columns($tablename) + { + if (!$this->Link_ID && !$this->connect()) + { + return False; + } + // REMOVE-IF-ONLY-ADODB + if (isset($GLOBALS['phpgw_info']['server']['use_adodb']) && + !@$GLOBALS['phpgw_info']['server']['use_adodb']) + { + return array(); + } + return $this->Link_ID->MetaPrimaryKeys($tablename); + } + /** * Create a new database * diff --git a/phpgwapi/inc/class.schema_proc_pgsql.inc.php b/phpgwapi/inc/class.schema_proc_pgsql.inc.php index d55410ded8..8b8bf65a04 100644 --- a/phpgwapi/inc/class.schema_proc_pgsql.inc.php +++ b/phpgwapi/inc/class.schema_proc_pgsql.inc.php @@ -602,14 +602,16 @@ $oProc->m_odb->query("ALTER TABLE $sOldTableName ALTER $sField SET DEFAULT nextval('seq_" . $sNewTableName . "')",__LINE__,__FILE__); } + $indexes = array(); $indexnames = $oProc->m_odb->index_names(); while(list($key,$val) = @each($indexnames)) { $indexes[] = $val['index_name']; } - if(!in_array($sOldTableName . '_pkey',$indexes)) // no idea how this can happen + $pkeys = $oProc->m_odb->pkey_columns($sOldTableName); + if(!in_array($sOldTableName . '_pkey',$indexes) && !isset($pkeys[0])) // no idea how this can happen { - $oProc->m_odb->query("DROP INDEX " . $sOldTableName . "_pkey",__LINE__,__FILE__); + $oProc->m_odb->query("ALTER TABLE " . $sOldTableName . " DROP CONSTRAINT " . $sOldTableName . "_pkey",__LINE__,__FILE__); } else // rename the index {