~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/dtcollation.cc

Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <drizzled/session.h>
29
29
 
30
30
 
31
 
static bool
32
 
left_is_superset(const DTCollation &left, const DTCollation &right)
33
 
{
34
 
  /* Allow convert to Unicode */
35
 
  if (left.collation->state & MY_CS_UNICODE &&
36
 
      (left.derivation < right.derivation ||
37
 
       (left.derivation == right.derivation &&
38
 
        !(right.collation->state & MY_CS_UNICODE))))
39
 
    return true;
40
 
  /* Allow convert from ASCII */
41
 
  if (right.repertoire == MY_REPERTOIRE_ASCII &&
42
 
      (left.derivation < right.derivation ||
43
 
       (left.derivation == right.derivation &&
44
 
        !(left.repertoire == MY_REPERTOIRE_ASCII))))
45
 
    return true;
46
 
  /* Disallow conversion otherwise */
47
 
  return false;
48
 
}
49
 
 
50
 
 
51
31
DTCollation::DTCollation()
52
32
{
53
33
  collation= &my_charset_bin;
54
34
  derivation= DERIVATION_NONE;
55
 
  repertoire= MY_REPERTOIRE_UNICODE30;
56
35
}
57
36
 
58
37
 
61
40
{
62
41
  collation= collation_arg;
63
42
  derivation= derivation_arg;
64
 
  set_repertoire_from_charset(collation_arg);
65
 
}
66
 
void DTCollation::set_repertoire_from_charset(const CHARSET_INFO * const cs)
67
 
{
68
 
  repertoire= cs->state & MY_CS_PUREASCII ?
69
 
    MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
70
43
}
71
44
 
72
45
 
74
47
{
75
48
  collation= dt.collation;
76
49
  derivation= dt.derivation;
77
 
  repertoire= dt.repertoire;
78
50
}
79
51
 
80
52
 
83
55
{
84
56
  collation= collation_arg;
85
57
  derivation= derivation_arg;
86
 
  set_repertoire_from_charset(collation_arg);
87
 
}
88
 
 
89
 
 
90
 
void DTCollation::set(const CHARSET_INFO * const collation_arg,
91
 
                      Derivation derivation_arg,
92
 
                      uint32_t repertoire_arg)
93
 
{
94
 
  collation= collation_arg;
95
 
  derivation= derivation_arg;
96
 
  repertoire= repertoire_arg;
97
58
}
98
59
 
99
60
 
100
61
void DTCollation::set(const CHARSET_INFO * const collation_arg)
101
62
{
102
63
  collation= collation_arg;
103
 
  set_repertoire_from_charset(collation_arg);
104
64
}
105
65
 
106
66
 
141
101
      }
142
102
    }
143
103
    else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
144
 
             left_is_superset(*this, dt))
 
104
             collation->state & MY_CS_UNICODE &&
 
105
             (derivation < dt.derivation ||
 
106
              (derivation == dt.derivation &&
 
107
               !(dt.collation->state & MY_CS_UNICODE))))
145
108
    {
146
109
      // Do nothing
147
110
    }
148
111
    else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
149
 
             left_is_superset(dt, *this))
 
112
             dt.collation->state & MY_CS_UNICODE &&
 
113
             (dt.derivation < derivation ||
 
114
              (dt.derivation == derivation &&
 
115
               !(collation->state & MY_CS_UNICODE))))
150
116
    {
151
117
      set(dt);
152
118
    }
165
131
    else
166
132
    {
167
133
      // Cannot apply conversion
168
 
      set(0, DERIVATION_NONE, 0);
169
 
      return 1;
 
134
      set(0, DERIVATION_NONE);
 
135
      return true;
170
136
    }
171
137
  }
172
138
  else if (derivation < dt.derivation)
187
153
    {
188
154
      if (derivation == DERIVATION_EXPLICIT)
189
155
      {
190
 
        set(0, DERIVATION_NONE, 0);
191
 
        return 1;
 
156
        set(0, DERIVATION_NONE);
 
157
        return true;
192
158
      }
193
159
      if (collation->state & MY_CS_BINSORT)
194
 
        return 0;
 
160
        return false;
195
161
      if (dt.collation->state & MY_CS_BINSORT)
196
162
      {
197
163
        set(dt);
198
 
        return 0;
 
164
        return false;
199
165
      }
200
166
      const CHARSET_INFO * const bin= get_charset_by_csname(collation->csname, MY_CS_BINSORT);
201
167
      set(bin, DERIVATION_NONE);
202
168
    }
203
169
  }
204
 
  repertoire|= dt.repertoire;
205
 
  return 0;
 
170
 
 
171
  return false;
206
172
}
207
173
 
208
174
 
296
262
                                  &dummy_offset))
297
263
      continue;
298
264
 
299
 
    if (!(conv= (*arg)->safe_charset_converter(coll.collation)) &&
300
 
        ((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII))
301
 
      conv= new Item_func_conv_charset(*arg, coll.collation, 1);
302
 
 
303
 
    if (!conv)
 
265
    if (!(conv= (*arg)->safe_charset_converter(coll.collation)))
304
266
    {
305
267
      if (nargs >=2 && nargs <= 3)
306
268
      {