~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/field/enum.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
** If one uses this string in a number context one gets the type number.
39
39
****************************************************************************/
40
40
 
41
 
enum ha_base_keytype Field_enum::key_type() const
42
 
{
43
 
  switch (packlength) 
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;
50
 
  }
51
 
}
52
 
 
53
41
void Field_enum::store_type(uint64_t value)
54
42
{
55
 
  switch (packlength) {
56
 
  case 1: ptr[0]= (unsigned char) value;  break;
57
 
  case 2:
58
 
#ifdef WORDS_BIGENDIAN
59
 
  if (table->s->db_low_byte_first)
60
 
  {
61
 
    int2store(ptr,(unsigned short) value);
62
 
  }
63
 
  else
64
 
#endif
65
 
    shortstore(ptr,(unsigned short) value);
66
 
  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;
87
 
  }
 
43
  value--; /* we store as starting from 0, although SQL starts from 1 */
 
44
 
 
45
#ifdef WORDS_BIGENDIAN
 
46
  if (getTable()->s->db_low_byte_first)
 
47
  {
 
48
    int4store(ptr, (unsigned short) value);
 
49
  }
 
50
  else
 
51
#endif
 
52
    longstore(ptr, (unsigned short) value);
88
53
}
89
54
 
90
55
/**
91
56
 * 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, 
 
57
 * and stores the found key.  Upon not finding an entry in the typelib,
93
58
 * we always throw an error.
94
59
 */
95
60
int Field_enum::store(const char *from, uint32_t length, const CHARSET_INFO * const)
136
101
 * @note MySQL allows 0 values, saying that 0 is "the index of the
137
102
 * blank string error", whatever that means.  Uhm, Drizzle doesn't
138
103
 * 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 
 
104
 * must specify the 1-based index of the enum column definition's
140
105
 * key.
141
106
 */
142
107
int Field_enum::store(int64_t from, bool)
166
131
{
167
132
  ASSERT_COLUMN_MARKED_FOR_READ;
168
133
 
169
 
  switch (packlength) {
170
 
  case 1:
171
 
    return (int64_t) ptr[0];
172
 
  case 2:
173
 
  {
174
 
    uint16_t tmp;
175
 
#ifdef WORDS_BIGENDIAN
176
 
    if (table->s->db_low_byte_first)
177
 
      tmp=sint2korr(ptr);
178
 
    else
179
 
#endif
180
 
      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
 
  }
207
 
  }
208
 
  return 0;                                     // impossible
 
134
  uint16_t tmp;
 
135
#ifdef WORDS_BIGENDIAN
 
136
  if (getTable()->s->db_low_byte_first)
 
137
    tmp= sint4korr(ptr);
 
138
  else
 
139
#endif
 
140
    longget(tmp,ptr);
 
141
  return ((int64_t) tmp) + 1; /* SQL is from 1, we store from 0 */
209
142
}
210
143
 
211
144
String *Field_enum::val_str(String *, String *val_ptr)
215
148
  ASSERT_COLUMN_MARKED_FOR_READ;
216
149
 
217
150
  if (!tmp || tmp > typelib->count)
 
151
  {
218
152
    val_ptr->set("", 0, field_charset);
 
153
  }
219
154
  else
220
 
    val_ptr->set((const char*) typelib->type_names[tmp-1],
221
 
                 typelib->type_lengths[tmp-1],
222
 
                 field_charset);
 
155
  {
 
156
    val_ptr->set((const char*) typelib->type_names[tmp-1], typelib->type_lengths[tmp-1], field_charset);
 
157
  }
 
158
 
223
159
  return val_ptr;
224
160
}
225
161
 
227
163
{
228
164
  unsigned char *old= ptr;
229
165
  ptr= (unsigned char*) a_ptr;
230
 
  uint64_t a=Field_enum::val_int();
 
166
  uint64_t a= Field_enum::val_int();
231
167
  ptr= (unsigned char*) b_ptr;
232
 
  uint64_t b=Field_enum::val_int();
 
168
  uint64_t b= Field_enum::val_int();
233
169
  ptr= old;
234
170
  return (a < b) ? -1 : (a > b) ? 1 : 0;
235
171
}
236
172
 
237
173
void Field_enum::sort_string(unsigned char *to,uint32_t )
238
174
{
239
 
  uint64_t value=Field_enum::val_int();
240
 
  to+=packlength-1;
241
 
  for (uint32_t i=0 ; i < packlength ; i++)
 
175
  uint64_t value=Field_enum::val_int()-1; /* SQL is 1 based, stored as 0 based*/
 
176
  to+=pack_length() -1;
 
177
  for (uint32_t i=0 ; i < pack_length() ; i++)
242
178
  {
243
179
    *to-- = (unsigned char) (value & 255);
244
180
    value>>=8;
273
209
{
274
210
  Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);
275
211
  if (res)
 
212
  {
276
213
    res->typelib= copy_typelib(root, typelib);
 
214
  }
277
215
  return res;
278
216
}
279
217