~drizzle-trunk/drizzle/development

584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
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>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
30
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
31
namespace drizzled
32
{
33
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
34
class Item;
934.2.20 by Jay Pipes
Move Foreign_key implementation into its own implementation file and out of session.cc
35
class Table_ident;
36
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
37
namespace memory { class Root; }
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
38
1638.10.78 by Stewart Smith
separate out adding the foreign key to the table protobuf message from mysql_prepare_create_table and call a function to do it directly from the parser where we set up the foreign key structures
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
1237.9.4 by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file.
50
class Foreign_key: public Key 
51
{
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
52
public:
53
  Table_ident *ref_table;
54
  List<Key_part_spec> ref_columns;
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
55
56
  message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt;
57
  message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt;
58
  message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt;
59
1089.1.6 by Brian Aker
Removed dead flag code, style cleanup in FK. Removed dead structs.
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,
1638.9.2 by Stewart Smith
use the ENUM in the table proto instead of duplicating it for Foreign key options and match option. A move in the direction of just having foreign keys in the proto
64
              message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
65
              message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
66
              message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg) :
1089.1.6 by Brian Aker
Removed dead flag code, style cleanup in FK. Removed dead structs.
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
934.2.20 by Jay Pipes
Move Foreign_key implementation into its own implementation file and out of session.cc
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
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
81
  Foreign_key(const Foreign_key &rhs, memory::Root *mem_root);
1089.1.6 by Brian Aker
Removed dead flag code, style cleanup in FK. Removed dead structs.
82
83
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
84
  /**
934.2.20 by Jay Pipes
Move Foreign_key implementation into its own implementation file and out of session.cc
85
   * Used to make a clone of this object for ALTER/CREATE TABLE
86
   * 
87
   * @see comment for Key_part_spec::clone
88
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
89
  virtual Key *clone(memory::Root *mem_root) const
934.2.20 by Jay Pipes
Move Foreign_key implementation into its own implementation file and out of session.cc
90
  {
91
    return new (mem_root) Foreign_key(*this, mem_root);
92
  }
1089.1.6 by Brian Aker
Removed dead flag code, style cleanup in FK. Removed dead structs.
93
94
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
95
  /* Used to validate foreign key options */
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
96
  bool validate(List<CreateField> &table_fields);
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
97
};
98
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
99
} /* namespace drizzled */
100
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
101
#endif /* DRIZZLED_FOREIGN_KEY_H */