Drizzled Public API Documentation

foreign_key.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 
00021 #pragma once
00022 
00023 #include <drizzled/memory/sql_alloc.h>
00024 #include <drizzled/key.h>
00025 #include <drizzled/key_part_spec.h>
00026 #include <drizzled/sql_list.h>
00027 #include <drizzled/cursor.h> /* for default_key_create_info */
00028 #include <drizzled/message/table.pb.h>
00029 
00030 namespace drizzled
00031 {
00032 
00033 class Item;
00034 class Table_ident;
00035 
00036 namespace memory { class Root; }
00037 
00038 void add_foreign_key_to_table_message(
00039     message::Table *table_message,
00040     const char* fkey_name,
00041     List<Key_part_spec> &cols,
00042     Table_ident *table,
00043     List<Key_part_spec> &ref_cols,
00044     message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
00045     message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
00046     message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg);
00047 
00048 
00049 class Foreign_key: public Key 
00050 {
00051 public:
00052   Table_ident *ref_table;
00053   List<Key_part_spec> ref_columns;
00054 
00055   message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt;
00056   message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt;
00057   message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt;
00058 
00059   Foreign_key(const LEX_STRING &name_arg,
00060               List<Key_part_spec> &cols,
00061               Table_ident *table,
00062               List<Key_part_spec> &ref_cols,
00063               message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
00064               message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
00065               message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg) :
00066     Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols), ref_table(table),
00067     ref_columns(ref_cols),
00068     delete_opt(delete_opt_arg),
00069     update_opt(update_opt_arg),
00070     match_opt(match_opt_arg)
00071   { }
00072 
00073 
00080   Foreign_key(const Foreign_key &rhs, memory::Root *mem_root);
00081 
00082 
00088   virtual Key *clone(memory::Root *mem_root) const
00089   {
00090     return new (mem_root) Foreign_key(*this, mem_root);
00091   }
00092 
00093 
00094   /* Used to validate foreign key options */
00095   bool validate(List<CreateField> &table_fields);
00096 };
00097 
00098 } /* namespace drizzled */
00099