String::set(double) and set(longlong) -> set_real() and set_int()

fix Field::store(double) being used instead of store(longlong)

NB: overloading functions is evil
This commit is contained in:
unknown 2006-06-16 12:17:20 +02:00
parent 2996b49af7
commit 0237d9b0af
16 changed files with 83 additions and 83 deletions

View file

@ -4978,7 +4978,7 @@ int Field_time::store_time(TIME *ltime, timestamp_type type)
(ltime->minute * 100 + ltime->second);
if (ltime->neg)
tmp= -tmp;
return Field_time::store((longlong) tmp);
return Field_time::store((longlong) tmp, TRUE);
}
@ -4990,7 +4990,7 @@ int Field_time::store(double nr)
if (nr > 8385959.0)
{
tmp=8385959L;
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME);
error= 1;
}
@ -7117,7 +7117,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
int Field_blob::store(double nr)
{
CHARSET_INFO *cs=charset();
value.set(nr, 2, cs);
value.set_real(nr, 2, cs);
return Field_blob::store(value.ptr(),(uint) value.length(), cs);
}
@ -7125,7 +7125,7 @@ int Field_blob::store(double nr)
int Field_blob::store(longlong nr, bool unsigned_val)
{
CHARSET_INFO *cs=charset();
value.set(nr, unsigned_val, cs);
value.set_int(nr, unsigned_val, cs);
return Field_blob::store(value.ptr(), (uint) value.length(), cs);
}
@ -8216,7 +8216,7 @@ int Field_bit::store_decimal(const my_decimal *val)
{
int err= 0;
longlong i= convert_decimal2longlong(val, 1, &err);
return test(err | store(i));
return test(err | store(i, TRUE));
}

View file

@ -61,7 +61,7 @@ Hybrid_type_traits::val_decimal(Hybrid_type *val, my_decimal *to) const
String *
Hybrid_type_traits::val_str(Hybrid_type *val, String *to, uint8 decimals) const
{
to->set(val->real, decimals, &my_charset_bin);
to->set_real(val->real, decimals, &my_charset_bin);
return to;
}
@ -202,7 +202,7 @@ String *Item::val_string_from_real(String *str)
double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals, &my_charset_bin);
str->set_real(nr,decimals, &my_charset_bin);
return str;
}
@ -212,7 +212,7 @@ String *Item::val_string_from_int(String *str)
longlong nr= val_int();
if (null_value)
return 0;
str->set(nr, unsigned_flag, &my_charset_bin);
str->set_int(nr, unsigned_flag, &my_charset_bin);
return str;
}
@ -2038,7 +2038,7 @@ String *Item_float::val_str(String *str)
{
// following assert is redundant, because fixed=1 assigned in constructor
DBUG_ASSERT(fixed == 1);
str->set(value,decimals,&my_charset_bin);
str->set_real(value,decimals,&my_charset_bin);
return str;
}
@ -2633,7 +2633,7 @@ String *Item_param::val_str(String* str)
case LONG_DATA_VALUE:
return &str_value_ptr;
case REAL_VALUE:
str->set(value.real, NOT_FIXED_DEC, &my_charset_bin);
str->set_real(value.real, NOT_FIXED_DEC, &my_charset_bin);
return str;
case INT_VALUE:
str->set(value.integer, &my_charset_bin);
@ -2673,7 +2673,7 @@ const String *Item_param::query_val_str(String* str) const
str->set(value.integer, &my_charset_bin);
break;
case REAL_VALUE:
str->set(value.real, NOT_FIXED_DEC, &my_charset_bin);
str->set_real(value.real, NOT_FIXED_DEC, &my_charset_bin);
break;
case DECIMAL_VALUE:
if (my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value,
@ -4326,7 +4326,7 @@ void Item_float::print(String *str)
}
char buffer[20];
String num(buffer, sizeof(buffer), &my_charset_bin);
num.set(value, decimals, &my_charset_bin);
num.set_real(value, decimals, &my_charset_bin);
str->append(num);
}
@ -5768,7 +5768,7 @@ longlong Item_cache_real::val_int()
String* Item_cache_real::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
str->set(value, decimals, default_charset());
str->set_real(value, decimals, default_charset());
return str;
}

View file

