Subject Re: [firebird-support] Re: unsuccessful metadata update object is in use
Author Helen Borrie
At 06:36 AM 28/04/2004 +0000, you wrote:
>Dear Martijn Tonies,
>
> > 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.

Try committing the transaction in which you create Table 1, before
attempting create a foreign key that references it. It's not a "new"
anything until those metadata get committed.

As for "documents/descriptions", it seems you need to understand the
concept of transactions. You might like to try a couple of TechInfo sheets
on the subject at the TechInfo page of www.ibobjects.com. Another place
where transactions are reasonably well documented is the Embedded SQL
Guide, from Borland's IB 6 documentation set (EmbedSql.pdf - google it, or
get it from www.ibphoenix.com InterBase download page)

/hb