GdaDbFkey: libgda Reference Manual

## GdaDbFkey GdaDbFkey — Object to hold information for foregn key. |

## Stability Level

Stable, unless otherwise indicated

## Functions

GdaDbFkey * | gda_db_fkey_new ()
GdaDbFkey * | gda_db_fkey_new_from_meta ()
const GList * | gda_db_fkey_get_field_name ()
const GList * | gda_db_fkey_get_ref_field ()
void | gda_db_fkey_set_field ()
const gchar * | gda_db_fkey_get_ref_table ()
void | gda_db_fkey_set_ref_table ()
const gchar * | gda_db_fkey_get_ondelete ()
GdaDbFkeyReferenceAction | gda_db_fkey_get_ondelete_id ()
void | gda_db_fkey_set_ondelete ()
const gchar * | gda_db_fkey_get_onupdate ()
GdaDbFkeyReferenceAction | gda_db_fkey_get_onupdate_id ()
void | gda_db_fkey_set_onupdate ()
gboolean | gda_db_fkey_prepare_create ()

## Types and Values

| GdaDbFkey
#define | GDA_TYPE_DB_FKEY
enum | GdaDbFkeyReferenceAction

## Object Hierarchy

        GObject
        ╰── GdaDbFkey

## Implemented Interfaces

GdaDbFkey implements GdaDbBuildable.

## Includes

    #include <libgda/libgda.h>

## Description

For generating database from xml file or for mapping database to an xml file GdaDbFkey holds information about foregn keys with a convenient set of methods to manipulate them. GdaDbFkey implements GdaDbBuildable interface for parsing xml file. This is an example how GdaDbFkey can be used:

    1
    2
    3
    4
    5
    6
    7
    GdaDbFkey *fkey = gda_db_fkey_new ();
    gda_db_fkey_set_ref_table (fkey, "Project");
    gda_db_fkey_set_ondelete (fkey, GDA_DB_FKEY_RESTRICT);
    gda_db_fkey_set_onupdate (fkey, GDA_DB_FKEY_RESTRICT);
    gda_db_fkey_set_field (fkey, "project_id", "id");

    gda_db_table_append_fkey (temployee, fkey);

## Functions

### gda_db_fkey_new ()

    GdaDbFkey *
    gda_db_fkey_new (void);

Create a new GdaDbFkey object.

Since: 6.0

Stability Level: Stable

### gda_db_fkey_new_from_meta ()

    GdaDbFkey *
    gda_db_fkey_new_from_meta (GdaMetaTableForeignKey *metafkey);

Create a new instance from the corresponding meta object. If `metafkey` is `NULL`, this function is identical to `gda_db_fkey_new()`.

#### Parameters

metafkey | a GdaMetaTableForeignKey instance |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_get_field_name ()

    const GList *
    gda_db_fkey_get_field_name (GdaDbFkey *self);

#### Parameters

self | a GdaDbFkey object |

#### Returns

A const GList of strings where each string corresponds to a foreign key field or `NULL`.

[element-type utf8][transfer none]

Since: 6.0

Stability Level: Stable

### gda_db_fkey_get_ref_field ()

    const GList *
    gda_db_fkey_get_ref_field (GdaDbFkey *self);

#### Parameters

self | a GdaDbFkey object |

#### Returns

A GList of strings where each string corresponds to a foreign key reference field or `NULL`.

[element-type utf8][transfer none]

Since: 6.0

Stability Level: Stable

### gda_db_fkey_set_field ()

    void
    gda_db_fkey_set_field (GdaDbFkey *self,
                           const gchar *field,
                           const gchar *reffield);

All arguments should be valid strings.

#### Parameters

self | An object GdaDbFkey |
field | Field name as a string |
reffield | A reference field name as a string |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_get_ref_table ()

    const gchar *
    gda_db_fkey_get_ref_table (GdaDbFkey *self);

Return: Returns reference table name as a string or `NULL` if table name hasn't been set.

#### Parameters

self | a GdaDbFkey object |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_set_ref_table ()

    void
    gda_db_fkey_set_ref_table (GdaDbFkey *self,
                               const gchar *rtable);

Set reference table

#### Parameters

self | GdaDbFkey object |
rtable | reference table name |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_get_ondelete ()

    const gchar *
    gda_db_fkey_get_ondelete (GdaDbFkey *self);

Return: ON DELETE action as a string. If the action is not set then the string corresponding to NO_ACTION is returned.

#### Parameters

self | An object GdaDbFkey |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_get_ondelete_id ()

    GdaDbFkeyReferenceAction
    gda_db_fkey_get_ondelete_id (GdaDbFkey *self);

The default value is `NO_ACTION`

Return: ON DELETE action as a GdaDbFkeyReferenceAction.

#### Parameters

self | a GdaDbFkey object |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_set_ondelete ()

    void
    gda_db_fkey_set_ondelete (GdaDbFkey *self,
                              GdaDbFkeyReferenceAction id);

Set action for ON_DELETE

#### Parameters

self | An object GdaDbFkey |
id | GdaDbFkeyReferenceAction action to set |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_get_onupdate ()

    const gchar *
    gda_db_fkey_get_onupdate (GdaDbFkey *self);

#### Parameters

self | a GdaDbFkey instance |

#### Returns

ON_UPDATE action as a string. Never `NULL`

Since: 6.0

Stability Level: Stable

### gda_db_fkey_get_onupdate_id ()

    GdaDbFkeyReferenceAction
    gda_db_fkey_get_onupdate_id (GdaDbFkey *self);

Return: ON_UPDATE action as a GdaDbFkeyReferenceAction

#### Parameters

self | a GdaDbFkey instance |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_set_onupdate ()

    void
    gda_db_fkey_set_onupdate (GdaDbFkey *self,
                              GdaDbFkeyReferenceAction id);

Set action for ON_UPDATE

#### Parameters

self | An object GdaDbFkey |
id | GdaDbFkeyReferenceAction action to set |

Since: 6.0

Stability Level: Stable

### gda_db_fkey_prepare_create ()

    gboolean
    gda_db_fkey_prepare_create (GdaDbFkey *self,
                                GdaServerOperation *op,
                                gint i,
                                GError **error);

Prepare `op` object for execution by populating with information stored in `self` .

#### Parameters

self | a GdaDbFkey instance |
op | a GdaServerOperation to populate |
i | Order number |
error | error container |

#### Returns

`TRUE` if no error or `FALSE` otherwise.

Since: 6.0

Stability Level: Stable

## Types and Values

### GdaDbFkey

    typedef struct _GdaDbFkey GdaDbFkey;

### GDA_TYPE_DB_FKEY

    #define GDA_TYPE_DB_FKEY (gda_db_fkey_get_type())

### enum GdaDbFkeyReferenceAction

Specify numeric value for the actions, e.g. "ON DELETE" and "ON UPDATE"

#### Members

GDA_DB_FKEY_NO_ACTION | Action is not specified. |
GDA_DB_FKEY_SET_NULL | Action value is set to `NULL` |
GDA_DB_FKEY_RESTRICT | Value is set to "RESTRICT" |
GDA_DB_FKEY_SET_DEFAULT | Value is set to default behavior |
GDA_DB_FKEY_CASCADE | Value is set to cascade |