85
Storing a empty string in a enum field gives a warning
86
(if there isn't a empty value in the enum)
89
int Field_enum::store(const char *from, uint32_t length, const CHARSET_INFO * const cs)
87
* Given a supplied string, looks up the string in the internal typelib
88
* and stores the found key. Upon not finding an entry in the typelib,
89
* we always throw an error.
91
int Field_enum::store(const char *from, uint32_t length, const CHARSET_INFO * const)
93
char buff[STRING_BUFFER_USUAL_SIZE];
94
String tmpstr(buff,sizeof(buff), &my_charset_bin);
96
/* Convert character set if necessary */
97
if (String::needs_conversion(length, cs, field_charset, ¬_used))
99
uint32_t dummy_errors;
100
tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
102
length= tmpstr.length();
105
95
/* Remove end space */
106
96
length= field_charset->cset->lengthsp(field_charset, from, length);
107
uint32_t tmp=find_type2(typelib, from, length, field_charset);
97
tmp= find_type2(typelib, from, length, field_charset);
110
if (length < 6) // Can't be more than 99999 enums
100
if (length < 6) /* Can't be more than 99999 enums */
112
102
/* This is for reading numbers with LOAD DATA INFILE */
114
tmp=(uint32_t) my_strntoul(cs,from,length,10,&end,&err);
115
if (err || end != from+length || tmp > typelib->count)
103
/* Convert the string to an integer using stringstream */
104
std::stringstream ss;
108
if (tmp == 0 || tmp > typelib->count)
118
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
110
my_error(ER_INVALID_ENUM_VALUE, MYF(ME_FATALERROR), from);
120
if (!table->in_use->count_cuted_fields)
124
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
116
my_error(ER_INVALID_ENUM_VALUE, MYF(ME_FATALERROR), from);
126
120
store_type((uint64_t) tmp);
131
int Field_enum::store(double nr)
133
return Field_enum::store((int64_t) nr, false);
137
int Field_enum::store(int64_t nr,
141
if ((uint64_t) nr > typelib->count || nr == 0)
124
int Field_enum::store(double from)
126
return Field_enum::store((int64_t) from, false);
130
* @note MySQL allows 0 values, saying that 0 is "the index of the
131
* blank string error", whatever that means. Uhm, Drizzle doesn't
132
* allow this. To store an ENUM column value using an integer, you
133
* must specify the 1-based index of the enum column definition's
136
int Field_enum::store(int64_t from, bool)
138
if (from <= 0 || (uint64_t) from > typelib->count)
143
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
144
if (nr != 0 || table->in_use->count_cuted_fields)
140
/* Convert the integer to a string using stringstream */
141
std::stringstream ss;
143
ss << from; ss >> tmp;
145
my_error(ER_INVALID_ENUM_VALUE, MYF(ME_FATALERROR), tmp.c_str());
150
store_type((uint64_t) (uint32_t) nr);
148
store_type((uint64_t) (uint32_t) from);
155
152
double Field_enum::val_real(void)
157
154
return (double) Field_enum::val_int();
161
157
int64_t Field_enum::val_int(void)
163
159
switch (packlength) {