## GnomeDbConstraint

GnomeDbConstraint — Represents a constraint within a database

##

# Synopsis

    struct      GnomeDbConstraint;
    enum        GnomeDbConstraintType;
    enum        GnomeDbConstraintFkAction;
    GType       gnome_db_constraint_get_type    (void);
    GObject*    gnome_db_constraint_new         (GnomeDbTable *table,
                                                 GnomeDbConstraintType type);
    GnomeDbConstraintType gnome_db_constraint_get_constraint_type
                                                (GnomeDbConstraint *cstr);
    gboolean    gnome_db_constraint_equal       (GnomeDbConstraint *cstr1,
                                                 GnomeDbConstraint *cstr2);
    GnomeDbTable* gnome_db_constraint_get_table (GnomeDbConstraint *cstr);
    gboolean    gnome_db_constraint_uses_field  (GnomeDbConstraint *cstr,
                                                 GnomeDbTableField *field);
    void        gnome_db_constraint_pkey_set_fields
                                                (GnomeDbConstraint *cstr,
                                                 const GSList *fields);
    GSList*     gnome_db_constraint_pkey_get_fields
                                                (GnomeDbConstraint *cstr);
    void        gnome_db_constraint_fkey_set_fields
                                                (GnomeDbConstraint *cstr,
                                                 const GSList *pairs);
    GnomeDbTable* gnome_db_constraint_fkey_get_ref_table
                                                (GnomeDbConstraint *cstr);
    GSList*     gnome_db_constraint_fkey_get_fields
                                                (GnomeDbConstraint *cstr);
    void        gnome_db_constraint_fkey_set_actions
                                                (GnomeDbConstraint *cstr,
                                                 GnomeDbConstraintFkAction on_update,
                                                 GnomeDbConstraintFkAction on_delete);
    void        gnome_db_constraint_fkey_get_actions
                                                (GnomeDbConstraint *cstr,
                                                 GnomeDbConstraintFkAction *on_update,
                                                 GnomeDbConstraintFkAction *on_delete);
    void        gnome_db_constraint_unique_set_fields
                                                (GnomeDbConstraint *cstr,
                                                 const GSList *fields);
    GSList*     gnome_db_constraint_unique_get_fields
                                                (GnomeDbConstraint *cstr);
    void        gnome_db_constraint_not_null_set_field
                                                (GnomeDbConstraint *cstr,
                                                 GnomeDbTableField *field);
    GnomeDbTableField* gnome_db_constraint_not_null_get_field
                                                (GnomeDbConstraint *cstr);

## Object Hierarchy

      GObject
       +----GnomeDbBase
             +----GnomeDbConstraint

## Implemented Interfaces

GnomeDbConstraint implements GnomeDbXmlStorage and GnomeDbReferer.

## Properties

      "user-constraint"      gboolean             : Read / Write

## Signal Prototypes

    "templ-signal"
                void        user_function      (GnomeDbConstraint *dbconstraint,
                                                gpointer user_data);

## 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 GnomeDbXmlStorage and GnomeDbReferer interfaces.

## Details

### struct GnomeDbConstraint

    struct GnomeDbConstraint;

### enum GnomeDbConstraintType

    typedef enum
    {
    	CONSTRAINT_PRIMARY_KEY,
    	CONSTRAINT_FOREIGN_KEY,
    	CONSTRAINT_UNIQUE,
    	CONSTRAINT_NOT_NULL,
    	CONSTRAINT_CHECK_EXPR,
    	CONSTRAINT_UNKNOWN
    } GnomeDbConstraintType;

### enum GnomeDbConstraintFkAction

    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
    } GnomeDbConstraintFkAction;

### gnome_db_constraint_get_type ()

    GType       gnome_db_constraint_get_type    (void);

Returns : |

### gnome_db_constraint_new ()

    GObject*    gnome_db_constraint_new         (GnomeDbTable *table,
                                                 GnomeDbConstraintType type);

Creates a new GnomeDbConstraint object

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

### gnome_db_constraint_get_constraint_type ()

    GnomeDbConstraintType gnome_db_constraint_get_constraint_type
                                                (GnomeDbConstraint *cstr);

Get the type of constraint the `cstr` object represents

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

