Subject Re: [firebird-support] Re: unsuccessful metadata update object is in use
Author Martijn Tonies
Hi,

> > Because adding a FK will raise an error if it isn't an exclusive
> > connection.
>
> Thanks for the reply.. But I'd like to understand the reason for
> the "error".. Why should the firebird prevent meta data updates for
> even non-used tables.. ie., I can not do even the following
> operation :
>
> String createTable1 = "Create table table1 (ID INTEGER NOT NULL
> PRIMARY KEY)";
>
> String createTable2 = "Create table table2 (ID INTEGER NOT NULL
> PRIMARY KEY, FOREIGN KEY (ID) REFERENCES table1(ID))";
>
> Connection conn1 = DriverManager.getConnection(..); // first
> connection to firebirddb
> Connection conn2 = DriverManager.getConnection(..);// second
> connection to firebirddb
>
> Statement stmt = conn1.createStatement();
> stmt.executeUpdate(createTable1); //creates the table1
> stmt.executeUpdate(createTable2); //creates the table2
>
> The error happens during the creation of table2. The question I have
> is: the 'table1' that is being referred is anyway a "NEW" table and
> is NOT used by any other transaction; then why should the metadata
> update be denied for this table. If this is anything to do with the
> way the firebird db handles the metadata operations, I'd be grateful
> if I can get any document/descriptions reasoning this behavior.

The "why" is that it simply always will raise the error as soon
as there are more than one connection to the database.

Internally, it simply checks for the number of connections and
raises an error if this is more than 1.

There are some historic reasons for this, but I don't know the
precise ones...

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com