fix RenameTable for PostgreSQL to only use old logic, if we still have an old sequence, and if old logic is used, set sequence value

This commit is contained in:
Ralf Becker 2016-08-01 13:32:43 +02:00
parent 27468f0dac
commit c033435122

View File

@ -371,12 +371,15 @@ class Schema
{ {
if (!($table_def = $this->GetTableDefinition($sOldTableName))) return 0; if (!($table_def = $this->GetTableDefinition($sOldTableName))) return 0;
if ($this->_PostgresHasOldSequence($sOldTableName,True) || count($table_def['pk']) || // only use old PostgreSQL stuff, if we have an old sequence, otherwise rely on it being new enough
count($table_def['ix']) || count($table_def['uc'])) if ($this->_PostgresHasOldSequence($sOldTableName,True) &&
(count($table_def['pk']) || count($table_def['ix']) || count($table_def['uc'])))
{ {
if ($this->adodb->BeginTrans() && if ($this->adodb->BeginTrans() &&
$this->CreateTable($sNewTableName,$table_def,True) && $this->CreateTable($sNewTableName,$table_def,True) &&
$this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName",__LINE__,__FILE__) && $this->m_odb->query("INSERT INTO $sNewTableName SELECT * FROM $sOldTableName",__LINE__,__FILE__) &&
// sequence must be updated, after inserts containing pkey, otherwise new inserst will fail!
(count($table_def['pk']) !== 1 || $this->UpdateSequence($sNewTableName, $table_def['pk'][0])) &&
$this->DropTable($sOldTableName)) $this->DropTable($sOldTableName))
{ {
$this->adodb->CommitTrans(); $this->adodb->CommitTrans();