38
38
** If one uses this string in a number context one gets the type number.
39
39
****************************************************************************/
41
enum ha_base_keytype Field_enum::key_type() const
45
default: return HA_KEYTYPE_BINARY;
48
case 4: return HA_KEYTYPE_ULONG_INT;
49
case 8: return HA_KEYTYPE_ULONGLONG;
53
41
void Field_enum::store_type(uint64_t value)
56
case 1: ptr[0]= (unsigned char) value; break;
58
#ifdef WORDS_BIGENDIAN
59
if (table->s->db_low_byte_first)
61
int2store(ptr,(unsigned short) value);
65
shortstore(ptr,(unsigned short) value);
67
case 3: int3store(ptr,(long) value); break;
69
#ifdef WORDS_BIGENDIAN
70
if (table->s->db_low_byte_first)
76
longstore(ptr,(long) value);
79
#ifdef WORDS_BIGENDIAN
80
if (table->s->db_low_byte_first)
86
int64_tstore(ptr,value); break;
43
value--; /* we store as starting from 0, although SQL starts from 1 */
45
#ifdef WORDS_BIGENDIAN
46
if (getTable()->s->db_low_byte_first)
48
int4store(ptr, (unsigned short) value);
52
longstore(ptr, (unsigned short) value);
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.
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
142
107
int Field_enum::store(int64_t from, bool)
167
132
ASSERT_COLUMN_MARKED_FOR_READ;
169
switch (packlength) {
171
return (int64_t) ptr[0];
175
#ifdef WORDS_BIGENDIAN
176
if (table->s->db_low_byte_first)
181
return (int64_t) tmp;
184
return (int64_t) uint3korr(ptr);
188
#ifdef WORDS_BIGENDIAN
189
if (table->s->db_low_byte_first)
194
return (int64_t) tmp;
199
#ifdef WORDS_BIGENDIAN
200
if (table->s->db_low_byte_first)
208
return 0; // impossible
135
#ifdef WORDS_BIGENDIAN
136
if (getTable()->s->db_low_byte_first)
141
return ((int64_t) tmp) + 1; /* SQL is from 1, we store from 0 */
211
144
String *Field_enum::val_str(String *, String *val_ptr)
215
148
ASSERT_COLUMN_MARKED_FOR_READ;
217
150
if (!tmp || tmp > typelib->count)
218
152
val_ptr->set("", 0, field_charset);
220
val_ptr->set((const char*) typelib->type_names[tmp-1],
221
typelib->type_lengths[tmp-1],
156
val_ptr->set((const char*) typelib->type_names[tmp-1], typelib->type_lengths[tmp-1], field_charset);
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();
234
170
return (a < b) ? -1 : (a > b) ? 1 : 0;
237
173
void Field_enum::sort_string(unsigned char *to,uint32_t )
239
uint64_t value=Field_enum::val_int();
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++)
243
179
*to-- = (unsigned char) (value & 255);