~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/foreign_key.h

  • Committer: Monty Taylor
  • Date: 2009-03-06 03:33:24 UTC
  • mfrom: (916.1.2 merge)
  • Revision ID: mordred@inaugust.com-20090306033324-dcedf80g9qzywbvu
Merged Brian's merge... re-rotate the tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef DRIZZLED_FOREIGN_KEY_H
22
22
#define DRIZZLED_FOREIGN_KEY_H
23
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
 
{
 
24
#include <drizzled/sql_alloc.h>
 
25
#include <drizzled/key.h>
 
26
#include <drizzled/sql_list.h>
33
27
 
34
28
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
 
{
 
29
typedef struct st_mem_root MEM_ROOT;
 
30
 
 
31
class Foreign_key: public Key {
52
32
public:
 
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};
 
37
 
53
38
  Table_ident *ref_table;
54
39
  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),
 
40
  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),
71
48
    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
 
 
 
49
    {}
 
50
  Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root);
 
51
  /**
 
52
     Used to make a clone of this object for ALTER/CREATE TABLE
 
53
     @sa comment for Key_part_spec::clone
 
54
  */
 
55
  virtual Key *clone(MEM_ROOT *mem_root) const
 
56
  { return new (mem_root) Foreign_key(*this, mem_root); }
95
57
  /* Used to validate foreign key options */
96
 
  bool validate(List<CreateField> &table_fields);
 
58
  bool validate(List<Create_field> &table_fields);
97
59
};
98
60
 
99
 
} /* namespace drizzled */
100
 
 
101
61
#endif /* DRIZZLED_FOREIGN_KEY_H */