~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/foreign_key.cc

  • Committer: Olaf van der Spek
  • Date: 2011-08-05 13:28:48 UTC
  • mto: This revision was merged to the branch mainline in revision 2395.
  • Revision ID: olafvdspek@gmail.com-20110805132848-vvwjg6pgwf56xnsd
Use const char* instead of str_ref

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 *system_charset_info;
 
33
extern const charset_info_st *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_iterator<Key_part_spec> col_it(cols);
 
67
  List<Key_part_spec>::iterator col_it(cols.begin());
68
68
  while ((keypart= col_it++))
69
69
  {
70
70
    pfkey->add_column_names(keypart->field_name.str);
71
71
  }
72
72
 
73
 
  List_iterator<Key_part_spec> ref_it(ref_cols);
 
73
  List<Key_part_spec>::iterator ref_it(ref_cols.begin());
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
  while (T* el= it++)
 
102
    it.replace(el->clone(mem_root));
 
103
}
 
104
 
81
105
Foreign_key::Foreign_key(const Foreign_key &rhs, memory::Root *mem_root)
82
106
  :Key(rhs),
83
107
  ref_table(rhs.ref_table),
108
132
  /* Ensure that 'a' is the generated key */
109
133
  if (a->generated)
110
134
  {
111
 
    if (b->generated && a->columns.elements > b->columns.elements)
 
135
    if (b->generated && a->columns.size() > b->columns.size())
112
136
      std::swap(a, b);                       // Put shorter key in 'a'
113
137
  }
114
138
  else
119
143
  }
120
144
 
121
145
  /* Test if 'a' is a prefix of 'b' */
122
 
  if (a->columns.elements > b->columns.elements)
 
146
  if (a->columns.size() > b->columns.size())
123
147
    return true;                                // Can't be prefix
124
148
 
125
 
  List_iterator<Key_part_spec> col_it1(a->columns);
126
 
  List_iterator<Key_part_spec> col_it2(b->columns);
 
149
  List<Key_part_spec>::iterator col_it1(a->columns.begin());
 
150
  List<Key_part_spec>::iterator col_it2(b->columns.begin());
127
151
  const Key_part_spec *col1, *col2;
128
152
 
129
153
#ifdef ENABLE_WHEN_INNODB_CAN_HANDLE_SWAPED_FOREIGN_KEY_COLUMNS
130
154
  while ((col1= col_it1++))
131
155
  {
132
156
    bool found= 0;
133
 
    col_it2.rewind();
 
157
    col_it2=b->columns.begin();
134
158
    while ((col2= col_it2++))
135
159
    {
136
160
      if (*col1 == *col2)
166
190
{
167
191
  CreateField  *sql_field;
168
192
  Key_part_spec *column;
169
 
  List_iterator<Key_part_spec> cols(columns);
170
 
  List_iterator<CreateField> it(table_fields);
 
193
  List<Key_part_spec>::iterator cols(columns.begin());
 
194
  List<CreateField>::iterator it(table_fields.begin());
171
195
  while ((column= cols++))
172
196
  {
173
 
    it.rewind();
 
197
    it= table_fields.begin();
174
198
    while ((sql_field= it++) &&
175
199
           my_strcasecmp(system_charset_info,
176
200
                         column->field_name.str,