### gnome_db_constraint_equal ()

    gboolean    gnome_db_constraint_equal       (GnomeDbConstraint *cstr1,
                                                 GnomeDbConstraint *cstr2);

Compares two GnomeDbConstraint 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 GnomeDbConstraint to compare
`cstr2` : | the second GnomeDbConstraint to compare
Returns : | TRUE if the two constraints are equal and FALSE otherwise

### gnome_db_constraint_get_table ()

    GnomeDbTable* gnome_db_constraint_get_table (GnomeDbConstraint *cstr);

Get the table to which the constraint is attached

`cstr` : | a GnomeDbConstraint object
Returns : | the GnomeDbTable

### gnome_db_constraint_uses_field ()

    gboolean    gnome_db_constraint_uses_field  (GnomeDbConstraint *cstr,
                                                 GnomeDbTableField *field);

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

`cstr` : | a GnomeDbConstraint object
`field` : | a GnomeDbTableField object
Returns : | TRUE if `cstr` uses `field`

### gnome_db_constraint_pkey_set_fields ()

    void        gnome_db_constraint_pkey_set_fields
                                                (GnomeDbConstraint *cstr,
                                                 const GSList *fields);

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

`cstr` : | a GnomeDbConstraint object
`fields` : | a list of GnomeDbTableField objects

### gnome_db_constraint_pkey_get_fields ()

    GSList*     gnome_db_constraint_pkey_get_fields
                                                (GnomeDbConstraint *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 GnomeDbConstraint object
Returns : | a new list of fields

### gnome_db_constraint_fkey_set_fields ()

    void        gnome_db_constraint_fkey_set_fields
                                                (GnomeDbConstraint *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 GnomeDbTable to which the constraint is attached and a field which belongs to a GnomeDbTable which is different from the one just mentionned and which is within the same database. The pairs are of type GnomeDbConstraintFkeyPair.

`cstr` : | a GnomeDbConstraint object
`pairs` : | a list of GnomeDbTableField objects

### gnome_db_constraint_fkey_get_ref_table ()

    GnomeDbTable* gnome_db_constraint_fkey_get_ref_table
                                                (GnomeDbConstraint *cstr);

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

`cstr` : | a GnomeDbConstraint object
Returns : | the GnomeDbTable

### gnome_db_constraint_fkey_get_fields ()

    GSList*     gnome_db_constraint_fkey_get_fields
                                                (GnomeDbConstraint *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 GnomeDbConstraint object
Returns : | a new list of GnomeDbConstraintFkeyPair pairs

### gnome_db_constraint_fkey_set_actions ()

    void        gnome_db_constraint_fkey_set_actions
                                                (GnomeDbConstraint *cstr,
                                                 GnomeDbConstraintFkAction on_update,
                                                 GnomeDbConstraintFkAction on_delete);

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

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

### gnome_db_constraint_fkey_get_actions ()

    void        gnome_db_constraint_fkey_get_actions
                                                (GnomeDbConstraint *cstr,
                                                 GnomeDbConstraintFkAction *on_update,
                                                 GnomeDbConstraintFkAction *on_delete);

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

`cstr` : | a GnomeDbConstraint 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

### gnome_db_constraint_unique_set_fields ()

    void        gnome_db_constraint_unique_set_fields
                                                (GnomeDbConstraint *cstr,
                                                 const GSList *fields);

`cstr` : | a GnomeDbConstraint object
`fields` : |

### gnome_db_constraint_unique_get_fields ()

    GSList*     gnome_db_constraint_unique_get_fields
                                                (GnomeDbConstraint *cstr);

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

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

### gnome_db_constraint_not_null_set_field ()

    void        gnome_db_constraint_not_null_set_field
                                                (GnomeDbConstraint *cstr,
                                                 GnomeDbTableField *field);

`cstr` : |
`field` : |

### gnome_db_constraint_not_null_get_field ()

    GnomeDbTableField* gnome_db_constraint_not_null_get_field
                                                (GnomeDbConstraint *cstr);

`cstr` : |
Returns : |

## Properties

"`user-constraint`" (gboolean : Read / Write) |

## Signals

### The "templ-signal" signal

    void        user_function                  (GnomeDbConstraint *dbconstraint,
                                                gpointer user_data);

`dbconstraint` : | the object which received the signal.
`user_data` : | user data set when the signal handler was connected.