~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/enum.cc

Remove dead memset call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
enum ha_base_keytype Field_enum::key_type() const
42
42
{
43
 
  switch (packlength) 
 
43
  switch (packlength)
44
44
  {
45
 
    default: return HA_KEYTYPE_BINARY;
46
 
    case 2: assert(1);
47
 
    case 3: assert(1);
48
 
    case 4: return HA_KEYTYPE_ULONG_INT;
49
 
    case 8: return HA_KEYTYPE_ULONGLONG;
 
45
  case 1:
 
46
    return HA_KEYTYPE_BINARY;
 
47
  case 2:
 
48
    return HA_KEYTYPE_ULONG_INT;
 
49
  default:
 
50
    assert(packlength <= 2);
 
51
    return HA_KEYTYPE_ULONG_INT;
50
52
  }
51
53
}
52
54
 
53
55
void Field_enum::store_type(uint64_t value)
54
56
{
 
57
  value--; /* we store as starting from 0, although SQL starts from 1 */
 
58
 
55
59
  switch (packlength) {
56
60
  case 1: ptr[0]= (unsigned char) value;  break;
57
61
  case 2:
58
62
#ifdef WORDS_BIGENDIAN
59
 
  if (table->s->db_low_byte_first)
 
63
  if (getTable()->s->db_low_byte_first)
60
64
  {
61
65
    int2store(ptr,(unsigned short) value);
62
66
  }
64
68
#endif
65
69
    shortstore(ptr,(unsigned short) value);
66
70
  break;
67
 
  case 3: int3store(ptr,(long) value); break;
68
 
  case 4:
69
 
#ifdef WORDS_BIGENDIAN
70
 
  if (table->s->db_low_byte_first)
71
 
  {
72
 
    int4store(ptr,value);
73
 
  }
74
 
  else
75
 
#endif
76
 
    longstore(ptr,(long) value);
77
 
  break;
78
 
  case 8:
79
 
#ifdef WORDS_BIGENDIAN
80
 
  if (table->s->db_low_byte_first)
81
 
  {
82
 
    int8store(ptr,value);
83
 
  }
84
 
  else
85
 
#endif
86
 
    int64_tstore(ptr,value); break;
 
71
  default:
 
72
    assert(packlength <= 2);
87
73
  }
88
74
}
89
75
 
90
76
/**
91
77
 * Given a supplied string, looks up the string in the internal typelib
92
 
 * and stores the found key.  Upon not finding an entry in the typelib, 
 
78
 * and stores the found key.  Upon not finding an entry in the typelib,
93
79
 * we always throw an error.
94
80
 */
95
81
int Field_enum::store(const char *from, uint32_t length, const CHARSET_INFO * const)
136
122
 * @note MySQL allows 0 values, saying that 0 is "the index of the
137
123
 * blank string error", whatever that means.  Uhm, Drizzle doesn't
138
124
 * allow this.  To store an ENUM column value using an integer, you
139
 
 * must specify the 1-based index of the enum column definition's 
 
125
 * must specify the 1-based index of the enum column definition's
140
126
 * key.
141
127
 */
142
128
int Field_enum::store(int64_t from, bool)
168
154
 
169
155
  switch (packlength) {
170
156
  case 1:
171
 
    return (int64_t) ptr[0];
 
157
    return ((int64_t) ptr[0]) + 1; /* SQL is from 1, we store from 0 */
172
158
  case 2:
173
159
  {
174
160
    uint16_t tmp;
175
161
#ifdef WORDS_BIGENDIAN
176
 
    if (table->s->db_low_byte_first)
 
162
    if (getTable()->s->db_low_byte_first)
177
163
      tmp=sint2korr(ptr);
178
164
    else
179
165
#endif
180
166
      shortget(tmp,ptr);
181
 
    return (int64_t) tmp;
182
 
  }
183
 
  case 3:
184
 
    return (int64_t) uint3korr(ptr);
185
 
  case 4:
186
 
  {
187
 
    uint32_t tmp;
188
 
#ifdef WORDS_BIGENDIAN
189
 
    if (table->s->db_low_byte_first)
190
 
      tmp=uint4korr(ptr);
191
 
    else
192
 
#endif
193
 
      longget(tmp,ptr);
194
 
    return (int64_t) tmp;
195
 
  }
196
 
  case 8:
197
 
  {
198
 
    int64_t tmp;
199
 
#ifdef WORDS_BIGENDIAN
200
 
    if (table->s->db_low_byte_first)
201
 
      tmp=sint8korr(ptr);
202
 
    else
203
 
#endif
204
 
      int64_tget(tmp,ptr);
205
 
    return tmp;
206
 
  }
 
167
    return ((int64_t) tmp) + 1; /* SQL is from 1, we store from 0 */
 
168
  }
 
169
  default:
 
170
    assert(packlength <= 2);
207
171
  }
208
172
  return 0;                                     // impossible
209
173
}
215
179
  ASSERT_COLUMN_MARKED_FOR_READ;
216
180
 
217
181
  if (!tmp || tmp > typelib->count)
 
182
  {
218
183
    val_ptr->set("", 0, field_charset);
 
184
  }
219
185
  else
220
 
    val_ptr->set((const char*) typelib->type_names[tmp-1],
221
 
                 typelib->type_lengths[tmp-1],
222
 
                 field_charset);
 
186
  {
 
187
    val_ptr->set((const char*) typelib->type_names[tmp-1], typelib->type_lengths[tmp-1], field_charset);
 
188
  }
 
189
 
223
190
  return val_ptr;
224
191
}
225
192
 
236
203
 
237
204
void Field_enum::sort_string(unsigned char *to,uint32_t )
238
205
{
239
 
  uint64_t value=Field_enum::val_int();
 
206
  uint64_t value=Field_enum::val_int()-1; /* SQL is 1 based, stored as 0 based*/
240
207
  to+=packlength-1;
241
208
  for (uint32_t i=0 ; i < packlength ; i++)
242
209
  {
273
240
{
274
241
  Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);
275
242
  if (res)
 
243
  {
276
244
    res->typelib= copy_typelib(root, typelib);
 
245
  }
277
246
  return res;
278
247
}
279
248