forked from extern/egroupware
fixed RenameTable to also rename indices and not only primary keys
This commit is contained in:
parent
1ba38621ba
commit
6a4447b62e
@ -36,6 +36,7 @@
|
|||||||
/* Return a type suitable for DDL */
|
/* Return a type suitable for DDL */
|
||||||
function TranslateType($sType, $iPrecision = 0, $iScale = 0)
|
function TranslateType($sType, $iPrecision = 0, $iScale = 0)
|
||||||
{
|
{
|
||||||
|
$sTranslated = $sType;
|
||||||
switch($sType)
|
switch($sType)
|
||||||
{
|
{
|
||||||
case 'auto':
|
case 'auto':
|
||||||
@ -82,12 +83,6 @@
|
|||||||
$sTranslated = 'text';
|
$sTranslated = 'text';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'date':
|
|
||||||
case 'text':
|
|
||||||
case 'timestamp':
|
|
||||||
case 'bool':
|
|
||||||
$sTranslated = $sType;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return $sTranslated;
|
return $sTranslated;
|
||||||
}
|
}
|
||||||
@ -601,25 +596,16 @@
|
|||||||
if($GLOBALS['DEBUG']) { echo '<br>RenameTable(): Altering column default for: ' . $sField; }
|
if($GLOBALS['DEBUG']) { echo '<br>RenameTable(): Altering column default for: ' . $sField; }
|
||||||
$oProc->m_odb->query("ALTER TABLE $sOldTableName ALTER $sField SET DEFAULT nextval('seq_" . $sNewTableName . "')",__LINE__,__FILE__);
|
$oProc->m_odb->query("ALTER TABLE $sOldTableName ALTER $sField SET DEFAULT nextval('seq_" . $sNewTableName . "')",__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
|
// renameing existing indexes and primary keys
|
||||||
$indexes = array();
|
$indexes = $oProc->m_odb->Link_ID->MetaIndexes($sOldTableName,True);
|
||||||
$indexnames = $oProc->m_odb->index_names();
|
if($GLOBALS['DEBUG']) { echo '<br>RenameTable(): Fetching indexes: '.print_r($indexes,True); }
|
||||||
while(list($key,$val) = @each($indexnames))
|
foreach($indexes as $name => $data)
|
||||||
{
|
{
|
||||||
$indexes[] = $val['index_name'];
|
$new_name = str_replace($sOldTableName,$sNewTableName,$name);
|
||||||
|
$sql = "ALTER TABLE $name RENAME TO $new_name";
|
||||||
|
if($GLOBALS['DEBUG']) { echo "<br>RenameTable(): Renaming the index '$name': $sql"; }
|
||||||
|
$oProc->m_odb->query($sql);
|
||||||
}
|
}
|
||||||
$pkeys = $oProc->m_odb->pkey_columns($sOldTableName);
|
|
||||||
if(!in_array($sOldTableName . '_pkey',$indexes) && !isset($pkeys[0])) // no idea how this can happen
|
|
||||||
{
|
|
||||||
// this happens if the table has no primary key --> nothing to do
|
|
||||||
// trying to drop the (not existing) constrain results in an error
|
|
||||||
//$oProc->m_odb->query("ALTER TABLE " . $sOldTableName . " DROP CONSTRAINT " . $sOldTableName . "_pkey",__LINE__,__FILE__);
|
|
||||||
}
|
|
||||||
else // rename the index
|
|
||||||
{
|
|
||||||
$oProc->m_odb->query('ALTER TABLE '.$sOldTableName.'_pkey RENAME TO '.$sNewTableName.'_pkey');
|
|
||||||
}
|
|
||||||
|
|
||||||
return !!($oProc->m_odb->query("ALTER TABLE $sOldTableName RENAME TO $sNewTableName"));
|
return !!($oProc->m_odb->query("ALTER TABLE $sOldTableName RENAME TO $sNewTableName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user