Index: trunk/core/kernel/utility/temp_handler.php =================================================================== diff -u -r2792 -r2794 --- trunk/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 2792) +++ trunk/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 2794) @@ -23,6 +23,8 @@ var $DroppedTables = Array(); + var $FinalRefs = Array(); + /** * Description * @@ -101,17 +103,19 @@ $query = sprintf("CREATE TABLE %s SELECT * FROM %s WHERE 0", $this->GetTempName($table), $table); - + $this->Conn->Query($query); } function BuildTables($prefix, $ids) { + $this->TableIdCounter = 0; $tables = Array( 'TableName' => $this->Application->getUnitOption($prefix,'TableName'), 'IdField' => $this->Application->getUnitOption($prefix,'IDField'), 'IDs' => $ids, 'Prefix' => $prefix, + 'TableId' => $this->TableIdCounter++, ); $SubItems = $this->Application->getUnitOption($prefix,'SubItems'); @@ -133,7 +137,9 @@ 'Prefix' => $prefix, 'AutoClone' => $this->Application->getUnitOption($prefix,'AutoClone'), 'AutoDelete' => $this->Application->getUnitOption($prefix,'AutoDelete'), + 'TableId' => $this->TableIdCounter++, ); + $this->FinalRefs[$tmp['TableName']] = $tmp['TableId']; $constrain = $this->Application->getUnitOption($prefix,'Constrain'); if ($constrain) $tmp['Constrain'] = $constrain; @@ -483,11 +489,14 @@ // no need to clear temp table - it will be dropped by next statement } } - if ( is_array(getArrayValue($master, 'ForeignKey')) ) { //if multiple ForeignKeys + + if ($this->FinalRefs[$master['TableName']] != $master['TableId']) return; + + /*if ( is_array(getArrayValue($master, 'ForeignKey')) ) { //if multiple ForeignKeys if ( $master['ForeignKey'][$parent_prefix] != end($master['ForeignKey']) ) { return; // Do not delete temp table if not all ForeignKeys have been processed (current is not the last) } - } + }*/ $this->DropTempTable($master['TableName']); }