Adding a necessary functionality to ::store and ::save_in_field

that will take place properly after pull from 4.0, in order to 
handle conversions from quoted constants to bigint's.
parent fdb3bcc5
This diff is collapsed.
This diff is collapsed.
...@@ -340,7 +340,7 @@ void Item_param::set_long_end() ...@@ -340,7 +340,7 @@ void Item_param::set_long_end()
item_result_type = STRING_RESULT; item_result_type = STRING_RESULT;
}; };
bool Item_param::save_in_field(Field *field) int Item_param::save_in_field(Field *field)
{ {
if (null_value) if (null_value)
return set_field_to_null(field); return set_field_to_null(field);
...@@ -349,20 +349,17 @@ bool Item_param::save_in_field(Field *field) ...@@ -349,20 +349,17 @@ bool Item_param::save_in_field(Field *field)
if (item_result_type == INT_RESULT) if (item_result_type == INT_RESULT)
{ {
longlong nr=val_int(); longlong nr=val_int();
field->store(nr); return (field->store(nr)) ? -1 : 0;
return 0;
} }
if (item_result_type == REAL_RESULT) if (item_result_type == REAL_RESULT)
{ {
double nr=val(); double nr=val();
field->store(nr); return (field->store(nr)) ? -1 : 0;
return 0;
} }
String *result; String *result;
CHARSET_INFO *cs=default_charset_info;//fix this CHARSET_INFO *cs=default_charset_info;//fix this
result=val_str(&str_value); result=val_str(&str_value);
field->store(result->ptr(),result->length(),cs); return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0;
return 0;
} }
void Item_param::make_field(Send_field *tmp_field) void Item_param::make_field(Send_field *tmp_field)
...@@ -615,7 +612,7 @@ void Item_field::save_org_in_field(Field *to) ...@@ -615,7 +612,7 @@ void Item_field::save_org_in_field(Field *to)
} }
} }
bool Item_field::save_in_field(Field *to) int Item_field::save_in_field(Field *to)
{ {
if (result_field->is_null()) if (result_field->is_null())
{ {
...@@ -632,14 +629,15 @@ bool Item_field::save_in_field(Field *to) ...@@ -632,14 +629,15 @@ bool Item_field::save_in_field(Field *to)
} }
bool Item_null::save_in_field(Field *field) int Item_null::save_in_field(Field *field)
{ {
return set_field_to_null(field); return set_field_to_null(field);
} }
bool Item::save_in_field(Field *field) int Item::save_in_field(Field *field)
{ {
int error;
if (result_type() == STRING_RESULT || if (result_type() == STRING_RESULT ||
result_type() == REAL_RESULT && result_type() == REAL_RESULT &&
field->result_type() == STRING_RESULT) field->result_type() == STRING_RESULT)
...@@ -652,7 +650,7 @@ bool Item::save_in_field(Field *field) ...@@ -652,7 +650,7 @@ bool Item::save_in_field(Field *field)
if (null_value) if (null_value)
return set_field_to_null(field); return set_field_to_null(field);
field->set_notnull(); field->set_notnull();
field->store(result->ptr(),result->length(),cs); error=field->store(result->ptr(),result->length(),cs);
str_value.set_quick(0, 0, cs); str_value.set_quick(0, 0, cs);
} }
else if (result_type() == REAL_RESULT) else if (result_type() == REAL_RESULT)
...@@ -661,7 +659,7 @@ bool Item::save_in_field(Field *field) ...@@ -661,7 +659,7 @@ bool Item::save_in_field(Field *field)
if (null_value) if (null_value)
return set_field_to_null(field); return set_field_to_null(field);
field->set_notnull(); field->set_notnull();
field->store(nr); error=field->store(nr);
} }
else else
{ {
...@@ -669,12 +667,12 @@ bool Item::save_in_field(Field *field) ...@@ -669,12 +667,12 @@ bool Item::save_in_field(Field *field)
if (null_value) if (null_value)
return set_field_to_null(field); return set_field_to_null(field);
field->set_notnull(); field->set_notnull();
field->store(nr); error=field->store(nr);
} }
return 0; return (error) ? -1 : 0;
} }
bool Item_string::save_in_field(Field *field) int Item_string::save_in_field(Field *field)
{ {
String *result; String *result;
CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset(); CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset();
...@@ -682,28 +680,25 @@ bool Item_string::save_in_field(Field *field) ...@@ -682,28 +680,25 @@ bool Item_string::save_in_field(Field *field)
if (null_value) if (null_value)
return set_field_to_null(field); return set_field_to_null(field);
field->set_notnull(); field->set_notnull();
field->store(result->ptr(),result->length(),cs); return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0;
return 0;
} }
bool Item_int::save_in_field(Field *field) int Item_int::save_in_field(Field *field)
{ {
longlong nr=val_int(); longlong nr=val_int();
if (null_value) if (null_value)
return set_field_to_null(field); return set_field_to_null(field);
field->set_notnull(); field->set_notnull();
field->store(nr); return (field->store(nr)) ? -1 : 0;
return 0;
} }
bool Item_real::save_in_field(Field *field) int Item_real::save_in_field(Field *field)
{ {
double nr=val(); double nr=val();
if (null_value) if (null_value)
return set_field_to_null(field); return set_field_to_null(field);
field->set_notnull(); field->set_notnull();
field->store(nr); return (field->store(nr)) ? -1 : 0;
return 0;
} }
/**************************************************************************** /****************************************************************************
...@@ -751,20 +746,21 @@ longlong Item_varbinary::val_int() ...@@ -751,20 +746,21 @@ longlong Item_varbinary::val_int()
} }
bool Item_varbinary::save_in_field(Field *field) int Item_varbinary::save_in_field(Field *field)
{ {
int error;
CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset(); CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset();
field->set_notnull(); field->set_notnull();
if (field->result_type() == STRING_RESULT) if (field->result_type() == STRING_RESULT)
{ {
field->store(str_value.ptr(),str_value.length(),cs); error=field->store(str_value.ptr(),str_value.length(),cs);
} }
else else
{ {
longlong nr=val_int(); longlong nr=val_int();
field->store(nr); error=field->store(nr);
} }
return 0; return (error) ? -1 : 0;
} }
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
void set_name(char* str,uint length=0); void set_name(char* str,uint length=0);
void init_make_field(Send_field *tmp_field,enum enum_field_types type); void init_make_field(Send_field *tmp_field,enum enum_field_types type);
virtual bool fix_fields(THD *, struct st_table_list *, Item **); virtual bool fix_fields(THD *, struct st_table_list *, Item **);
virtual bool save_in_field(Field *field); virtual int save_in_field(Field *field);
virtual void save_org_in_field(Field *field) virtual void save_org_in_field(Field *field)
{ (void) save_in_field(field); } { (void) save_in_field(field); }
virtual bool send(THD *thd, String *str); virtual bool send(THD *thd, String *str);
...@@ -124,7 +124,7 @@ public: ...@@ -124,7 +124,7 @@ public:
bool send(THD *thd, String *str_arg) { return result_field->send(thd,str_arg); } bool send(THD *thd, String *str_arg) { return result_field->send(thd,str_arg); }
void make_field(Send_field *field); void make_field(Send_field *field);
bool fix_fields(THD *, struct st_table_list *, Item **); bool fix_fields(THD *, struct st_table_list *, Item **);
bool save_in_field(Field *field); int save_in_field(Field *field);
void save_org_in_field(Field *field); void save_org_in_field(Field *field);
table_map used_tables() const; table_map used_tables() const;
enum Item_result result_type () const enum Item_result result_type () const
...@@ -149,7 +149,7 @@ public: ...@@ -149,7 +149,7 @@ public:
longlong val_int(); longlong val_int();
String *val_str(String *str); String *val_str(String *str);
void make_field(Send_field *field); void make_field(Send_field *field);
bool save_in_field(Field *field); int save_in_field(Field *field);
enum Item_result result_type () const enum Item_result result_type () const
{ return STRING_RESULT; } { return STRING_RESULT; }
bool send(THD *thd, String *str); bool send(THD *thd, String *str);
...@@ -178,7 +178,7 @@ public: ...@@ -178,7 +178,7 @@ public:
longlong val_int(); longlong val_int();
String *val_str(String*); String *val_str(String*);
void make_field(Send_field *field); void make_field(Send_field *field);
bool save_in_field(Field *field); int save_in_field(Field *field);
void set_null(); void set_null();
void set_int(longlong i); void set_int(longlong i);
void set_double(float i); void set_double(float i);
...@@ -215,7 +215,7 @@ public: ...@@ -215,7 +215,7 @@ public:
double val() { return (double) value; } double val() { return (double) value; }
String *val_str(String*); String *val_str(String*);
void make_field(Send_field *field); void make_field(Send_field *field);
bool save_in_field(Field *field); int save_in_field(Field *field);
bool basic_const_item() const { return 1; } bool basic_const_item() const { return 1; }
Item *new_item() { return new Item_int(name,value,max_length); } Item *new_item() { return new Item_int(name,value,max_length); }
void print(String *str); void print(String *str);
...@@ -254,7 +254,7 @@ public: ...@@ -254,7 +254,7 @@ public:
max_length=length; max_length=length;
} }
Item_real(double value_par) :value(value_par) {} Item_real(double value_par) :value(value_par) {}
bool save_in_field(Field *field); int save_in_field(Field *field);
enum Type type() const { return REAL_ITEM; } enum Type type() const { return REAL_ITEM; }
double val() { return value; } double val() { return value; }
longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5));} longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5));}
...@@ -297,7 +297,7 @@ public: ...@@ -297,7 +297,7 @@ public:
double val() { return atof(str_value.ptr()); } double val() { return atof(str_value.ptr()); }
longlong val_int() { return strtoll(str_value.ptr(),(char**) 0,10); } longlong val_int() { return strtoll(str_value.ptr(),(char**) 0,10); }
String *val_str(String*) { return (String*) &str_value; } String *val_str(String*) { return (String*) &str_value; }
bool save_in_field(Field *field); int save_in_field(Field *field);
void make_field(Send_field *field); void make_field(Send_field *field);
enum Item_result result_type () const { return STRING_RESULT; } enum Item_result result_type () const { return STRING_RESULT; }
bool basic_const_item() const { return 1; } bool basic_const_item() const { return 1; }
...@@ -334,7 +334,7 @@ public: ...@@ -334,7 +334,7 @@ public:
double val() { return (double) Item_varbinary::val_int(); } double val() { return (double) Item_varbinary::val_int(); }
longlong val_int(); longlong val_int();
String *val_str(String*) { return &str_value; } String *val_str(String*) { return &str_value; }
bool save_in_field(Field *field); int save_in_field(Field *field);
void make_field(Send_field *field); void make_field(Send_field *field);
enum Item_result result_type () const { return INT_RESULT; } enum Item_result result_type () const { return INT_RESULT; }
}; };
...@@ -394,7 +394,7 @@ public: ...@@ -394,7 +394,7 @@ public:
bool send(THD *thd, String *tmp) { return (*ref)->send(thd, tmp); } bool send(THD *thd, String *tmp) { return (*ref)->send(thd, tmp); }
void make_field(Send_field *field) { (*ref)->make_field(field); } void make_field(Send_field *field) { (*ref)->make_field(field); }
bool fix_fields(THD *, struct st_table_list *, Item **); bool fix_fields(THD *, struct st_table_list *, Item **);
bool save_in_field(Field *field) { return (*ref)->save_in_field(field); } int save_in_field(Field *field) { return (*ref)->save_in_field(field); }
void save_org_in_field(Field *field) { (*ref)->save_org_in_field(field); } void save_org_in_field(Field *field) { (*ref)->save_org_in_field(field); }
enum Item_result result_type () const { return (*ref)->result_type(); } enum Item_result result_type () const { return (*ref)->result_type(); }
table_map used_tables() const { return (*ref)->used_tables(); } table_map used_tables() const { return (*ref)->used_tables(); }
...@@ -413,7 +413,7 @@ class Item_int_with_ref :public Item_int ...@@ -413,7 +413,7 @@ class Item_int_with_ref :public Item_int
public: public:
Item_int_with_ref(longlong i, Item *ref_arg) :Item_int(i), ref(ref_arg) Item_int_with_ref(longlong i, Item *ref_arg) :Item_int(i), ref(ref_arg)
{} {}
bool save_in_field(Field *field) int save_in_field(Field *field)
{ {
return ref->save_in_field(field); return ref->save_in_field(field);
} }
......
...@@ -43,7 +43,8 @@ static bool convert_constant_item(Field *field, Item **item) ...@@ -43,7 +43,8 @@ static bool convert_constant_item(Field *field, Item **item)
{ {
if ((*item)->const_item()) if ((*item)->const_item())
{ {
(*item)->save_in_field(field); if ((*item)->save_in_field(field))
return 0;
if (!((*item)->null_value)) if (!((*item)->null_value))
{ {
Item *tmp=new Item_int_with_ref(field->val_int(), *item); Item *tmp=new Item_int_with_ref(field->val_int(), *item);
......
...@@ -1915,7 +1915,7 @@ outp: ...@@ -1915,7 +1915,7 @@ outp:
} }
bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables) bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables, Item **ref)
{ {
char buff[STACK_BUFF_ALLOC]; // Max argument in function char buff[STACK_BUFF_ALLOC]; // Max argument in function
binary=0; binary=0;
...@@ -1948,7 +1948,7 @@ String *Item_func_set_collation::val_str(String *str) ...@@ -1948,7 +1948,7 @@ String *Item_func_set_collation::val_str(String *str)
return str; return str;
} }
bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables) bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables, Item **ref)
{ {
char buff[STACK_BUFF_ALLOC]; // Max argument in function char buff[STACK_BUFF_ALLOC]; // Max argument in function
binary=0; binary=0;
......
...@@ -489,7 +489,7 @@ class Item_func_conv_charset :public Item_str_func ...@@ -489,7 +489,7 @@ class Item_func_conv_charset :public Item_str_func
public: public:
Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a) Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
{ conv_charset=cs; } { conv_charset=cs; }
bool fix_fields(THD *thd,struct st_table_list *tables); bool fix_fields(THD *thd,struct st_table_list *tables,Item **ref);
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec(); void fix_length_and_dec();
const char *func_name() const { return "conv_charset"; } const char *func_name() const { return "conv_charset"; }
...@@ -501,7 +501,7 @@ class Item_func_set_collation :public Item_str_func ...@@ -501,7 +501,7 @@ class Item_func_set_collation :public Item_str_func
public: public:
Item_func_set_collation(Item *a, CHARSET_INFO *cs) :Item_str_func(a) Item_func_set_collation(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
{ set_collation=cs; } { set_collation=cs; }
bool fix_fields(THD *thd,struct st_table_list *tables); bool fix_fields(THD *thd,struct st_table_list *tables, Item **ref);
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() void fix_length_and_dec()
{ {
......
...@@ -410,7 +410,7 @@ String *Item_date::val_str(String *str) ...@@ -410,7 +410,7 @@ String *Item_date::val_str(String *str)
} }
bool Item_date::save_in_field(Field *field) int Item_date::save_in_field(Field *field)
{ {
TIME ltime; TIME ltime;
timestamp_type t_type=TIMESTAMP_FULL; timestamp_type t_type=TIMESTAMP_FULL;
...@@ -525,7 +525,7 @@ bool Item_func_now::get_date(TIME *res, ...@@ -525,7 +525,7 @@ bool Item_func_now::get_date(TIME *res,
} }
bool Item_func_now::save_in_field(Field *to) int Item_func_now::save_in_field(Field *to)
{ {
to->set_notnull(); to->set_notnull();
to->store_time(&ltime,TIMESTAMP_FULL); to->store_time(&ltime,TIMESTAMP_FULL);
......
...@@ -228,7 +228,7 @@ public: ...@@ -228,7 +228,7 @@ public:
double val() { return (double) val_int(); } double val() { return (double) val_int(); }
const char *func_name() const { return "date"; } const char *func_name() const { return "date"; }
void fix_length_and_dec() { decimals=0; max_length=10; } void fix_length_and_dec() { decimals=0; max_length=10; }
bool save_in_field(Field *to); int save_in_field(Field *to);
void make_field(Send_field *tmp_field) void make_field(Send_field *tmp_field)
{ {
init_make_field(tmp_field,FIELD_TYPE_DATE); init_make_field(tmp_field,FIELD_TYPE_DATE);
...@@ -311,7 +311,7 @@ public: ...@@ -311,7 +311,7 @@ public:
enum Item_result result_type () const { return STRING_RESULT; } enum Item_result result_type () const { return STRING_RESULT; }
double val() { return (double) value; } double val() { return (double) value; }
longlong val_int() { return value; } longlong val_int() { return value; }
bool save_in_field(Field *to); int save_in_field(Field *to);
String *val_str(String *str) String *val_str(String *str)
{ str_value.set(buff,buff_length,default_charset_info); return &str_value; } { str_value.set(buff,buff_length,default_charset_info); return &str_value; }
const char *func_name() const { return "now"; } const char *func_name() const { return "now"; }
......
...@@ -1028,7 +1028,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part, ...@@ -1028,7 +1028,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
field->cmp_type() != value->result_type()) field->cmp_type() != value->result_type())
DBUG_RETURN(0); DBUG_RETURN(0);
if (value->save_in_field(field)) if (value->save_in_field(field) == 1)
{ {
if (type == Item_func::EQUAL_FUNC) if (type == Item_func::EQUAL_FUNC)
{ {
......
...@@ -2113,7 +2113,7 @@ fill_record(List<Item> &fields,List<Item> &values) ...@@ -2113,7 +2113,7 @@ fill_record(List<Item> &fields,List<Item> &values)
while ((field=(Item_field*) f++)) while ((field=(Item_field*) f++))
{ {
value=v++; value=v++;
if (value->save_in_field(field->field)) if (value->save_in_field(field->field) == 1)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -2131,7 +2131,7 @@ fill_record(Field **ptr,List<Item> &values) ...@@ -2131,7 +2131,7 @@ fill_record(Field **ptr,List<Item> &values)
while ((field = *ptr++)) while ((field = *ptr++))
{ {
value=v++; value=v++;
if (value->save_in_field(field)) if (value->save_in_field(field) == 1)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
......
...@@ -179,7 +179,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -179,7 +179,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
Item *item; Item *item;
for (key_len=0 ; (item=it_ke++) ; key_part++) for (key_len=0 ; (item=it_ke++) ; key_part++)
{ {
item->save_in_field(key_part->field); (void) item->save_in_field(key_part->field);
key_len+=key_part->store_length; key_len+=key_part->store_length;
} }
if (!(key= (byte*) sql_calloc(ALIGN_SIZE(key_len)))) if (!(key= (byte*) sql_calloc(ALIGN_SIZE(key_len))))
......
...@@ -2478,7 +2478,7 @@ store_val_in_field(Field *field,Item *item) ...@@ -2478,7 +2478,7 @@ store_val_in_field(Field *field,Item *item)
THD *thd=current_thd; THD *thd=current_thd;
ulong cuted_fields=thd->cuted_fields; ulong cuted_fields=thd->cuted_fields;
thd->count_cuted_fields=1; thd->count_cuted_fields=1;
item->save_in_field(field); (void) item->save_in_field(field);
thd->count_cuted_fields=0; thd->count_cuted_fields=0;
return cuted_fields != thd->cuted_fields; return cuted_fields != thd->cuted_fields;
} }
......
...@@ -338,7 +338,7 @@ public: ...@@ -338,7 +338,7 @@ public:
{} {}
bool copy() bool copy()
{ {
item->save_in_field(to_field); (void) item->save_in_field(to_field);
return err != 0; return err != 0;
} }
const char *name() const { return "func"; } const char *name() const { return "func"; }
...@@ -362,7 +362,7 @@ public: ...@@ -362,7 +362,7 @@ public:
if (!inited) if (!inited)
{ {
inited=1; inited=1;
item->save_in_field(to_field); (void)item->save_in_field(to_field);
} }
return err != 0; return err != 0;
} }
......
...@@ -590,7 +590,7 @@ static bool make_empty_rec(File file,enum db_type table_type, ...@@ -590,7 +590,7 @@ static bool make_empty_rec(File file,enum db_type table_type,
if (field->def && if (field->def &&
(regfield->real_type() != FIELD_TYPE_YEAR || (regfield->real_type() != FIELD_TYPE_YEAR ||
field->def->val_int() != 0)) field->def->val_int() != 0))
field->def->save_in_field(regfield); (void) field->def->save_in_field(regfield);
else if (regfield->real_type() == FIELD_TYPE_ENUM && else if (regfield->real_type() == FIELD_TYPE_ENUM &&
(field->flags & NOT_NULL_FLAG)) (field->flags & NOT_NULL_FLAG))
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment