MetaStore.declareForeignKey

Defines a new declared foreign key into store. If another declared foreign key is already defined between the two tables and with the same name, then it is first removed.

This method begins a transaction if possible (ie. none is already started), and if it can't, then if there is an error, the job may be partially done.

A check is always performed to make sure all the database objects actually exist and returns an error if not. The check is performed using mstruct if it's not null (in this case only the tables already represented in mstruct will be considered, in other words: mstruct will not be modified), and using an internal #GdaMetaStruct is null.

The catalog, schema, table, ref_catalog, ref_schema and ref_table must follow the SQL identifiers naming convention, see the <link linkend="gen:sql_identifiers">SQL identifiers</link> section. The same convention needs to be respected for the strings in conames and ref_colnames.

If catalog is not null, then schema must also be not null (the same restriction applies to ref_catalog and ref_schema).

class MetaStore
bool
declareForeignKey
(,
string fkName
,
string catalog
,
string schema
,
string table
,
string refCatalog
,
string refSchema
,
string refTable
,
string[] colnames
,
string[] refColnames
)

Parameters

mstruct gda.meta_struct.MetaStruct

a #GdaMetaStruct, or null

fkName string

the name of the foreign key to declare

catalog string

the catalog in which the table (for which the foreign key is for) is, or null

schema string

the schema in which the table (for which the foreign key is for) is, or null

table string

the name of the table (for which the foreign key is for)

refCatalog string

the catalog in which the referenced table is, or null

refSchema string

the schema in which the referenced table is, or null

refTable string

the name of the referenced table

colnames string[]

an array of column names from the table for which the foreign key is for

refColnames string[]

an array of column names from the referenced table

Return Value

Type: bool

true if no error occurred

Throws