## GdaDictConstraint GdaDictConstraint — Represents a constraint within a database |

## Synopsis

                        GdaDictConstraint;
    enum                GdaDictConstraintType;
    enum                GdaDictConstraintFkAction;
    GdaDictConstraint*  gda_dict_constraint_new             (GdaDictTable *table,
                                                             GdaDictConstraintType type);
    GdaDictConstraint*  gda_dict_constraint_new_with_db     (GdaDictDatabase *db);
    GdaDictConstraintType gda_dict_constraint_get_constraint_type
                                                            (GdaDictConstraint *cstr);
    gboolean            gda_dict_constraint_equal           (GdaDictConstraint *cstr1,
                                                             GdaDictConstraint *cstr2);
    GdaDictTable*       gda_dict_constraint_get_table       (GdaDictConstraint *cstr);
    gboolean            gda_dict_constraint_uses_field      (GdaDictConstraint *cstr,
                                                             GdaDictField *field);
    void                gda_dict_constraint_pkey_set_fields (GdaDictConstraint *cstr,
                                                             const GSList *fields);
    GSList*             gda_dict_constraint_pkey_get_fields (GdaDictConstraint *cstr);
    void                gda_dict_constraint_fkey_set_fields (GdaDictConstraint *cstr,
                                                             const GSList *pairs);
    GdaDictTable*       gda_dict_constraint_fkey_get_ref_table
                                                            (GdaDictConstraint *cstr);
    GSList*             gda_dict_constraint_fkey_get_fields (GdaDictConstraint *cstr);
    void                gda_dict_constraint_fkey_set_actions
                                                            (GdaDictConstraint *cstr,
                                                             GdaDictConstraintFkAction on_update,
                                                             GdaDictConstraintFkAction on_delete);
    void                gda_dict_constraint_fkey_get_actions
                                                            (GdaDictConstraint *cstr,
                                                             GdaDictConstraintFkAction *on_update,
                                                             GdaDictConstraintFkAction *on_delete);
    void                gda_dict_constraint_unique_set_fields
                                                            (GdaDictConstraint *cstr,
                                                             const GSList *fields);
    GSList*             gda_dict_constraint_unique_get_fields
                                                            (GdaDictConstraint *cstr);
    void                gda_dict_constraint_not_null_set_field
                                                            (GdaDictConstraint *cstr,
                                                             GdaDictField *field);
    GdaDictField*       gda_dict_constraint_not_null_get_field
                                                            (GdaDictConstraint *cstr);

## Object Hierarchy

      GObject
       +----GdaObject
             +----GdaDictConstraint

## Implemented Interfaces

GdaDictConstraint implements GdaXmlStorage and GdaReferer.

## Properties

      "user-constraint"          gboolean              : Read / Write

## Description

Any type of constraint in a database is represented by one instance of the class (see the possible types of constraints). As some constraints may not depend exclusively on a table, all the constraints are attached to the database itself.

It implements the GdaXmlStorage and GdaReferer interfaces.

## Details

### GdaDictConstraint

    typedef struct _GdaDictConstraint GdaDictConstraint;

### enum GdaDictConstraintType

    typedef enum
    {
    	CONSTRAINT_PRIMARY_KEY,
    	CONSTRAINT_FOREIGN_KEY,
    	CONSTRAINT_UNIQUE,
    	CONSTRAINT_NOT_NULL,
    	CONSTRAINT_CHECK_EXPR,
    	CONSTRAINT_CHECK_IN_LIST,
    	CONSTRAINT_CHECK_SETOF_LIST,
    	CONSTRAINT_UNKNOWN
    } GdaDictConstraintType;

### enum GdaDictConstraintFkAction

    typedef enum
    {
    	CONSTRAINT_FK_ACTION_CASCADE,
    	CONSTRAINT_FK_ACTION_SET_NULL,
    	CONSTRAINT_FK_ACTION_SET_DEFAULT,
    	CONSTRAINT_FK_ACTION_SET_VALUE,
    	CONSTRAINT_FK_ACTION_NO_ACTION
    } GdaDictConstraintFkAction;

### gda_dict_constraint_new ()

    GdaDictConstraint*  gda_dict_constraint_new             (GdaDictTable *table,
                                                             GdaDictConstraintType type);

Creates a new GdaDictConstraint object

`table` : | the GdaDictTable to which the constraint is attached
`type` : | the type of constraint
Returns : | the new object

### gda_dict_constraint_new_with_db ()

    GdaDictConstraint*  gda_dict_constraint_new_with_db     (GdaDictDatabase *db);

Creates a new GdaDictConstraint object without specifying anything about the constraint except the database it is attached to. This is usefull only when the object is going to be loaded from an XML node.

`db` : | a GdaDictDatabase object
Returns : | the new uninitialized object

### gda_dict_constraint_get_constraint_type ()

    GdaDictConstraintType gda_dict_constraint_get_constraint_type
                                                            (GdaDictConstraint *cstr);

Get the type of constraint the `cstr` object represents

`cstr` : | a GdaDictConstraint object
Returns : | the constraint type

### gda_dict_constraint_equal ()

    gboolean            gda_dict_constraint_equal           (GdaDictConstraint *cstr1,
                                                             GdaDictConstraint *cstr2);

Compares two GdaDictConstraint objects to see if they are equal, without taking into account the name of the constraints or weather they are user or system defined

