26
26
#include <drizzled/sql_list.h>
29
31
typedef struct st_mem_root MEM_ROOT;
31
33
class Foreign_key: public Key {
33
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
34
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
35
enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE,
36
FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT};
38
52
Table_ident *ref_table;
39
53
List<Key_part_spec> ref_columns;
40
54
uint32_t delete_opt, update_opt, match_opt;
41
Foreign_key(const LEX_STRING &name_arg, List<Key_part_spec> &cols,
42
Table_ident *table, List<Key_part_spec> &ref_cols,
43
uint32_t delete_opt_arg, uint32_t update_opt_arg,
44
uint32_t match_opt_arg)
45
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
46
ref_table(table), ref_columns(ref_cols),
47
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
48
match_opt(match_opt_arg)
55
Foreign_key(const LEX_STRING &name_arg
56
, List<Key_part_spec> &cols
58
, List<Key_part_spec> &ref_cols
59
, uint32_t delete_opt_arg
60
, uint32_t update_opt_arg
61
, uint32_t match_opt_arg)
64
, &default_key_create_info
68
, ref_columns(ref_cols)
69
, delete_opt(delete_opt_arg)
70
, update_opt(update_opt_arg)
71
, match_opt(match_opt_arg)
74
* Constructs an (almost) deep copy of this foreign key. Only those
75
* elements that are known to never change are not copied.
76
* If out of memory, a partial copy is returned and an error is set
50
79
Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root);
52
Used to make a clone of this object for ALTER/CREATE TABLE
53
@sa comment for Key_part_spec::clone
81
* Used to make a clone of this object for ALTER/CREATE TABLE
83
* @see comment for Key_part_spec::clone
55
85
virtual Key *clone(MEM_ROOT *mem_root) const
56
{ return new (mem_root) Foreign_key(*this, mem_root); }
87
return new (mem_root) Foreign_key(*this, mem_root);
57
89
/* Used to validate foreign key options */
58
90
bool validate(List<Create_field> &table_fields);