~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/foreign_key.cc

  • Committer: Andrew Hutchings
  • Date: 2011-02-01 10:23:22 UTC
  • mto: (2136.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2137.
  • Revision ID: andrew@linuxjedi.co.uk-20110201102322-oxztcyrjzg3c7yta
Fix counters cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"
 
28
#include "drizzled/table_ident.h"
29
29
 
30
30
namespace drizzled
31
31
{
32
32
 
33
 
extern const charset_info_st *system_charset_info;
 
33
extern const CHARSET_INFO *system_charset_info;
34
34
 
35
35
void add_foreign_key_to_table_message(
36
36
    message::Table *table_message,
64
64
  pfkey->set_references_table_name(table->table.str);
65
65
 
66
66
  Key_part_spec *keypart;
67
 
  List<Key_part_spec>::iterator col_it(cols.begin());
 
67
  List_iterator<Key_part_spec> col_it(cols);
68
68
  while ((keypart= col_it++))
69
69
  {
70
70
    pfkey->add_column_names(keypart->field_name.str);
71
71
  }
72
72
 
73
 
  List<Key_part_spec>::iterator ref_it(ref_cols.begin());
 
73
  List_iterator<Key_part_spec> ref_it(ref_cols);
74
74
  while ((keypart= ref_it++))
75
75
  {
76
76
    pfkey->add_references_columns(keypart->field_name.str);
78
78
 
79
79
}
80
80
 
81
 
/**
82
 
  Make a deep copy of each list element.
83
 
 
84
 
  @note A template function and not a template method of class List
85
 
  is employed because of explicit template instantiation:
86
 
  in server code there are explicit instantiations of List<T> and
87
 
  an explicit instantiation of a template requires that any method
88
 
  of the instantiated class used in the template can be resolved.
89
 
  Evidently not all template arguments have clone() method with
90
 
  the right signature.
91
 
 
92
 
  @return You must query the error state in Session for out-of-memory
93
 
  situation after calling this function.
94
 
*/
95
 
 
96
 
template <typename T>
97
 
void list_copy_and_replace_each_value(List<T> &list, memory::Root *mem_root)
98
 
{
99
 
  /* Make a deep copy of each element */
100
 
  typename List<T>::iterator it(list.begin());
101
 
  T *el;
102
 
  while ((el= it++))
103
 
    it.replace(el->clone(mem_root));
104
 
}
105
 
 
106
81
Foreign_key::Foreign_key(const Foreign_key &rhs, memory::Root *mem_root)
107
82
  :Key(rhs),
108
83
  ref_table(rhs.ref_table),
133
108
  /* Ensure that 'a' is the generated key */
134
109
  if (a->generated)
135
110
  {
136
 
    if (b->generated && a->columns.size() > b->columns.size())
 
111
    if (b->generated && a->columns.elements > b->columns.elements)
137
112
      std::swap(a, b);                       // Put shorter key in 'a'
138
113
  }
139
114
  else
144
119
  }
145
120
 
146
121
  /* Test if 'a' is a prefix of 'b' */
147
 
  if (a->columns.size() > b->columns.size())
 
122
  if (a->columns.elements > b->columns.elements)
148
123
    return true;                                // Can't be prefix
149
124
 
150
 
  List<Key_part_spec>::iterator col_it1(a->columns.begin());
151
 
  List<Key_part_spec>::iterator col_it2(b->columns.begin());
 
125
  List_iterator<Key_part_spec> col_it1(a->columns);
 
126
  List_iterator<Key_part_spec> col_it2(b->columns);
152
127
  const Key_part_spec *col1, *col2;
153
128
 
154
129
#ifdef ENABLE_WHEN_INNODB_CAN_HANDLE_SWAPED_FOREIGN_KEY_COLUMNS
155
130
  while ((col1= col_it1++))
156
131
  {
157
132
    bool found= 0;
158
 
    col_it2=b->columns.begin();
 
133
    col_it2.rewind();
159
134
    while ((col2= col_it2++))
160
135
    {
161
136
      if (*col1 == *col2)
191
166
{
192
167
  CreateField  *sql_field;
193
168
  Key_part_spec *column;
194
 
  List<Key_part_spec>::iterator cols(columns.begin());
195
 
  List<CreateField>::iterator it(table_fields.begin());
 
169
  List_iterator<Key_part_spec> cols(columns);
 
170
  List_iterator<CreateField> it(table_fields);
196
171
  while ((column= cols++))
197
172
  {
198
 
    it= table_fields.begin();
 
173
    it.rewind();
199
174
    while ((sql_field= it++) &&
200
175
           my_strcasecmp(system_charset_info,
201
176
                         column->field_name.str,