mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 08:23:12 +01:00
fixed (hopefully last) postgres problem with the indices: sequences have not been set, after the data was inserted into the newly created table
This commit is contained in:
parent
4ae1356b53
commit
39c7cc14da
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
re<?php
|
||||
/**************************************************************************\
|
||||
* eGroupWare - Setup *
|
||||
* http://www.egroupware.org *
|
||||
@ -219,6 +219,16 @@
|
||||
|
||||
return $retVal && $this->m_oTranslator->CreateTable($this, $this->m_aTables, $sTableName, $aTableDef);
|
||||
}
|
||||
|
||||
function UpdateSequence($sTableName,$sColumnName)
|
||||
{
|
||||
if (method_exists($this->m_oTranslator,'UpdateSequence'))
|
||||
{
|
||||
return $this->m_oTranslator->UpdateSequence($this->m_odb,$sTableName,$sColumnName);
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
// This function manually re-created the table incl. primary key and all other indices
|
||||
// It is meant to use if the primary key, existing indices or column-order changes or
|
||||
@ -269,7 +279,7 @@
|
||||
$select[] = $value;
|
||||
}
|
||||
$select = implode(',',$select);
|
||||
|
||||
|
||||
$Ok = $this->RenameTable($sTableName,$tmp_name) &&
|
||||
$this->CreateTable($sTableName,$aTableDef) &&
|
||||
$this->m_odb->query("INSERT INTO $sTableName SELECT DISTINCT $select FROM $tmp_name",__LINE__,__FILE__);
|
||||
@ -279,6 +289,11 @@
|
||||
$this->m_odb->transaction_abort();
|
||||
return False;
|
||||
}
|
||||
// do we need to update the new sequences value ?
|
||||
if (count($aTableDef['pk']) == 1 && $aTableDef['fd'][$aTableDef['pk'][0]]['type'] == 'auto')
|
||||
{
|
||||
$this->UpdateSequence($sTableName,$aTableDef['pk'][0]);
|
||||
}
|
||||
$this->DropTable($tmp_name);
|
||||
$this->m_odb->transaction_commit();
|
||||
|
||||
|
@ -699,6 +699,20 @@
|
||||
return $Ok;
|
||||
}
|
||||
|
||||
function UpdateSequence($oDb,$sTableName,$sColName)
|
||||
{
|
||||
$sql = "SELECT MAX($sColName) FROM $sTableName";
|
||||
|
||||
$oDb->query($sql,__LINE__,__FILE__);
|
||||
if ($oDb->next_record() && $oDb->f(0))
|
||||
{
|
||||
$sql = "SELECT setval('seq_$sTableName',".(1 + $oDb->f(0)).")";
|
||||
if($GLOBALS['DEBUG']) { echo "<br>Updating sequence 'seq_$sTableName' using: $sql"; }
|
||||
return $oDb->query($sql,__LINE__,__FILE__);
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
function GetSequenceSQL($sTableName, &$sSequenceSQL)
|
||||
{
|
||||
$sSequenceSQL = sprintf("CREATE SEQUENCE seq_%s", $sTableName);
|
||||
|
Loading…
Reference in New Issue
Block a user