Commit 7f13b1bd authored by unknown's avatar unknown

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 029dc2b3
This diff is collapsed.
This diff is collapsed.
......@@ -340,7 +340,7 @@ void Item_param::set_long_end()
item_result_type = STRING_RESULT;
};
bool Item_param::save_in_field(Field *field)
int Item_param::save_in_field(Field *field)
{
if (null_value)
return set_field_to_null(field);
......@@ -349,20 +349,17 @@ bool Item_param::save_in_field(Field *field)
if (item_result_type == INT_RESULT)
{
longlong nr=val_int();
field->store(nr);
return 0;
return (field->store(nr)) ? -1 : 0;
}
if (item_result_type == REAL_RESULT)
{
double nr=val();
field->store(nr);
return 0;
return (field->store(nr)) ? -1 : 0;
}
String *result;
CHARSET_INFO *cs=default_charset_info;//fix this
result=val_str(&str_value);
field->store(result->ptr(),result->length(),cs);
return 0;
return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0;
}
void Item_param::make_field(Send_field *tmp_field)
......@@ -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())
{
......@@ -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);
}
bool Item::save_in_field(Field *field)
int Item::save_in_field(Field *field)
{
int error;
if (result_type() == STRING_RESULT ||
result_type() == REAL_RESULT &&
field->result_type() == STRING_RESULT)
......@@ -652,7 +650,7 @@ bool Item::save_in_field(Field *field)
if (null_value)
return set_field_to_null(field);
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);
}
else if (result_type() == REAL_RESULT)
......@@ -661,7 +659,7 @@ bool Item::save_in_field(Field *field)
if (null_value)
return set_field_to_null(field);
field->set_notnull();
field->store(nr);
error=field->store(nr);
}
else
{
......@@ -669,12 +667,12 @@ bool Item::save_in_field(Field *field)
if (null_value)
return set_field_to_null(field);
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;
CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset();
......@@ -682,28 +680,25 @@ bool Item_string::save_in_field(Field *field)
if (null_value)
return set_field_to_null(field);
field->set_notnull();
field->store(result->ptr(),result->length(),cs);
return 0;
return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0;
}
bool Item_int::save_in_field(Field *field)
int Item_int::save_in_field(Field *field)
{
longlong nr=val_int();
if (null_value)
return set_field_to_null(field);
field->set_notnull();
field->store(nr);
return 0;
return (field->store(nr)) ? -1 : 0;
}
bool Item_real::save_in_field(Field *field)
int Item_real::save_in_field(Field *field)
{
double nr=val();
if (null_value)
return set_field_to_null(field);
field->set_notnull();
field->store(nr);
return 0;
return (field->store(nr)) ? -1 : 0;
}
/****************************************************************************
......@@ -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();
field->set_notnull();
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
{
longlong nr=val_int();
field->store(nr);
error=field->store(nr);
}
return 0;
return (error) ? -1 : 0;
}
......
......@@ -53,7 +53,7 @@ class Item {
void set_name(char* str,uint length=0);
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 save_in_field(Field *field);
virtual int save_in_field(Field *field);
virtual void save_org_in_field(Field *field)
{ (void) save_in_field(field); }
virtual bool send(THD *thd, String *str);
......@@ -124,7 +124,7 @@ class Item_field :public Item_ident
bool send(THD *thd, String *str_arg) { return result_field->send(thd,str_arg); }
void make_field(Send_field *field);
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);
table_map used_tables() const;
enum Item_result result_type () const
......@@ -149,7 +149,7 @@ class Item_null :public Item
longlong val_int();
String *val_str(String *str);
void make_field(Send_field *field);
bool save_in_field(Field *field);
int save_in_field(Field *field);
enum Item_result result_type () const
{ return STRING_RESULT; }
bool send(THD *thd, String *str);
......@@ -178,7 +178,7 @@ class Item_param :public Item
longlong val_int();
String *val_str(String*);
void make_field(Send_field *field);
bool save_in_field(Field *field);
int save_in_field(Field *field);
void set_null();
void set_int(longlong i);
void set_double(float i);
......@@ -215,7 +215,7 @@ class Item_int :public Item
double val() { return (double) value; }
String *val_str(String*);
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; }
Item *new_item() { return new Item_int(name,value,max_length); }
void print(String *str);
......@@ -254,7 +254,7 @@ class Item_real :public Item
max_length=length;
}
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; }
double val() { return value; }
longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5));}
......@@ -297,7 +297,7 @@ class Item_string :public Item
double val() { return atof(str_value.ptr()); }
longlong val_int() { return strtoll(str_value.ptr(),(char**) 0,10); }
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);
enum Item_result result_type () const { return STRING_RESULT; }
bool basic_const_item() const { return 1; }
......@@ -334,7 +334,7 @@ class Item_varbinary :public Item
double val() { return (double) Item_varbinary::val_int(); }
longlong val_int();
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);
enum Item_result result_type () const { return INT_RESULT; }
};
......@@ -394,7 +394,7 @@ class Item_ref :public Item_ident
bool send(THD *thd, String *tmp) { return (*ref)->send(thd, tmp); }
void make_field(Send_field *field) { (*ref)->make_field(field); }
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); }
enum Item_result result_type () const { return (*ref)->result_type(); }
table_map used_tables() const { return (*ref)->used_tables(); }
......@@ -413,7 +413,7 @@ class Item_int_with_ref :public Item_int
public:
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);
}
......
......@@ -43,7 +43,8 @@ static bool convert_constant_item(Field *field, Item **item)
{
if ((*item)->const_item())
{
(*item)->save_in_field(field);
if ((*item)->save_in_field(field))
return 0;
if (!((*item)->null_value))
{
Item *tmp=new Item_int_with_ref(field->val_int(), *item);
......
......@@ -1915,7 +1915,7 @@ String *Item_func_conv_charset3::val_str(String *str)
}
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
binary=0;
......@@ -1948,7 +1948,7 @@ String *Item_func_set_collation::val_str(String *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
binary=0;
......
......@@ -489,7 +489,7 @@ class Item_func_conv_charset :public Item_str_func
public:
Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
{ 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 *);
void fix_length_and_dec();
const char *func_name() const { return "conv_charset"; }
......@@ -501,7 +501,7 @@ class Item_func_set_collation :public Item_str_func
public:
Item_func_set_collation(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
{ 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 *);
void fix_length_and_dec()
{
......
......@@ -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;
timestamp_type t_type=TIMESTAMP_FULL;
......@@ -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->store_time(&ltime,TIMESTAMP_FULL);
......
......@@ -228,7 +228,7 @@ class Item_date :public Item_func
double val() { return (double) val_int(); }
const char *func_name() const { return "date"; }
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)
{
init_make_field(tmp_field,FIELD_TYPE_DATE);
......@@ -311,7 +311,7 @@ class Item_func_now :public Item_date_func
enum Item_result result_type () const { return STRING_RESULT; }
double val() { return (double) value; }
longlong val_int() { return value; }
bool save_in_field(Field *to);
int save_in_field(Field *to);
String *val_str(String *str)
{ str_value.set(buff,buff_length,default_charset_info); return &str_value; }
const char *func_name() const { return "now"; }
......
......@@ -1028,7 +1028,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
field->cmp_type() != value->result_type())
DBUG_RETURN(0);
if (value->save_in_field(field))
if (value->save_in_field(field) == 1)
{
if (type == Item_func::EQUAL_FUNC)
{
......
......@@ -2113,7 +2113,7 @@ fill_record(List<Item> &fields,List<Item> &values)
while ((field=(Item_field*) f++))
{
value=v++;
if (value->save_in_field(field->field))
if (value->save_in_field(field->field) == 1)
DBUG_RETURN(1);
}
DBUG_RETURN(0);
......@@ -2131,7 +2131,7 @@ fill_record(Field **ptr,List<Item> &values)
while ((field = *ptr++))
{
value=v++;
if (value->save_in_field(field))
if (value->save_in_field(field) == 1)
DBUG_RETURN(1);
}
DBUG_RETURN(0);
......
......@@ -179,7 +179,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
Item *item;
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;
}
if (!(key= (byte*) sql_calloc(ALIGN_SIZE(key_len))))
......
......@@ -2478,7 +2478,7 @@ store_val_in_field(Field *field,Item *item)
THD *thd=current_thd;
ulong cuted_fields=thd->cuted_fields;
thd->count_cuted_fields=1;
item->save_in_field(field);
(void) item->save_in_field(field);
thd->count_cuted_fields=0;
return cuted_fields != thd->cuted_fields;
}
......
......@@ -338,7 +338,7 @@ class store_key_item :public store_key
{}
bool copy()
{
item->save_in_field(to_field);
(void) item->save_in_field(to_field);
return err != 0;
}
const char *name() const { return "func"; }
......@@ -362,7 +362,7 @@ class store_key_const_item :public store_key_item
if (!inited)
{
inited=1;
item->save_in_field(to_field);
(void)item->save_in_field(to_field);
}
return err != 0;
}
......
......@@ -590,7 +590,7 @@ static bool make_empty_rec(File file,enum db_type table_type,
if (field->def &&
(regfield->real_type() != FIELD_TYPE_YEAR ||
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 &&
(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