@ -416,7 +416,7 @@ String *Item_real_func::val_str(String *str)
double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals, &my_charset_bin);
str->set_real(nr,decimals, &my_charset_bin);
return str;
}
@ -556,7 +556,7 @@ String *Item_int_func::val_str(String *str)
longlong nr=val_int();
if (null_value)
return 0;
str->set(nr, unsigned_flag, &my_charset_bin);
str->set_int(nr, unsigned_flag, &my_charset_bin);
return str;
}
@ -698,7 +698,7 @@ String *Item_func_numhybrid::val_str(String *str)
longlong nr= int_op();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr, unsigned_flag, &my_charset_bin);
str->set_int(nr, unsigned_flag, &my_charset_bin);
break;
}
case REAL_RESULT:
@ -706,7 +706,7 @@ String *Item_func_numhybrid::val_str(String *str)
double nr= real_op();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals,&my_charset_bin);
str->set_real(nr,decimals,&my_charset_bin);
break;
}
case STRING_RESULT:
@ -2052,7 +2052,7 @@ String *Item_func_min_max::val_str(String *str)
longlong nr=val_int();
if (null_value)
return 0;
str->set(nr, unsigned_flag, &my_charset_bin);
str->set_int(nr, unsigned_flag, &my_charset_bin);
return str;
}
case DECIMAL_RESULT:
@ -2068,7 +2068,7 @@ String *Item_func_min_max::val_str(String *str)
double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals,&my_charset_bin);
str->set_real(nr,decimals,&my_charset_bin);
return str;
}
case STRING_RESULT:
@ -2819,7 +2819,7 @@ String *Item_func_udf_float::val_str(String *str)
double nr= val_real();
if (null_value)
return 0; /* purecov: inspected */
str->set(nr,decimals,&my_charset_bin);
str->set_real(nr,decimals,&my_charset_bin);
return str;
}
@ -2838,7 +2838,7 @@ String *Item_func_udf_int::val_str(String *str)
longlong nr=val_int();
if (null_value)
return 0;
str->set(nr, unsigned_flag, &my_charset_bin);
str->set_int(nr, unsigned_flag, &my_charset_bin);
return str;
}
@ -3638,7 +3638,7 @@ String *user_var_entry::val_str(my_bool *null_value, String *str,
switch (type) {
case REAL_RESULT:
str->set(*(double*) value, decimals, &my_charset_bin);
str->set_real(*(double*) value, decimals, &my_charset_bin);
break;
case INT_RESULT:
str->set(*(longlong*) value, &my_charset_bin);

View file

@ -1808,7 +1808,7 @@ String *Item_func_format::val_str(String *str)
return 0; /* purecov: inspected */
nr= my_double_round(nr, decimals, FALSE);
/* Here default_charset() is right as this is not an automatic conversion */
str->set(nr,decimals, default_charset());
str->set_real(nr,decimals, default_charset());
if (isnan(nr))
return str;
str_length=str->length();

View file

@ -1578,13 +1578,13 @@ Item_sum_hybrid::val_str(String *str)
case STRING_RESULT:
return &value;
case REAL_RESULT:
str->set(sum,decimals, &my_charset_bin);
str->set_real(sum,decimals, &my_charset_bin);
break;
case DECIMAL_RESULT:
my_decimal2string(E_DEC_FATAL_ERROR, &sum_dec, 0, 0, 0, str);
return str;
case INT_RESULT:
str->set(sum_int, unsigned_flag, &my_charset_bin);
str->set_int(sum_int, unsigned_flag, &my_charset_bin);
break;
case ROW_RESULT:
default:

View file

@ -1503,7 +1503,7 @@ double Item_func_sysdate_local::val_real()
{
DBUG_ASSERT(fixed == 1);
store_now_in_TIME(&ltime);
return (longlong) TIME_to_ulonglong_datetime(&ltime);
return ulonglong2double(TIME_to_ulonglong_datetime(&ltime));
}

View file

@ -313,9 +313,9 @@ bool Log_to_csv_event_handler::
table->field[1]->store(user_host, user_host_len, client_cs);
table->field[1]->set_notnull();
table->field[2]->store((longlong) thread_id);
table->field[2]->store((longlong) thread_id, TRUE);
table->field[2]->set_notnull();
table->field[3]->store((longlong) server_id);
table->field[3]->store((longlong) server_id, TRUE);
table->field[3]->set_notnull();
table->field[4]->store(command_type, command_type_len, client_cs);
table->field[4]->set_notnull();
@ -395,13 +395,13 @@ bool Log_to_csv_event_handler::
if (query_start_arg)
{
/* fill in query_time field */
table->field[2]->store(query_time);
table->field[2]->store(query_time, TRUE);
/* lock_time */
table->field[3]->store(lock_time);
table->field[3]->store(lock_time, TRUE);
/* rows_sent */
table->field[4]->store((longlong) thd->sent_row_count);
table->field[4]->store((longlong) thd->sent_row_count, TRUE);
/* rows_examined */
table->field[5]->store((longlong) thd->examined_row_count);
table->field[5]->store((longlong) thd->examined_row_count, TRUE);
}
else
{
@ -420,18 +420,18 @@ bool Log_to_csv_event_handler::
if (thd->last_insert_id_used)
{
table->field[7]->store((longlong) thd->current_insert_id);
table->field[7]->store((longlong) thd->current_insert_id, TRUE);
table->field[7]->set_notnull();
}
/* set value if we do an insert on autoincrement column */
if (thd->insert_id_used)
{
table->field[8]->store((longlong) thd->last_insert_id);
table->field[8]->store((longlong) thd->last_insert_id, TRUE);
table->field[8]->set_notnull();
}
table->field[9]->store((longlong) server_id);
table->field[9]->store((longlong) server_id, TRUE);
table->field[9]->set_notnull();
/* sql_text */

View file

@ -68,11 +68,11 @@ public:
longlong val_int() { return (longlong) value; }
String *val_str(String *s)
{
s->set(value,decimals,default_charset());
s->set_real(value,decimals,default_charset());
return s;
}
my_decimal *val_decimal(my_decimal *);
unsigned int size_of() { return sizeof(*this);}
unsigned int size_of() { return sizeof(*this);}
};
class Item_proc_int :public Item_proc
@ -91,7 +91,7 @@ public:
longlong val_int() { return value; }
String *val_str(String *s) { s->set(value, default_charset()); return s; }
my_decimal *val_decimal(my_decimal *);
unsigned int size_of() { return sizeof(*this);}
unsigned int size_of() { return sizeof(*this);}
};
@ -102,12 +102,12 @@ public:
{ this->max_length=length; }
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
void set(double nr) { str_value.set(nr, 2, default_charset()); }
void set(double nr) { str_value.set_real(nr, 2, default_charset()); }
void set(longlong nr) { str_value.set(nr, default_charset()); }
void set(const char *str, uint length, CHARSET_INFO *cs)
{ str_value.copy(str,length,cs); }
double val_real()
{
{
int err_not_used;
char *end_not_used;
CHARSET_INFO *cs= str_value.charset();

View file

@ -897,7 +897,7 @@ bool Protocol_simple::store(float from, uint32 decimals, String *buffer)
field_types[field_pos] == MYSQL_TYPE_FLOAT);
field_pos++;
#endif
buffer->set((double) from, decimals, thd->charset());
buffer->set_real((double) from, decimals, thd->charset());
return net_store_data((char*) buffer->ptr(), buffer->length());
}
@ -909,7 +909,7 @@ bool Protocol_simple::store(double from, uint32 decimals, String *buffer)
field_types[field_pos] == MYSQL_TYPE_DOUBLE);
field_pos++;
#endif
buffer->set(from, decimals, thd->charset());
buffer->set_real(from, decimals, thd->charset());
return net_store_data((char*) buffer->ptr(), buffer->length());
}

