149
static Item* default_value_item(enum_field_types field_type, const charset_info_st& charset, bool default_null,
150
const string& default_value, const string& default_bin_value)
149
static Item *default_value_item(enum_field_types field_type,
150
const charset_info_st *charset,
151
bool default_null, const string *default_value,
152
const string *default_bin_value)
154
Item *default_item= NULL;
152
157
if (default_null)
153
159
return new Item_null();
157
164
case DRIZZLE_TYPE_LONG:
158
165
case DRIZZLE_TYPE_LONGLONG:
166
default_item= new Item_int(default_value->c_str(),
167
(int64_t) internal::my_strtoll10(default_value->c_str(),
170
default_value->length());
172
if (error && error != -1) /* was an error and wasn't a negative number */
161
Item* default_item= new Item_int(default_value.c_str(), (int64_t) internal::my_strtoll10(default_value.c_str(), NULL, &error), default_value.length());
163
if (error && error != -1) /* was an error and wasn't a negative number */
170
179
case DRIZZLE_TYPE_DOUBLE:
171
return new Item_float(default_value.c_str(), default_value.length());
180
default_item= new Item_float(default_value->c_str(),
181
default_value->length());
172
183
case DRIZZLE_TYPE_NULL:
175
186
case DRIZZLE_TYPE_TIMESTAMP:
176
187
case DRIZZLE_TYPE_DATETIME:
181
192
case DRIZZLE_TYPE_IPV6:
182
193
case DRIZZLE_TYPE_MICROTIME:
183
194
case DRIZZLE_TYPE_BOOLEAN:
184
// return new Item_string(*default_value, system_charset_info); // crash
185
return new Item_string(default_value.data(), default_value.size(), system_charset_info);
195
default_item= new Item_string(default_value->c_str(),
196
default_value->length(),
197
system_charset_info);
186
199
case DRIZZLE_TYPE_VARCHAR:
187
200
case DRIZZLE_TYPE_BLOB: /* Blob is here due to TINYTEXT. Feel the hate. */
188
return &charset== &my_charset_bin
189
? new Item_string(default_bin_value, &my_charset_bin)
190
: new Item_string(default_value, system_charset_info);
201
if (charset==&my_charset_bin)
203
default_item= new Item_string(default_bin_value->c_str(),
204
default_bin_value->length(),
209
default_item= new Item_string(default_value->c_str(),
210
default_value->length(),
211
system_charset_info);
191
214
case DRIZZLE_TYPE_DECIMAL:
192
return new Item_decimal(default_value.c_str(), default_value.length(), system_charset_info);
215
default_item= new Item_decimal(default_value->c_str(),
216
default_value->length(),
217
system_charset_info);
699
742
key_part->key_type= 0;
702
if (not indx.has_comment())
745
if (! indx.has_comment())
704
keyinfo->comment.clear();
747
keyinfo->comment.length= 0;
748
keyinfo->comment.str= NULL;
708
752
keyinfo->flags|= HA_USES_COMMENT;
709
keyinfo->comment.assign(mem().strdup(indx.comment()), indx.comment().length());
753
keyinfo->comment.length= indx.comment().length();
754
keyinfo->comment.str= mem().strdup(indx.comment());
712
757
keyinfo->name= mem().strdup(indx.name());
932
977
unireg_type= Field::TIMESTAMP_UN_FIELD;
936
if (pfield.has_comment())
938
comment.assign(mem().strdup(pfield.comment()), pfield.comment().size());
980
lex_string_t comment;
981
if (!pfield.has_comment())
983
comment.str= (char*)"";
988
comment.str= mem().strdup(pfield.comment());
989
comment.length= pfield.comment().size();
941
992
enum_field_types field_type;
945
996
const charset_info_st *charset= &my_charset_bin;
947
if (field_type == DRIZZLE_TYPE_BLOB || field_type == DRIZZLE_TYPE_VARCHAR)
998
if (field_type == DRIZZLE_TYPE_BLOB ||
999
field_type == DRIZZLE_TYPE_VARCHAR)
949
1001
message::Table::Field::StringFieldOptions field_options= pfield.string_options();
951
charset= get_charset(field_options.has_collation_id() ? field_options.collation_id() : 0);
1003
charset= get_charset(field_options.has_collation_id() ?
1004
field_options.collation_id() : 0);
954
1007
charset= default_charset_info;
959
1012
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
961
charset= get_charset(field_options.has_collation_id() ? field_options.collation_id() : 0);
1014
charset= get_charset(field_options.has_collation_id()?
1015
field_options.collation_id() : 0);
964
1018
charset= default_charset_info;
967
1021
uint8_t decimals= 0;
968
if (field_type == DRIZZLE_TYPE_DECIMAL || field_type == DRIZZLE_TYPE_DOUBLE)
1022
if (field_type == DRIZZLE_TYPE_DECIMAL
1023
|| field_type == DRIZZLE_TYPE_DOUBLE)
970
1025
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
972
if (not pfield.has_numeric_options() || ! fo.has_scale())
1027
if (! pfield.has_numeric_options() || ! fo.has_scale())
975
1030
We don't write the default to table proto so
995
1050
pfield.options().default_null() ||
996
1051
pfield.options().has_default_bin_value())
998
default_value= default_value_item(field_type, *charset, pfield.options().default_null(), pfield.options().default_value(), pfield.options().default_bin_value());
1053
default_value= default_value_item(field_type,
1055
pfield.options().default_null(),
1056
&pfield.options().default_value(),
1057
&pfield.options().default_bin_value());
999
1058
if (default_value == NULL)
1001
1060
my_error(ER_INVALID_DEFAULT, MYF(0), pfield.name().c_str());