~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/foreign_key.h

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 */
19
 
 
20
 
 
21
 
#ifndef DRIZZLED_FOREIGN_KEY_H
22
 
#define DRIZZLED_FOREIGN_KEY_H
23
 
 
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"
30
 
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
class Item;
35
 
class Table_ident;
36
 
 
37
 
namespace memory { class Root; }
38
 
 
39
 
void add_foreign_key_to_table_message(
40
 
    message::Table *table_message,
41
 
    const char* fkey_name,
42
 
    List<Key_part_spec> &cols,
43
 
    Table_ident *table,
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);
48
 
 
49
 
 
50
 
class Foreign_key: public Key 
51
 
{
52
 
public:
53
 
  Table_ident *ref_table;
54
 
  List<Key_part_spec> ref_columns;
55
 
 
56
 
  message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt;
57
 
  message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt;
58
 
  message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt;
59
 
 
60
 
  Foreign_key(const LEX_STRING &name_arg,
61
 
              List<Key_part_spec> &cols,
62
 
              Table_ident *table,
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)
72
 
  { }
73
 
 
74
 
 
75
 
  /**
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
79
 
   * in Session.
80
 
   */
81
 
  Foreign_key(const Foreign_key &rhs, memory::Root *mem_root);
82
 
 
83
 
 
84
 
  /**
85
 
   * Used to make a clone of this object for ALTER/CREATE TABLE
86
 
   * 
87
 
   * @see comment for Key_part_spec::clone
88
 
   */
89
 
  virtual Key *clone(memory::Root *mem_root) const
90
 
  {
91
 
    return new (mem_root) Foreign_key(*this, mem_root);
92
 
  }
93
 
 
94
 
 
95
 
  /* Used to validate foreign key options */
96
 
  bool validate(List<CreateField> &table_fields);
97
 
};
98
 
 
99
 
} /* namespace drizzled */
100
 
 
101
 
#endif /* DRIZZLED_FOREIGN_KEY_H */