MgDbConstraint

MgDbConstraint — Represents a constraint within a database

Synopsis




            MgDbConstraint;
enum        MgDbConstraintType;
enum        MgDbConstraintFkAction;
guint       mg_db_constraint_get_type       (void);
GObject*    mg_db_constraint_new            (MgDbTable *table,
                                             MgDbConstraintType type);
MgDbConstraintType mg_db_constraint_get_constraint_type
                                            (MgDbConstraint *cstr);
gboolean    mg_db_constraint_equal          (MgDbConstraint *cstr1,
                                             MgDbConstraint *cstr2);
MgDbTable*  mg_db_constraint_get_table      (MgDbConstraint *cstr);
gboolean    mg_db_constraint_uses_field     (MgDbConstraint *cstr,
                                             MgDbField *field);
void        mg_db_constraint_pkey_set_fields
                                            (MgDbConstraint *cstr,
                                             const GSList *fields);
GSList*     mg_db_constraint_pkey_get_fields
                                            (MgDbConstraint *cstr);
void        mg_db_constraint_fkey_set_fields
                                            (MgDbConstraint *cstr,
                                             const GSList *pairs);
MgDbTable*  mg_db_constraint_fkey_get_ref_table
                                            (MgDbConstraint *cstr);
GSList*     mg_db_constraint_fkey_get_fields
                                            (MgDbConstraint *cstr);
void        mg_db_constraint_fkey_set_actions
                                            (MgDbConstraint *cstr,
                                             MgDbConstraintFkAction on_update,
                                             MgDbConstraintFkAction on_delete);
void        mg_db_constraint_fkey_get_actions
                                            (MgDbConstraint *cstr,
                                             MgDbConstraintFkAction *on_update,
                                             MgDbConstraintFkAction *on_delete);
void        mg_db_constraint_unique_set_fields
                                            (MgDbConstraint *cstr,
                                             const GSList *fields);
GSList*     mg_db_constraint_unique_get_fields
                                            (MgDbConstraint *cstr);
void        mg_db_constraint_not_null_set_field
                                            (MgDbConstraint *cstr,
                                             MgDbField *field);
MgDbField*  mg_db_constraint_not_null_get_field
                                            (MgDbConstraint *cstr);

Object Hierarchy


  GObject
   +----MgBase
         +----MgDbConstraint

Implemented Interfaces

MgDbConstraint implements MgXmlStorage and MgReferer.

Properties


  "user-constraint"      gboolean              : Read / Write

Signal Prototypes


"templ-signal"
            void        user_function      (MgDbConstraint *mgdbconstraint,
                                            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 MgXmlStorage and MgReferer interfaces.

Details

MgDbConstraint

typedef struct _MgDbConstraint MgDbConstraint;


enum MgDbConstraintType

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

Possible types of constraints

CONSTRAINT_PRIMARY_KEY Represents a primary key constraint which can be on a single field or on several fields at once.
CONSTRAINT_FOREIGN_KEY Represents a foreign key constraint which can be on a single field or on several fields at once, along with the referenced fields in another table.
CONSTRAINT_UNIQUE Represents a UNIQUE constraint (on a signle field or on several fields at once).
CONSTRAINT_NOT_NULL Represents a NOT NULL constraint on a single field.
CONSTRAINT_CHECK_EXPR Represents a CHECK constraint on any number of fields or tables (not yet implemented).
CONSTRAINT_UNKNOWN For error purposes.

enum MgDbConstraintFkAction

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

Possible actions performed by the DBMS on various events


mg_db_constraint_get_type ()

guint       mg_db_constraint_get_type       (void);

Returns :

mg_db_constraint_new ()

GObject*    mg_db_constraint_new            (MgDbTable *table,
                                             MgDbConstraintType type);

Creates a new MgDbConstraint object

table : the MgDbTable to which the constraint is attached
type : the type of constraint
Returns : the new object

mg_db_constraint_get_constraint_type ()

MgDbConstraintType mg_db_constraint_get_constraint_type
                                            (MgDbConstraint *cstr);

Get the type of constraint the cstr object represents

cstr : a MgDbConstraint object
Returns : the constraint type

mg_db_constraint_equal ()

gboolean    mg_db_constraint_equal          (MgDbConstraint *cstr1,
                                             MgDbConstraint *cstr2);

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

mg_db_constraint_get_table ()

MgDbTable*  mg_db_constraint_get_table      (MgDbConstraint *cstr);

Get the table to which the constraint is attached

cstr : a MgDbConstraint object
Returns : the MgDbTable

mg_db_constraint_uses_field ()

gboolean    mg_db_constraint_uses_field     (MgDbConstraint *cstr,
                                             MgDbField *field);

Tests if field is part of the cstr constraint

cstr : a MgDbConstraint object
field : a MgDbField object
Returns : TRUE if cstr uses field

mg_db_constraint_pkey_set_fields ()

void        mg_db_constraint_pkey_set_fields
                                            (MgDbConstraint *cstr,
                                             const GSList *fields);

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

cstr : a MgDbConstraint object
fields : a list of MgDbField objects

mg_db_constraint_pkey_get_fields ()

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

mg_db_constraint_fkey_set_fields ()

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

cstr : a MgDbConstraint object
pairs : a list of MgDbField objects

mg_db_constraint_fkey_get_ref_table ()

MgDbTable*  mg_db_constraint_fkey_get_ref_table
                                            (MgDbConstraint *cstr);

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

cstr : a MgDbConstraint object
Returns : the MgDbTable

mg_db_constraint_fkey_get_fields ()

GSList*     mg_db_constraint_fkey_get_fields
                                            (MgDbConstraint *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 MgDbConstraint object
Returns : a new list of MgDbConstraintFkeyPair pairs

mg_db_constraint_fkey_set_actions ()

void        mg_db_constraint_fkey_set_actions
                                            (MgDbConstraint *cstr,
                                             MgDbConstraintFkAction on_update,
                                             MgDbConstraintFkAction on_delete);

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

cstr : a MgDbConstraint object
on_update : the action undertaken when an UPDATE occurs
on_delete : the action undertaken when a DELETE occurs

mg_db_constraint_fkey_get_actions ()

void        mg_db_constraint_fkey_get_actions
                                            (MgDbConstraint *cstr,
                                             MgDbConstraintFkAction *on_update,
                                             MgDbConstraintFkAction *on_delete);

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

cstr : a MgDbConstraint 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

mg_db_constraint_unique_set_fields ()

void        mg_db_constraint_unique_set_fields
                                            (MgDbConstraint *cstr,
                                             const GSList *fields);

cstr : a MgDbConstraint object
fields :

mg_db_constraint_unique_get_fields ()

GSList*     mg_db_constraint_unique_get_fields
                                            (MgDbConstraint *cstr);

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

cstr : a MgDbConstraint object
Returns : a new list of fields

mg_db_constraint_not_null_set_field ()

void        mg_db_constraint_not_null_set_field
                                            (MgDbConstraint *cstr,
                                             MgDbField *field);

cstr :
field :

mg_db_constraint_not_null_get_field ()

MgDbField*  mg_db_constraint_not_null_get_field
                                            (MgDbConstraint *cstr);

cstr :
Returns :

Properties

The "user-constraint" property

  "user-constraint"      gboolean              : Read / Write

Default value: FALSE

Signals

The "templ-signal" signal

void        user_function                  (MgDbConstraint *mgdbconstraint,
                                            gpointer user_data);

mgdbconstraint : the object which received the signal.
user_data : user data set when the signal handler was connected.