summaryrefslogtreecommitdiff
path: root/sql/sql_analyse.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_analyse.cc')
-rw-r--r--sql/sql_analyse.cc121
1 files changed, 55 insertions, 66 deletions
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc
index bd8c0e5ba87..68f7d45e81c 100644
--- a/sql/sql_analyse.cc
+++ b/sql/sql_analyse.cc
@@ -41,13 +41,7 @@
int sortcmp2(void* cmp_arg __attribute__((unused)),
const String *a,const String *b)
{
- return sortcmp(a,b);
-}
-
-int stringcmp2(void* cmp_arg __attribute__((unused)),
- const String *a,const String *b)
-{
- return stringcmp(a,b);
+ return sortcmp(a,b,a->charset());
}
int compare_double2(void* cmp_arg __attribute__((unused)),
@@ -90,15 +84,14 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
(*param->item)->val() < 0)
{
delete pc;
- net_printf(&thd->net, ER_WRONG_PARAMETERS_TO_PROCEDURE, proc_name);
+ my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name);
DBUG_RETURN(0);
}
pc->max_tree_elements = (uint) (*param->item)->val_int();
param = param->next;
if (param->next) // no third parameter possible
{
- delete pc;
- net_printf(&thd->net, ER_WRONG_PARAMCOUNT_TO_PROCEDURE, proc_name);
+ my_error(ER_WRONG_PARAMCOUNT_TO_PROCEDURE, MYF(0), proc_name);
DBUG_RETURN(0);
}
// second parameter
@@ -106,7 +99,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
(*param->item)->val() < 0)
{
delete pc;
- net_printf(&thd->net, ER_WRONG_PARAMETERS_TO_PROCEDURE, proc_name);
+ my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name);
DBUG_RETURN(0);
}
pc->max_treemem = (uint) (*param->item)->val_int();
@@ -115,7 +108,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
(*param->item)->val() < 0)
{
delete pc;
- net_printf(&thd->net, ER_WRONG_PARAMETERS_TO_PROCEDURE, proc_name);
+ my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name);
DBUG_RETURN(0);
}
// if only one parameter was given, it will be the value of max_tree_elements
@@ -172,7 +165,7 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
MySQL removes any endspaces of a string, so we must take care only of
spaces in front of a string
*/
- for (; str != end && isspace(*str); str++) ;
+ for (; str != end && my_isspace(system_charset_info, *str); str++) ;
if (str == end)
return 0;
@@ -185,16 +178,18 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
else
info->negative = 0;
begin = str;
- for (; str != end && isdigit(*str); str++)
+ for (; str != end && my_isdigit(system_charset_info,*str); str++)
{
if (!info->integers && *str == '0' && (str + 1) != end &&
- isdigit(*(str + 1)))
+ my_isdigit(system_charset_info,*(str + 1)))
info->zerofill = 1; // could be a postnumber for example
info->integers++;
}
if (str == end && info->integers)
{
- info->ullval = (ulonglong) strtoull(begin ,NULL, 10);
+ char *endpos= (char*) end;
+ int error;
+ info->ullval= (ulonglong) my_strtoll10(begin, &endpos, &error);
if (info->integers == 1)
return 0; // a single number can't be zerofill
info->maybe_zerofill = 1;
@@ -206,7 +201,9 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
return 0;
if ((str + 1) == end) // number was something like '123[.eE]'
{
- info->ullval = (ulonglong) strtoull(begin, NULL, 10);
+ char *endpos= (char*) str;
+ int error;
+ info->ullval= (ulonglong) my_strtoll10(begin, &endpos, &error);
return 1;
}
if (*str == 'e' || *str == 'E') // number may be something like '1e+50'
@@ -214,7 +211,7 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
str++;
if (*str != '-' && *str != '+')
return 0;
- for (str++; str != end && isdigit(*str); str++) ;
+ for (str++; str != end && my_isdigit(system_charset_info,*str); str++) ;
if (str == end)
{
info->is_float = 1; // we can't use variable decimals here
@@ -225,14 +222,16 @@ bool test_if_number(NUM_INFO *info, const char *str, uint str_len)
for (str++; *(end - 1) == '0'; end--); // jump over zeros at the end
if (str == end) // number was something like '123.000'
{
- info->ullval = (ulonglong) strtoull(begin, NULL, 10);
+ char *endpos= (char*) str;
+ int error;
+ info->ullval= (ulonglong) my_strtoll10(begin, &endpos, &error);
return 1;
}
- for (; str != end && isdigit(*str); str++)
+ for (; str != end && my_isdigit(system_charset_info,*str); str++)
info->decimals++;
if (str == end)
{
- info->dval = atod(begin);
+ info->dval = my_atof(begin);
return 1;
}
}
@@ -278,7 +277,7 @@ void free_string(String *s)
void field_str::add()
{
char buff[MAX_FIELD_WIDTH], *ptr;
- String s(buff, sizeof(buff)), *res;
+ String s(buff, sizeof(buff),&my_charset_bin), *res;
ulong length;
if (!(res = item->val_str(&s)))
@@ -313,6 +312,7 @@ void field_str::add()
was_maybe_zerofill = num_info.maybe_zerofill;
}
+ /* Update min and max arguments */
if (!found)
{
found = 1;
@@ -328,30 +328,20 @@ void field_str::add()
if (length > max_length)
max_length = length;
- if (item->binary)
- {
- if (stringcmp(res, &min_arg) < 0)
- min_arg.copy(*res);
- if (stringcmp(res, &max_arg) > 0)
- max_arg.copy(*res);
- }
- else
- {
- if (sortcmp(res, &min_arg) < 0)
- min_arg.copy(*res);
- if (sortcmp(res, &max_arg) > 0)
- max_arg.copy(*res);
- }
+ if (sortcmp(res, &min_arg,item->collation.collation) < 0)
+ min_arg.copy(*res);
+ if (sortcmp(res, &max_arg,item->collation.collation) > 0)
+ max_arg.copy(*res);
}
if (room_in_tree)
{
if (res != &s)
s.copy(*res);
- if (!tree_search(&tree, (void*) &s)) // If not in tree
+ if (!tree_search(&tree, (void*) &s, tree.custom_arg)) // If not in tree
{
s.copy(); // slow, when SAFE_MALLOC is in use
- if (!tree_insert(&tree, (void*) &s, 0))
+ if (!tree_insert(&tree, (void*) &s, 0, tree.custom_arg))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
@@ -391,8 +381,7 @@ void field_real::add()
if ((decs = decimals()) == NOT_FIXED_DEC)
{
- sprintf(buff, "%g", num);
- length = (uint) strlen(buff);
+ length= my_sprintf(buff, (buff, "%g", num));
if (rint(num) != num)
max_notzero_dec_len = 1;
}
@@ -401,12 +390,11 @@ void field_real::add()
#ifdef HAVE_SNPRINTF
buff[sizeof(buff)-1]=0; // Safety
snprintf(buff, sizeof(buff)-1, "%-.*f", (int) decs, num);
+ length = (uint) strlen(buff);
#else
- sprintf(buff, "%-.*f", (int) decs, num);
+ length= my_sprintf(buff, (buff, "%-.*f", (int) decs, num));
#endif
- length = (uint) strlen(buff);
-
// We never need to check further than this
end = buff + length - 1 - decs + max_notzero_dec_len;
@@ -420,7 +408,7 @@ void field_real::add()
if (room_in_tree)
{
- if (!(element = tree_insert(&tree, (void*) &num, 0)))
+ if (!(element = tree_insert(&tree, (void*) &num, 0, tree.custom_arg)))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
@@ -476,7 +464,7 @@ void field_longlong::add()
if (room_in_tree)
{
- if (!(element = tree_insert(&tree, (void*) &num, 0)))
+ if (!(element = tree_insert(&tree, (void*) &num, 0, tree.custom_arg)))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
@@ -532,7 +520,7 @@ void field_ulonglong::add()
if (room_in_tree)
{
- if (!(element = tree_insert(&tree, (void*) &num, 0)))
+ if (!(element = tree_insert(&tree, (void*) &num, 0, tree.custom_arg)))
{
room_in_tree = 0; // Remove tree, out of RAM ?
delete_tree(&tree);
@@ -589,8 +577,9 @@ bool analyse::end_of_records()
{
field_info **f = f_info;
char buff[MAX_FIELD_WIDTH];
- String *res, s_min(buff, sizeof(buff)), s_max(buff, sizeof(buff)),
- ans(buff, sizeof(buff));
+ String *res, s_min(buff, sizeof(buff),&my_charset_bin),
+ s_max(buff, sizeof(buff),&my_charset_bin),
+ ans(buff, sizeof(buff),&my_charset_bin);
for (; f != f_end; f++)
{
@@ -604,23 +593,23 @@ bool analyse::end_of_records()
{
func_items[1]->null_value = 0;
res = (*f)->get_min_arg(&s_min);
- func_items[1]->set(res->ptr(), res->length());
+ func_items[1]->set(res->ptr(), res->length(), res->charset());
func_items[2]->null_value = 0;
res = (*f)->get_max_arg(&s_max);
- func_items[2]->set(res->ptr(), res->length());
+ func_items[2]->set(res->ptr(), res->length(), res->charset());
}
func_items[3]->set((longlong) (*f)->min_length);
func_items[4]->set((longlong) (*f)->max_length);
func_items[5]->set((longlong) (*f)->empty);
func_items[6]->set((longlong) (*f)->nulls);
res = (*f)->avg(&s_max, rows);
- func_items[7]->set(res->ptr(), res->length());
+ func_items[7]->set(res->ptr(), res->length(), res->charset());
func_items[8]->null_value = 0;
res = (*f)->std(&s_max, rows);
if (!res)
func_items[8]->null_value = 1;
else
- func_items[8]->set(res->ptr(), res->length());
+ func_items[8]->set(res->ptr(), res->length(), res->charset());
/*
count the dots, quotas, etc. in (ENUM("a","b","c"...))
If tree has been removed, don't suggest ENUM.
@@ -638,14 +627,14 @@ bool analyse::end_of_records()
((*f)->tree.elements_in_tree * 3 - 1 + 6))))
{
char tmp[331]; //331, because one double prec. num. can be this long
- String tmp_str(tmp, sizeof(tmp));
+ String tmp_str(tmp, sizeof(tmp),&my_charset_bin);
TREE_INFO tree_info;
tree_info.str = &tmp_str;
tree_info.found = 0;
tree_info.item = (*f)->item;
- tmp_str.set("ENUM(", 5);
+ tmp_str.set("ENUM(", 5,&my_charset_bin);
tree_walk(&(*f)->tree, (*f)->collect_enum(), (char*) &tree_info,
left_root_right);
tmp_str.append(')');
@@ -653,7 +642,7 @@ bool analyse::end_of_records()
if (!(*f)->nulls)
tmp_str.append(" NOT NULL");
output_str_length = tmp_str.length();
- func_items[9]->set(tmp_str.ptr(), tmp_str.length());
+ func_items[9]->set(tmp_str.ptr(), tmp_str.length(), tmp_str.charset());
if (result->send_data(result_fields))
return -1;
continue;
@@ -698,7 +687,7 @@ bool analyse::end_of_records()
}
if (!(*f)->nulls)
ans.append(" NOT NULL");
- func_items[9]->set(ans.ptr(), ans.length());
+ func_items[9]->set(ans.ptr(), ans.length(), ans.charset());
if (result->send_data(result_fields))
return -1;
}
@@ -749,7 +738,7 @@ void field_str::get_opt_type(String *answer, ha_rows total_rows)
{
if (must_be_blob)
{
- if (item->binary)
+ if (item->collation.collation == &my_charset_bin)
answer->append("TINYBLOB", 8);
else
answer->append("TINYTEXT", 8);
@@ -767,21 +756,21 @@ void field_str::get_opt_type(String *answer, ha_rows total_rows)
}
else if (max_length < (1L << 16))
{
- if (item->binary)
+ if (item->collation.collation == &my_charset_bin)
answer->append("BLOB", 4);
else
answer->append("TEXT", 4);
}
else if (max_length < (1L << 24))
{
- if (item->binary)
+ if (item->collation.collation == &my_charset_bin)
answer->append("MEDIUMBLOB", 10);
else
answer->append("MEDIUMTEXT", 10);
}
else
{
- if (item->binary)
+ if (item->collation.collation == &my_charset_bin)
answer->append("LONGBLOB", 8);
else
answer->append("LONGTEXT", 8);
@@ -907,14 +896,14 @@ int collect_real(double *element, element_count count __attribute__((unused)),
TREE_INFO *info)
{
char buff[MAX_FIELD_WIDTH];
- String s(buff, sizeof(buff));
+ String s(buff, sizeof(buff),current_thd->charset());
if (info->found)
info->str->append(',');
else
info->found = 1;
info->str->append('\'');
- s.set(*element, info->item->decimals);
+ s.set(*element, info->item->decimals, current_thd->charset());
info->str->append(s);
info->str->append('\'');
return 0;
@@ -926,14 +915,14 @@ int collect_longlong(longlong *element,
TREE_INFO *info)
{
char buff[MAX_FIELD_WIDTH];
- String s(buff, sizeof(buff));
+ String s(buff, sizeof(buff),&my_charset_bin);
if (info->found)
info->str->append(',');
else
info->found = 1;
info->str->append('\'');
- s.set(*element);
+ s.set(*element, current_thd->charset());
info->str->append(s);
info->str->append('\'');
return 0;
@@ -945,14 +934,14 @@ int collect_ulonglong(ulonglong *element,
TREE_INFO *info)
{
char buff[MAX_FIELD_WIDTH];
- String s(buff, sizeof(buff));
+ String s(buff, sizeof(buff),&my_charset_bin);
if (info->found)
info->str->append(',');
else
info->found = 1;
info->str->append('\'');
- s.set(*element);
+ s.set(*element, current_thd->charset());
info->str->append(s);
info->str->append('\'');
return 0;