View file

@ -555,17 +555,17 @@ db_create_routine(THD *thd, int type, sp_head *sp)
table->field[MYSQL_PROC_FIELD_NAME]->
store(sp->m_name.str, sp->m_name.length, system_charset_info);
table->field[MYSQL_PROC_FIELD_TYPE]->
store((longlong)type);
store((longlong)type, TRUE);
table->field[MYSQL_PROC_FIELD_SPECIFIC_NAME]->
store(sp->m_name.str, sp->m_name.length, system_charset_info);
if (sp->m_chistics->daccess != SP_DEFAULT_ACCESS)
table->field[MYSQL_PROC_FIELD_ACCESS]->
store((longlong)sp->m_chistics->daccess);
store((longlong)sp->m_chistics->daccess, TRUE);
table->field[MYSQL_PROC_FIELD_DETERMINISTIC]->
store((longlong)(sp->m_chistics->detistic ? 1 : 2));
store((longlong)(sp->m_chistics->detistic ? 1 : 2), TRUE);
if (sp->m_chistics->suid != SP_IS_DEFAULT_SUID)
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->
store((longlong)sp->m_chistics->suid);
store((longlong)sp->m_chistics->suid, TRUE);
table->field[MYSQL_PROC_FIELD_PARAM_LIST]->
store(sp->m_params.str, sp->m_params.length, system_charset_info);
if (sp->m_type == TYPE_ENUM_FUNCTION)
@ -582,7 +582,7 @@ db_create_routine(THD *thd, int type, sp_head *sp)
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_CREATED])->set_time();
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time();
table->field[MYSQL_PROC_FIELD_SQL_MODE]->
store((longlong)thd->variables.sql_mode);
store((longlong)thd->variables.sql_mode, TRUE);
if (sp->m_chistics->comment.str)
table->field[MYSQL_PROC_FIELD_COMMENT]->
store(sp->m_chistics->comment.str, sp->m_chistics->comment.length,
@ -686,10 +686,10 @@ db_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics)
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time();
if (chistics->suid != SP_IS_DEFAULT_SUID)
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->
store((longlong)chistics->suid);
store((longlong)chistics->suid, TRUE);
if (chistics->daccess != SP_DEFAULT_ACCESS)
table->field[MYSQL_PROC_FIELD_ACCESS]->
store((longlong)chistics->daccess);
store((longlong)chistics->daccess, TRUE);
if (chistics->comment.str)
table->field[MYSQL_PROC_FIELD_COMMENT]->store(chistics->comment.str,
chistics->comment.length,

View file

@ -2030,7 +2030,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
table->field[next_field+2]->store((longlong) mqh.conn_per_hour, TRUE);
if (table->s->fields >= 36 &&
(mqh.specified_limits & USER_RESOURCES::USER_CONNECTIONS))
table->field[next_field+3]->store((longlong) mqh.user_conn);
table->field[next_field+3]->store((longlong) mqh.user_conn, TRUE);
mqh_used= mqh_used || mqh.questions || mqh.updates || mqh.conn_per_hour;
}
if (old_row_exists)

