91
* 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,
93
* we always throw an error.
95
int Field_enum::store(const char *from, uint32_t length, const CHARSET_INFO * const)
83
Storing a empty string in a enum field gives a warning
84
(if there isn't a empty value in the enum)
87
int Field_enum::store(const char *from, uint32_t length, const CHARSET_INFO * const cs)
91
char buff[STRING_BUFFER_USUAL_SIZE];
92
String tmpstr(buff,sizeof(buff), &my_charset_bin);
99
ASSERT_COLUMN_MARKED_FOR_WRITE;
94
/* Convert character set if necessary */
95
if (String::needs_conversion(length, cs, field_charset, ¬_used))
97
uint32_t dummy_errors;
98
tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
100
length= tmpstr.length();
101
103
/* Remove end space */
102
104
length= field_charset->cset->lengthsp(field_charset, from, length);
103
tmp= find_type2(typelib, from, length, field_charset);
105
uint32_t tmp=find_type2(typelib, from, length, field_charset);
106
if (length < 6) /* Can't be more than 99999 enums */
108
if (length < 6) // Can't be more than 99999 enums
108
110
/* This is for reading numbers with LOAD DATA INFILE */
109
/* Convert the string to an integer using stringstream */
110
std::stringstream ss;
114
if (tmp == 0 || tmp > typelib->count)
112
tmp=(uint) my_strntoul(cs,from,length,10,&end,&err);
113
if (err || end != from+length || tmp > typelib->count)
116
my_error(ER_INVALID_ENUM_VALUE, MYF(ME_FATALERROR), from);
116
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
118
if (!table->in_use->count_cuted_fields)
122
my_error(ER_INVALID_ENUM_VALUE, MYF(ME_FATALERROR), from);
122
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
126
124
store_type((uint64_t) tmp);
130
int Field_enum::store(double from)
132
return Field_enum::store((int64_t) from, false);
136
* @note MySQL allows 0 values, saying that 0 is "the index of the
137
* blank string error", whatever that means. Uhm, Drizzle doesn't
138
* 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
142
int Field_enum::store(int64_t from, bool)
144
ASSERT_COLUMN_MARKED_FOR_WRITE;
146
if (from <= 0 || (uint64_t) from > typelib->count)
129
int Field_enum::store(double nr)
131
return Field_enum::store((int64_t) nr, false);
135
int Field_enum::store(int64_t nr,
136
bool unsigned_val __attribute__((unused)))
139
if ((uint64_t) nr > typelib->count || nr == 0)
148
/* Convert the integer to a string using stringstream */
149
std::stringstream ss;
151
ss << from; ss >> tmp;
153
my_error(ER_INVALID_ENUM_VALUE, MYF(ME_FATALERROR), tmp.c_str());
141
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
142
if (nr != 0 || table->in_use->count_cuted_fields)
156
store_type((uint64_t) (uint32_t) from);
148
store_type((uint64_t) (uint) nr);
160
153
double Field_enum::val_real(void)
162
155
return (double) Field_enum::val_int();
165
159
int64_t Field_enum::val_int(void)
167
ASSERT_COLUMN_MARKED_FOR_READ;
169
161
switch (packlength) {
171
163
return (int64_t) ptr[0];
208
200
return 0; // impossible
211
String *Field_enum::val_str(String *, String *val_ptr)
213
uint32_t tmp=(uint32_t) Field_enum::val_int();
215
ASSERT_COLUMN_MARKED_FOR_READ;
205
Save the field metadata for enum fields.
207
Saves the real type in the first byte and the pack length in the
208
second byte of the field metadata array at index of *metadata_ptr and
211
@param metadata_ptr First byte of field metadata
213
@returns number of bytes written to metadata_ptr
215
int Field_enum::do_save_field_metadata(unsigned char *metadata_ptr)
217
*metadata_ptr= real_type();
218
*(metadata_ptr + 1)= pack_length();
223
String *Field_enum::val_str(String *val_buffer __attribute__((unused)),
226
uint32_t tmp=(uint) Field_enum::val_int();
217
227
if (!tmp || tmp > typelib->count)
218
228
val_ptr->set("", 0, field_charset);
263
274
/* convert to res.charset() == utf8, then quote */
264
275
enum_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
265
append_unescaped(&res, enum_item.c_ptr(), enum_item.length());
276
append_unescaped(&res, enum_item.ptr(), enum_item.length());
271
Field *Field_enum::new_field(memory::Root *root, Table *new_table,
283
Field *Field_enum::new_field(MEM_ROOT *root, Table *new_table,
274
286
Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);