Hi Thomas,

I'm looking at the v1.2.147 code, sorry I can't get the latest version
yet.

I think the problem is in
AlterTableAlterColumn#cloneTableStructure(...){
        :
        :
        for (String sql : triggers) {
            execute(sql, true);
        }
        return newTable;
}

If you can move triggers execution out to the calling method
AlterTableAlterColumn#copyData()

I notice, Views are executed after the temp table is renamed, maybe
you can do the same with Triggers, delay the execute of trigger until
after temp table rename.

So I'm proposing to change AlterTableAlterColumn#copyData()
1. create new temp table
2. #cloneTableStructure() (without triggers)
3. #checkViews() //get views
4. #checkTriggers() //get triggers
5. DROP TABLE oldTable CASCADE
6. renameSchemaObject for newTable
7. execute the triggers
8. execute the views


Regards
Anthony

On May 13, 5:33 am, Thomas Mueller <[email protected]>
wrote:
> Hi,
>
> Currently, "alter table drop column" is implemented as:
>
> - create a new table (with the name TEMP_TABLE_...)
> - copy the data
> - rename the old table
> - rename the temp table
> - drop the old table
>
> The new table is created with a temporary name because at any time,
> only one table with a given name can exist.
>
> When renaming a table, the trigger init code isn't called. I wonder if
> it should be called - I guess it could be problematic because most
> likely it is already initialized.
>
> So, I'm not sure how to fix this problem currently. What do you
> suggest? One thing I could do (that wouldn't cause trouble) is to use
> a better name for the new table, such as: NEW_<tableName>. So if you
> alter a table called TEST the new table would be called NEW_TEST. (If
> such a table already exists, the new table would be called NEW1_TEST
> and so on.) In this way, at least the trigger has a chance to
> understand what the real table name is:
>
> tableName = tableName.replaceFirst("NEW.*_", "")
>
> What do you think? I know it's a bit ugly. As an alternative, the init
> method of the trigger could be called with the 'right' table name, but
> that would also be problematic because it's not actually correct.
>
> Regards,
> Thomas

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to