Subject Re: [Firebird-Java] Re: How to turn referential integrity checking off
Author Roman Rokytskyy
> Yes, the deferred constraint checks describe definitely better what I
> have to do. My purpose is to find a way to populate a target Firebird
> database without having problems with referenced tables that still do
> not exist (because they're still not written to the database at that
> point in time).

I think you mean that data in the tables do not exist, not the tables
themselves. Right?

>> The talk is about a global switch that triggers all constrains
>> inactive without a need to walk through all system tables and
>> deactivating each constraint separately.
>
> That will also suit my purpose: turn all constraints off, populate the
> Firebird database without complaints about references to nonexistent
> table columns, then turn the checks on as they have initially been.

Yup, but this functionality does not exist, as well as the deferred
constraint checking.

> As far as I could understand, one suggestion to do this is to drop all
> constraints and then create them anew. Is there a way to protocol the
> existent constraints somewhere before dropping them?

You have to code it yourself. You can walk through all tables, get their
constraints with DatabaseMetaData call (getImportedKeys and
getExportedKeys), store somewhere, and at the end construct appropriate SQL
statements.

> What kind of switch is it?

-N or -NO_VALIDITY

> Could you please tell me if I can find the source code for the gbak.exe
> somewhere in the CVS repository:
> http://cvs.sourceforge.net/viewcvs.py/firebird/ in order to have a look?

That is either firebird2/src/burp for Firebird 1.5 and 2.0 code base or
interbase/burp for Firebird 1.0 code base. BURP means BackUp and Restore
Protocol(?). But if I understand correctly, that won't help you much, since
the approach there is a bit different. When gbak creates a backup file, it
stores the constraints separately as ALTER TABLE ... ADD CONSTRAINT
statements (sure, that are not direct SQL statements, but something
similar). So, during restore the switch tells simply to ignore the
constraint restoration.

Roman