`cstr1` : | the first GdaDictConstraint to compare
`cstr2` : | the second GdaDictConstraint to compare
Returns : | TRUE if the two constraints are equal and FALSE otherwise

### gda_dict_constraint_get_table ()

    GdaDictTable*       gda_dict_constraint_get_table       (GdaDictConstraint *cstr);

Get the table to which the constraint is attached

`cstr` : | a GdaDictConstraint object
Returns : | the GdaDictTable

### gda_dict_constraint_uses_field ()

    gboolean            gda_dict_constraint_uses_field      (GdaDictConstraint *cstr,
                                                             GdaDictField *field);

Tests if `field` is part of the `cstr` constraint

`cstr` : | a GdaDictConstraint object
`field` : | a GdaDictField object
Returns : | TRUE if `cstr` uses `field`

### gda_dict_constraint_pkey_set_fields ()

    void                gda_dict_constraint_pkey_set_fields (GdaDictConstraint *cstr,
                                                             const GSList *fields);

Sets the fields which make the primary key represented by `cstr`. All the fields must belong to the same GdaDictTable to which the constraint is attached

`cstr` : | a GdaDictConstraint object
`fields` : | a list of GdaDictField objects

### gda_dict_constraint_pkey_get_fields ()

    GSList*             gda_dict_constraint_pkey_get_fields (GdaDictConstraint *cstr);

Get the list of fields composing the primary key constraint which `cstr` represents. The returned list is allocated and must be de-allocated by the caller.

`cstr` : | a GdaDictConstraint object
Returns : | a new list of fields

### gda_dict_constraint_fkey_set_fields ()

    void                gda_dict_constraint_fkey_set_fields (GdaDictConstraint *cstr,
                                                             const GSList *pairs);

Sets the field pairs which make the foreign key represented by `cstr`. All the field pairs must list a field which belong to the same GdaDictTable to which the constraint is attached and a field which belongs to a GdaDictTable which is different from the one just mentionned and which is within the same database. The pairs are of type GdaDictConstraintFkeyPair.

`cstr` : | a GdaDictConstraint object
`pairs` : | a list of GdaDictField objects

### gda_dict_constraint_fkey_get_ref_table ()

    GdaDictTable*       gda_dict_constraint_fkey_get_ref_table
                                                            (GdaDictConstraint *cstr);

Get the GdaDictTable at the other end of the foreign key relation represented by this constraint

`cstr` : | a GdaDictConstraint object
Returns : | the GdaDictTable

### gda_dict_constraint_fkey_get_fields ()

    GSList*             gda_dict_constraint_fkey_get_fields (GdaDictConstraint *cstr);

Get the list of field pairs composing the foreign key constraint which `cstr` represents. In the returned list, each pair item is allocated and it's up to the caller to free the list and each pair, and the reference count for each pointer to GObjects in each pair is NOT INCREASED, which means the caller of this function DOES NOT hold any reference on the mentionned GObjects (if he needs to, it has to call `g_object_ref()`)

`cstr` : | a GdaDictConstraint object
Returns : | a new list of GdaDictConstraintFkeyPair pairs

### gda_dict_constraint_fkey_set_actions ()

    void                gda_dict_constraint_fkey_set_actions
                                                            (GdaDictConstraint *cstr,
                                                             GdaDictConstraintFkAction on_update,
                                                             GdaDictConstraintFkAction on_delete);

Sets the actions undertaken by the DBMS when some actions occur on the referenced data

`cstr` : | a GdaDictConstraint object
`on_update` : | the action undertaken when an UPDATE occurs
`on_delete` : | the action undertaken when a DELETE occurs

### gda_dict_constraint_fkey_get_actions ()

    void                gda_dict_constraint_fkey_get_actions
                                                            (GdaDictConstraint *cstr,
                                                             GdaDictConstraintFkAction *on_update,
                                                             GdaDictConstraintFkAction *on_delete);

Get the actions undertaken by the DBMS when some actions occur on the referenced data

`cstr` : | a GdaDictConstraint object
`on_update` : | an address to store the action undertaken when an UPDATE occurs
`on_delete` : | an address to store the action undertaken when a DELETE occurs

### gda_dict_constraint_unique_set_fields ()

    void                gda_dict_constraint_unique_set_fields
                                                            (GdaDictConstraint *cstr,
                                                             const GSList *fields);

`cstr` : | a GdaDictConstraint object
`fields` : |

### gda_dict_constraint_unique_get_fields ()

    GSList*             gda_dict_constraint_unique_get_fields
                                                            (GdaDictConstraint *cstr);

Get the list of fields represented by this UNIQUE constraint. It's up to the caller to free the list.

`cstr` : | a GdaDictConstraint object
Returns : | a new list of fields

### gda_dict_constraint_not_null_set_field ()

    void                gda_dict_constraint_not_null_set_field
                                                            (GdaDictConstraint *cstr,
                                                             GdaDictField *field);

`cstr` : |
`field` : |

### gda_dict_constraint_not_null_get_field ()

    GdaDictField*       gda_dict_constraint_not_null_get_field
                                                            (GdaDictConstraint *cstr);

`cstr` : |
Returns : |

## Property Details

### The `"user-constraint"` property

      "user-constraint"          gboolean              : Read / Write

Default value: FALSE