~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/foreign_key.cc

  • Committer: Monty Taylor
  • Date: 2010-08-12 20:27:32 UTC
  • mto: (1720.1.5 build)
  • mto: This revision was merged to the branch mainline in revision 1722.
  • Revision ID: mordred@inaugust.com-20100812202732-9kzchbkvkyki4n3u
Merged libdrizzle directly into tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
22
#include <string>
23
23
 
24
 
#include <drizzled/foreign_key.h>
25
 
#include <drizzled/error.h>
26
 
#include <drizzled/create_field.h>
27
 
#include <drizzled/internal/my_sys.h>
28
 
#include <drizzled/table_ident.h>
 
24
#include "drizzled/foreign_key.h"
 
25
#include "drizzled/error.h"
 
26
#include "drizzled/create_field.h"
 
27
#include "drizzled/internal/my_sys.h"
29
28
 
30
29
namespace drizzled
31
30
{
32
31
 
33
32
extern const CHARSET_INFO *system_charset_info;
34
33
 
35
 
void add_foreign_key_to_table_message(
36
 
    message::Table *table_message,
37
 
    const char* fkey_name,
38
 
    List<Key_part_spec> &cols,
39
 
    Table_ident *table,
40
 
    List<Key_part_spec> &ref_cols,
41
 
    message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
42
 
    message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
43
 
    message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg)
44
 
{
45
 
  message::Table::ForeignKeyConstraint *pfkey= table_message->add_fk_constraint();
46
 
  if (fkey_name)
47
 
    pfkey->set_name(fkey_name);
48
 
  else if (table_message->has_name())
49
 
  {
50
 
    std::string name(table_message->name());
51
 
    char number[20];
52
 
 
53
 
    name.append("_ibfk_");
54
 
    snprintf(number, sizeof(number), "%d", table_message->fk_constraint_size());
55
 
    name.append(number);
56
 
 
57
 
    pfkey->set_name(name);
58
 
  }
59
 
 
60
 
  pfkey->set_match(match_opt_arg);
61
 
  pfkey->set_update_option(update_opt_arg);
62
 
  pfkey->set_delete_option(delete_opt_arg);
63
 
 
64
 
  pfkey->set_references_table_name(table->table.str);
65
 
 
66
 
  Key_part_spec *keypart;
67
 
  List<Key_part_spec>::iterator col_it(cols.begin());
68
 
  while ((keypart= col_it++))
69
 
  {
70
 
    pfkey->add_column_names(keypart->field_name.str);
71
 
  }
72
 
 
73
 
  List<Key_part_spec>::iterator ref_it(ref_cols.begin());
74
 
  while ((keypart= ref_it++))
75
 
  {
76
 
    pfkey->add_references_columns(keypart->field_name.str);
77
 
  }
78
 
 
79
 
}
80
 
 
81
34
Foreign_key::Foreign_key(const Foreign_key &rhs, memory::Root *mem_root)
82
35
  :Key(rhs),
83
36
  ref_table(rhs.ref_table),
122
75
  if (a->columns.elements > b->columns.elements)
123
76
    return true;                                // Can't be prefix
124
77
 
125
 
  List<Key_part_spec>::iterator col_it1(a->columns.begin());
126
 
  List<Key_part_spec>::iterator col_it2(b->columns.begin());
 
78
  List_iterator<Key_part_spec> col_it1(a->columns);
 
79
  List_iterator<Key_part_spec> col_it2(b->columns);
127
80
  const Key_part_spec *col1, *col2;
128
81
 
129
82
#ifdef ENABLE_WHEN_INNODB_CAN_HANDLE_SWAPED_FOREIGN_KEY_COLUMNS
130
83
  while ((col1= col_it1++))
131
84
  {
132
85
    bool found= 0;
133
 
    col_it2=b->columns.begin();
 
86
    col_it2.rewind();
134
87
    while ((col2= col_it2++))
135
88
    {
136
89
      if (*col1 == *col2)
166
119
{
167
120
  CreateField  *sql_field;
168
121
  Key_part_spec *column;
169
 
  List<Key_part_spec>::iterator cols(columns.begin());
170
 
  List<CreateField>::iterator it(table_fields.begin());
 
122
  List_iterator<Key_part_spec> cols(columns);
 
123
  List_iterator<CreateField> it(table_fields);
171
124
  while ((column= cols++))
172
125
  {
173
 
    it= table_fields.begin();
 
126
    it.rewind();
174
127
    while ((sql_field= it++) &&
175
128
           my_strcasecmp(system_charset_info,
176
129
                         column->field_name.str,