1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifndef DRIZZLED_FOREIGN_KEY_H
22
#define DRIZZLED_FOREIGN_KEY_H
24
#include "drizzled/memory/sql_alloc.h"
25
#include "drizzled/key.h"
26
#include "drizzled/key_part_spec.h"
27
#include "drizzled/sql_list.h"
28
#include "drizzled/cursor.h" /* for default_key_create_info */
29
#include "drizzled/message/table.pb.h"
37
namespace memory { class Root; }
39
void add_foreign_key_to_table_message(
40
message::Table *table_message,
41
const char* fkey_name,
42
List<Key_part_spec> &cols,
44
List<Key_part_spec> &ref_cols,
45
message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
46
message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
47
message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg);
50
class Foreign_key: public Key
53
Table_ident *ref_table;
54
List<Key_part_spec> ref_columns;
56
message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt;
57
message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt;
58
message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt;
60
Foreign_key(const LEX_STRING &name_arg,
61
List<Key_part_spec> &cols,
63
List<Key_part_spec> &ref_cols,
64
message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
65
message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
66
message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg) :
67
Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols), ref_table(table),
68
ref_columns(ref_cols),
69
delete_opt(delete_opt_arg),
70
update_opt(update_opt_arg),
71
match_opt(match_opt_arg)
76
* Constructs an (almost) deep copy of this foreign key. Only those
77
* elements that are known to never change are not copied.
78
* If out of memory, a partial copy is returned and an error is set
81
Foreign_key(const Foreign_key &rhs, memory::Root *mem_root);
85
* Used to make a clone of this object for ALTER/CREATE TABLE
87
* @see comment for Key_part_spec::clone
89
virtual Key *clone(memory::Root *mem_root) const
91
return new (mem_root) Foreign_key(*this, mem_root);
95
/* Used to validate foreign key options */
96
bool validate(List<CreateField> &table_fields);
99
} /* namespace drizzled */
101
#endif /* DRIZZLED_FOREIGN_KEY_H */