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 void add_foreign_key_to_table_message(
00033     message::Table *table_message,
00034     const char* fkey_name,
00035     List<Key_part_spec> &cols,
00036     Table_ident *table,
00037     List<Key_part_spec> &ref_cols,
00038     message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
00039     message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
00040     message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg);
00041 
00042 
00043 class Foreign_key : public Key 
00044 {
00045 public:
00046   Table_ident *ref_table;
00047   List<Key_part_spec> ref_columns;
00048 
00049   message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt;
00050   message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt;
00051   message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt;
00052 
00053   Foreign_key(str_ref name_arg,
00054               List<Key_part_spec> &cols,
00055               Table_ident *table,
00056               List<Key_part_spec> &ref_cols,
00057               message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
00058               message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
00059               message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg) :
00060     Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols), ref_table(table),
00061     ref_columns(ref_cols),
00062     delete_opt(delete_opt_arg),
00063     update_opt(update_opt_arg),
00064     match_opt(match_opt_arg)
00065   { }
00066 
00067 
00074   Foreign_key(const Foreign_key &rhs, memory::Root *mem_root);
00075 
00076   /* Used to validate foreign key options */
00077   bool validate(List<CreateField> &table_fields);
00078 };
00079 
00080 } /* namespace drizzled */