View file

@ -1024,7 +1024,7 @@ String *field_decimal::avg(String *s, ha_rows rows)
{
if (!(rows - nulls))
{
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
return s;
}
my_decimal num, avg_val, rounded_avg;
@ -1045,7 +1045,7 @@ String *field_decimal::std(String *s, ha_rows rows)
{
if (!(rows - nulls))
{
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
return s;
}
my_decimal num, tmp, sum2, sum2d;
@ -1058,7 +1058,7 @@ String *field_decimal::std(String *s, ha_rows rows)
my_decimal_sub(E_DEC_FATAL_ERROR, &sum2, sum_sqr+cur_sum, &tmp);
my_decimal_div(E_DEC_FATAL_ERROR, &tmp, &sum2, &num, prec_increment);
my_decimal2double(E_DEC_FATAL_ERROR, &tmp, &std_sqr);
s->set(((double) std_sqr <= 0.0 ? 0.0 : sqrt(std_sqr)),
s->set_real(((double) std_sqr <= 0.0 ? 0.0 : sqrt(std_sqr)),
min(item->decimals + prec_increment, NOT_FIXED_DEC), my_thd_charset);
return s;
@ -1092,7 +1092,7 @@ int collect_real(double *element, element_count count __attribute__((unused)),
else
info->found = 1;
info->str->append('\'');
s.set(*element, info->item->decimals, current_thd->charset());
s.set_real(*element, info->item->decimals, current_thd->charset());
info->str->append(s);
info->str->append('\'');
return 0;

View file

@ -128,9 +128,9 @@ public:
String *avg(String *s, ha_rows rows)
{
if (!(rows - nulls))
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
else
s->set((ulonglong2double(sum) / ulonglong2double(rows - nulls)),
s->set_real((ulonglong2double(sum) / ulonglong2double(rows - nulls)),
DEC_IN_AVG,my_thd_charset);
return s;
}
@ -190,34 +190,34 @@ public:
void add();
void get_opt_type(String*, ha_rows);
String *get_min_arg(String *s)
{
s->set(min_arg, item->decimals,my_thd_charset);
return s;
String *get_min_arg(String *s)
{
s->set_real(min_arg, item->decimals, my_thd_charset);
return s;
}
String *get_max_arg(String *s)
{
s->set(max_arg, item->decimals,my_thd_charset);
return s;
String *get_max_arg(String *s)
{
s->set_real(max_arg, item->decimals, my_thd_charset);
return s;
}
String *avg(String *s, ha_rows rows)
{
if (!(rows - nulls))
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
else
s->set(((double)sum / (double) (rows - nulls)), item->decimals,my_thd_charset);
s->set_real(((double)sum / (double) (rows - nulls)), item->decimals,my_thd_charset);
return s;
}
String *std(String *s, ha_rows rows)
{
double tmp = ulonglong2double(rows);
if (!(tmp - nulls))
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
else
{
double tmp2 = ((sum_sqr - sum * sum / (tmp - nulls)) /
(tmp - nulls));
s->set(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), item->decimals,my_thd_charset);
s->set_real(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), item->decimals,my_thd_charset);
}
return s;
}
@ -249,21 +249,21 @@ public:
String *avg(String *s, ha_rows rows)
{
if (!(rows - nulls))
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
else
s->set(((double) sum / (double) (rows - nulls)), DEC_IN_AVG,my_thd_charset);
s->set_real(((double) sum / (double) (rows - nulls)), DEC_IN_AVG,my_thd_charset);
return s;
}
String *std(String *s, ha_rows rows)
{
double tmp = ulonglong2double(rows);
if (!(tmp - nulls))
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
else
{
double tmp2 = ((sum_sqr - sum * sum / (tmp - nulls)) /
(tmp - nulls));
s->set(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), DEC_IN_AVG,my_thd_charset);
s->set_real(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), DEC_IN_AVG,my_thd_charset);
}
return s;
}
@ -293,9 +293,9 @@ public:
String *avg(String *s, ha_rows rows)
{
if (!(rows - nulls))
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
else
s->set((ulonglong2double(sum) / ulonglong2double(rows - nulls)),
s->set_real((ulonglong2double(sum) / ulonglong2double(rows - nulls)),
DEC_IN_AVG,my_thd_charset);
return s;
}
@ -303,13 +303,13 @@ public:
{
double tmp = ulonglong2double(rows);
if (!(tmp - nulls))
s->set((double) 0.0, 1,my_thd_charset);
s->set_real((double) 0.0, 1,my_thd_charset);
else
{
double tmp2 = ((ulonglong2double(sum_sqr) -
ulonglong2double(sum * sum) / (tmp - nulls)) /
(tmp - nulls));
s->set(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), DEC_IN_AVG,my_thd_charset);
s->set_real(((double) tmp2 <= 0.0 ? 0.0 : sqrt(tmp2)), DEC_IN_AVG,my_thd_charset);
}
return s;
}

View file

@ -3421,7 +3421,7 @@ static int get_schema_stat_record(THD *thd, struct st_table_list *tables,
show_table->field[key_part->fieldnr-1]->key_length()))
{
table->field[10]->store((longlong) key_part->length /
key_part->field->charset()->mbmaxlen);
key_part->field->charset()->mbmaxlen, TRUE);
table->field[10]->set_notnull();
}
uint flags= key_part->field ? key_part->field->flags : 0;

View file

@ -96,7 +96,7 @@ bool String::realloc(uint32 alloc_length)
return FALSE;
}
bool String::set(longlong num, bool unsigned_flag, CHARSET_INFO *cs)
bool String::set_int(longlong num, bool unsigned_flag, CHARSET_INFO *cs)
{
uint l=20*cs->mbmaxlen+1;
int base= unsigned_flag ? 10 : -10;
@ -108,7 +108,7 @@ bool String::set(longlong num, bool unsigned_flag, CHARSET_INFO *cs)
return FALSE;
}
bool String::set(double num,uint decimals, CHARSET_INFO *cs)
bool String::set_real(double num,uint decimals, CHARSET_INFO *cs)
{
char buff[331];
uint dummy_errors;

View file

@ -139,12 +139,12 @@ public:
}
str_charset=cs;
}
bool set(longlong num, bool unsigned_flag, CHARSET_INFO *cs);
bool set_int(longlong num, bool unsigned_flag, CHARSET_INFO *cs);
bool set(longlong num, CHARSET_INFO *cs)
{ return set(num, false, cs); }
{ return set_int(num, false, cs); }
bool set(ulonglong num, CHARSET_INFO *cs)
{ return set((longlong)num, true, cs); }
bool set(double num,uint decimals, CHARSET_INFO *cs);
{ return set_int((longlong)num, true, cs); }
bool set_real(double num,uint decimals, CHARSET_INFO *cs);
/*
PMG 2004.11.12