File: mg-db-constraint.h

package info (click to toggle)
mergeant 0.52-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 12,872 kB
  • ctags: 6,584
  • sloc: ansic: 63,372; xml: 23,218; sh: 10,895; makefile: 612; sql: 237
file content (127 lines) | stat: -rw-r--r-- 4,394 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* mg-db-constraint.h
 *
 * Copyright (C) 2003 Vivien Malerba
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */


#ifndef __MG_DB_CONSTRAINT_H_
#define __MG_DB_CONSTRAINT_H_

#include "mg-base.h"
#include "mg-ref-base.h"
#include "mg-defs.h"

G_BEGIN_DECLS

#define MG_DB_CONSTRAINT_TYPE          (mg_db_constraint_get_type())
#define MG_DB_CONSTRAINT(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, mg_db_constraint_get_type(), MgDbConstraint)
#define MG_DB_CONSTRAINT_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, mg_db_constraint_get_type (), MgDbConstraintClass)
#define IS_MG_DB_CONSTRAINT(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, mg_db_constraint_get_type ())


/* error reporting */
extern GQuark mg_db_constraint_error_quark (void);
#define MG_DB_CONSTRAINT_ERROR mg_db_constraint_error_quark ()

enum
{
	MG_DB_CONSTRAINT_XML_SAVE_ERROR,
	MG_DB_CONSTRAINT_XML_LOAD_ERROR
};

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

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;

typedef struct
{
	MgDbField *fkey;
	MgDbField *ref_pkey;
	MgRefBase *ref_pkey_repl; /* can be used instead of ref_pkey, the object will fill ref_pkey itself */
} MgDbConstraintFkeyPair;

#define MG_DB_CONSTRAINT_FK_PAIR(x) ((MgDbConstraintFkeyPair*) (x))

/* struct for the object's data */
struct _MgDbConstraint
{
	MgBase                  object;
	MgDbConstraintPrivate  *priv;
};

/* struct for the object's class */
struct _MgDbConstraintClass
{
	MgBaseClass                    class;

	/* signals */
	void   (*templ_signal)        (MgDbConstraint *obj);
};

guint              mg_db_constraint_get_type            (void);
GObject           *mg_db_constraint_new                 (MgDbTable *table, MgDbConstraintType type);
GObject           *mg_db_constraint_new_with_db         (MgDatabase *db);
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);

/* Primary KEY specific */
void               mg_db_constraint_pkey_set_fields     (MgDbConstraint *cstr, const GSList *fields);
GSList            *mg_db_constraint_pkey_get_fields     (MgDbConstraint *cstr);

/* Foreign KEY specific */
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);

/* UNIQUE specific */
void               mg_db_constraint_unique_set_fields   (MgDbConstraint *cstr, const GSList *fields);
GSList            *mg_db_constraint_unique_get_fields   (MgDbConstraint *cstr);

/* NOT NULL specific */
void               mg_db_constraint_not_null_set_field  (MgDbConstraint *cstr, MgDbField *field);
MgDbField         *mg_db_constraint_not_null_get_field  (MgDbConstraint *cstr);

/* Check specific */
/* TODO */

G_END_DECLS

#endif