Commit f224238f authored by unknown's avatar unknown

Merge malff@bk-internal.mysql.com:/home/bk/mysql-5.1-runtime

into  weblab.(none):/home/marcsql/TREE/mysql-5.1-22684


sql/item_func.cc:
  Auto merged
sql/item_func.h:
  Auto merged
sql/item_strfunc.cc:
  Auto merged
sql/item_strfunc.h:
  Auto merged
parents 9d4d6ffe 2975d65c
This diff is collapsed.
......@@ -296,11 +296,6 @@ select atan();
ERROR 42000: Incorrect parameter count in the call to native function 'atan'
select atan2(1, 2, 3);
ERROR 42000: Incorrect parameter count in the call to native function 'atan2'
select benchmark(10, 1+1);
benchmark(10, 1+1)
0
select benchmark(5+5, 2);
ERROR 42000: Incorrect parameters in the call to native function 'BENCHMARK'
select concat();
ERROR 42000: Incorrect parameter count in the call to native function 'concat'
select concat("foo");
......@@ -310,11 +305,6 @@ select concat_ws();
ERROR 42000: Incorrect parameter count in the call to native function 'concat_ws'
select concat_ws("foo");
ERROR 42000: Incorrect parameter count in the call to native function 'concat_ws'
set @pwd="my password";
select encode("secret", @pwd);
ERROR 42000: Incorrect parameters in the call to native function 'ENCODE'
select decode("encoded-secret", @pwd);
ERROR 42000: Incorrect parameters in the call to native function 'DECODE'
select encrypt();
ERROR 42000: Incorrect parameter count in the call to native function 'encrypt'
select encrypt(1, 2, 3);
......@@ -339,9 +329,6 @@ select field();
ERROR 42000: Incorrect parameter count in the call to native function 'field'
select field("p1");
ERROR 42000: Incorrect parameter count in the call to native function 'field'
set @dec=2;
select format(pi(), @dec);
ERROR 42000: Incorrect parameters in the call to native function 'FORMAT'
select from_unixtime();
ERROR 42000: Incorrect parameter count in the call to native function 'from_unixtime'
select from_unixtime(1, 2, 3);
......
......@@ -2391,3 +2391,49 @@ Level Code Message
Note 1051 Unknown table 't1'
Note 1051 Unknown table 't2'
deallocate prepare abc;
set @my_password="password";
set @my_data="clear text to encode";
prepare stmt1 from 'select decode(encode(?, ?), ?)';
execute stmt1 using @my_data, @my_password, @my_password;
decode(encode(?, ?), ?)
clear text to encode
set @my_data="more text to encode";
execute stmt1 using @my_data, @my_password, @my_password;
decode(encode(?, ?), ?)
more text to encode
set @my_password="new password";
execute stmt1 using @my_data, @my_password, @my_password;
decode(encode(?, ?), ?)
more text to encode
deallocate prepare stmt1;
set @to_format="123456789.123456789";
set @dec=0;
prepare stmt2 from 'select format(?, ?)';
execute stmt2 using @to_format, @dec;
format(?, ?)
123,456,789
set @dec=4;
execute stmt2 using @to_format, @dec;
format(?, ?)
123,456,789.1235
set @dec=6;
execute stmt2 using @to_format, @dec;
format(?, ?)
123,456,789.123457
set @dec=2;
execute stmt2 using @to_format, @dec;
format(?, ?)
123,456,789.12
set @to_format="100";
execute stmt2 using @to_format, @dec;
format(?, ?)
100.00
set @to_format="1000000";
execute stmt2 using @to_format, @dec;
format(?, ?)
1,000,000.00
set @to_format="10000";
execute stmt2 using @to_format, @dec;
format(?, ?)
10,000.00
deallocate prepare stmt2;
This diff is collapsed.
......@@ -399,11 +399,6 @@ select atan();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select atan2(1, 2, 3);
select benchmark(10, 1+1);
-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
select benchmark(5+5, 2);
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select concat();
select concat("foo");
......@@ -413,12 +408,6 @@ select concat_ws();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select concat_ws("foo");
set @pwd="my password";
-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
select encode("secret", @pwd);
-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
select decode("encoded-secret", @pwd);
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select encrypt();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
......@@ -448,10 +437,6 @@ select field();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select field("p1");
set @dec=2;
-- error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
select format(pi(), @dec);
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select from_unixtime();
-- error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
......
......@@ -2414,3 +2414,38 @@ execute abc;
drop table if exists t1, t2;
execute abc;
deallocate prepare abc;
#
# Bug#22684: The Functions ENCODE, DECODE and FORMAT are not real functions
#
set @my_password="password";
set @my_data="clear text to encode";
prepare stmt1 from 'select decode(encode(?, ?), ?)';
execute stmt1 using @my_data, @my_password, @my_password;
set @my_data="more text to encode";
execute stmt1 using @my_data, @my_password, @my_password;
set @my_password="new password";
execute stmt1 using @my_data, @my_password, @my_password;
deallocate prepare stmt1;
set @to_format="123456789.123456789";
set @dec=0;
prepare stmt2 from 'select format(?, ?)';
execute stmt2 using @to_format, @dec;
set @dec=4;
execute stmt2 using @to_format, @dec;
set @dec=6;
execute stmt2 using @to_format, @dec;
set @dec=2;
execute stmt2 using @to_format, @dec;
set @to_format="100";
execute stmt2 using @to_format, @dec;
set @to_format="1000000";
execute stmt2 using @to_format, @dec;
set @to_format="10000";
execute stmt2 using @to_format, @dec;
deallocate prepare stmt2;
......@@ -2612,15 +2612,8 @@ Create_func_benchmark Create_func_benchmark::s_singleton;
Item*
Create_func_benchmark::create(THD *thd, Item *arg1, Item *arg2)
{
/* TODO: Known limitation, see Bug#22684 */
if ((arg1->type() != Item::INT_ITEM) || ! arg1->basic_const_item())
{
my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), "BENCHMARK");
return NULL;
}
thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
return new (thd->mem_root) Item_func_benchmark(arg1->val_int(), arg2);
return new (thd->mem_root) Item_func_benchmark(arg1, arg2);
}
......@@ -2887,17 +2880,7 @@ Create_func_decode Create_func_decode::s_singleton;
Item*
Create_func_decode::create(THD *thd, Item *arg1, Item *arg2)
{
/* TODO: Known limitation, see Bug#22684 */
if ((arg2->type() != Item::STRING_ITEM) || ! arg2->basic_const_item())
{
my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), "DECODE");
return NULL;
}
String dummy;
String *val = arg2->val_str(& dummy);
DBUG_ASSERT(val);
return new (thd->mem_root) Item_func_decode(arg1, val->c_ptr());
return new (thd->mem_root) Item_func_decode(arg1, arg2);
}
......@@ -3033,17 +3016,7 @@ Create_func_encode Create_func_encode::s_singleton;
Item*
Create_func_encode::create(THD *thd, Item *arg1, Item *arg2)
{
/* TODO: Known limitation, see Bug#22684 */
if ((arg2->type() != Item::STRING_ITEM) || ! arg2->basic_const_item())
{
my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), "ENCODE");
return NULL;
}
String dummy;
String *val = arg2->val_str(& dummy);
DBUG_ASSERT(val);
return new (thd->mem_root) Item_func_encode(arg1, val->c_ptr());
return new (thd->mem_root) Item_func_encode(arg1, arg2);
}
......@@ -3235,14 +3208,7 @@ Create_func_format Create_func_format::s_singleton;
Item*
Create_func_format::create(THD *thd, Item *arg1, Item *arg2)
{
/* TODO: Known limitation, see Bug#22684 */
if ((arg2->type() != Item::INT_ITEM) || ! arg2->basic_const_item())
{
my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), "FORMAT");
return NULL;
}
return new (thd->mem_root) Item_func_format(arg1, arg2->val_int());
return new (thd->mem_root) Item_func_format(arg1, arg2);
}
......
......@@ -3403,18 +3403,28 @@ longlong Item_func_benchmark::val_int()
char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff), &my_charset_bin);
THD *thd=current_thd;
ulong loop_count;
loop_count= args[0]->val_int();
if (args[0]->null_value)
{
null_value= 1;
return 0;
}
null_value=0;
for (ulong loop=0 ; loop < loop_count && !thd->killed; loop++)
{
switch (args[0]->result_type()) {
switch (args[1]->result_type()) {
case REAL_RESULT:
(void) args[0]->val_real();
(void) args[1]->val_real();
break;
case INT_RESULT:
(void) args[0]->val_int();
(void) args[1]->val_int();
break;
case STRING_RESULT:
(void) args[0]->val_str(&tmp);
(void) args[1]->val_str(&tmp);
break;
case ROW_RESULT:
default:
......@@ -3430,13 +3440,9 @@ longlong Item_func_benchmark::val_int()
void Item_func_benchmark::print(String *str)
{
str->append(STRING_WITH_LEN("benchmark("));
char buffer[20];
// my_charset_bin is good enough for numbers
String st(buffer, sizeof(buffer), &my_charset_bin);
st.set((ulonglong)loop_count, &my_charset_bin);
str->append(st);
str->append(',');
args[0]->print(str);
str->append(',');
args[1]->print(str);
str->append(')');
}
......
......@@ -925,10 +925,9 @@ class Item_func_last_insert_id :public Item_int_func
class Item_func_benchmark :public Item_int_func
{
ulong loop_count;
public:
Item_func_benchmark(ulong loop_count_arg,Item *expr)
:Item_int_func(expr), loop_count(loop_count_arg)
Item_func_benchmark(Item *count_expr, Item *expr)
:Item_int_func(count_expr, expr)
{}
longlong val_int();
const char *func_name() const { return "benchmark"; }
......
......@@ -1673,21 +1673,33 @@ String *Item_func_encrypt::val_str(String *str)
void Item_func_encode::fix_length_and_dec()
{
max_length=args[0]->max_length;
maybe_null=args[0]->maybe_null;
maybe_null=args[0]->maybe_null || args[1]->maybe_null;
collation.set(&my_charset_bin);
}
String *Item_func_encode::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
String *res;
char pw_buff[80];
String tmp_pw_value(pw_buff, sizeof(pw_buff), system_charset_info);
String *password;
DBUG_ASSERT(fixed == 1);
if (!(res=args[0]->val_str(str)))
{
null_value=1; /* purecov: inspected */
return 0; /* purecov: inspected */
}
if (!(password=args[1]->val_str(& tmp_pw_value)))
{
null_value=1;
return 0;
}
null_value=0;
res=copy_if_not_alloced(str,res,res->length());
SQL_CRYPT sql_crypt(password->ptr());
sql_crypt.init();
sql_crypt.encode((char*) res->ptr(),res->length());
res->set_charset(&my_charset_bin);
......@@ -1696,15 +1708,27 @@ String *Item_func_encode::val_str(String *str)
String *Item_func_decode::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
String *res;
char pw_buff[80];
String tmp_pw_value(pw_buff, sizeof(pw_buff), system_charset_info);
String *password;
DBUG_ASSERT(fixed == 1);
if (!(res=args[0]->val_str(str)))
{
null_value=1; /* purecov: inspected */
return 0; /* purecov: inspected */
}
if (!(password=args[1]->val_str(& tmp_pw_value)))
{
null_value=1;
return 0;
}
null_value=0;
res=copy_if_not_alloced(str,res,res->length());
SQL_CRYPT sql_crypt(password->ptr());
sql_crypt.init();
sql_crypt.decode((char*) res->ptr(),res->length());
return res;
......@@ -1874,9 +1898,19 @@ String *Item_func_soundex::val_str(String *str)
** This should be 'internationalized' sometimes.
*/
Item_func_format::Item_func_format(Item *org,int dec) :Item_str_func(org)
const int FORMAT_MAX_DECIMALS= 30;
Item_func_format::Item_func_format(Item *org, Item *dec)
: Item_str_func(org, dec)
{
}
void Item_func_format::fix_length_and_dec()
{
decimals=(uint) set_zone(dec,0,30);
collation.set(default_charset());
uint char_length= args[0]->max_length/args[0]->collation.collation->mbmaxlen;
max_length= ((char_length + (char_length-args[0]->decimals)/3) *
collation.collation->mbmaxlen);
}
......@@ -1887,10 +1921,25 @@ Item_func_format::Item_func_format(Item *org,int dec) :Item_str_func(org)
String *Item_func_format::val_str(String *str)
{
uint32 length, str_length ,dec;
uint32 length;
uint32 str_length;
/* Number of decimal digits */
int dec;
/* Number of characters used to represent the decimals, including '.' */
uint32 dec_length;
int diff;
DBUG_ASSERT(fixed == 1);
dec= decimals ? decimals+1 : 0;
dec= args[1]->val_int();
if (args[1]->null_value)
{
null_value=1;
return NULL;
}
dec= set_zone(dec, 0, FORMAT_MAX_DECIMALS);
dec_length= dec ? dec+1 : 0;
null_value=0;
if (args[0]->result_type() == DECIMAL_RESULT ||
args[0]->result_type() == INT_RESULT)
......@@ -1899,7 +1948,7 @@ String *Item_func_format::val_str(String *str)
res= args[0]->val_decimal(&dec_val);
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
my_decimal_round(E_DEC_FATAL_ERROR, res, decimals, false, &rnd_dec);
my_decimal_round(E_DEC_FATAL_ERROR, res, dec, false, &rnd_dec);
my_decimal2string(E_DEC_FATAL_ERROR, &rnd_dec, 0, 0, 0, str);
str_length= str->length();
if (rnd_dec.sign())
......@@ -1910,9 +1959,9 @@ String *Item_func_format::val_str(String *str)
double nr= args[0]->val_real();
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
nr= my_double_round(nr, decimals, FALSE);
nr= my_double_round(nr, dec, FALSE);
/* Here default_charset() is right as this is not an automatic conversion */
str->set_real(nr,decimals, default_charset());
str->set_real(nr, dec, default_charset());
if (isnan(nr))
return str;
str_length=str->length();
......@@ -1920,13 +1969,13 @@ String *Item_func_format::val_str(String *str)
str_length--; // Don't count sign
}
/* We need this test to handle 'nan' values */
if (str_length >= dec+4)
if (str_length >= dec_length+4)
{
char *tmp,*pos;
length= str->length()+(diff=((int)(str_length- dec-1))/3);
length= str->length()+(diff=((int)(str_length- dec_length-1))/3);
str= copy_if_not_alloced(&tmp_str,str,length);
str->length(length);
tmp= (char*) str->ptr()+length - dec-1;
tmp= (char*) str->ptr()+length - dec_length-1;
for (pos= (char*) str->ptr()+length-1; pos != tmp; pos--)
pos[0]= pos[-diff];
while (diff)
......@@ -1950,12 +1999,8 @@ void Item_func_format::print(String *str)
{
str->append(STRING_WITH_LEN("format("));
args[0]->print(str);
str->append(',');
// my_charset_bin is good enough for numbers
char buffer[20];
String st(buffer, sizeof(buffer), &my_charset_bin);
st.set((ulonglong)decimals, &my_charset_bin);
str->append(st);
str->append(',');
args[1]->print(str);
str->append(')');
}
......
......@@ -361,11 +361,9 @@ class Item_func_encrypt :public Item_str_func
class Item_func_encode :public Item_str_func
{
protected:
SQL_CRYPT sql_crypt;
public:
Item_func_encode(Item *a, char *seed):
Item_str_func(a),sql_crypt(seed) {}
Item_func_encode(Item *a, Item *seed):
Item_str_func(a, seed) {}
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "encode"; }
......@@ -375,7 +373,7 @@ class Item_func_encode :public Item_str_func
class Item_func_decode :public Item_func_encode
{
public:
Item_func_decode(Item *a, char *seed): Item_func_encode(a,seed) {}
Item_func_decode(Item *a, Item *seed): Item_func_encode(a, seed) {}
String *val_str(String *);
const char *func_name() const { return "decode"; }
};
......@@ -508,15 +506,9 @@ class Item_func_format :public Item_str_func
{
String tmp_str;
public:
Item_func_format(Item *org,int dec);
Item_func_format(Item *org, Item *dec);
String *val_str(String *);
void fix_length_and_dec()
{
collation.set(default_charset());
uint char_length= args[0]->max_length/args[0]->collation.collation->mbmaxlen;
max_length= ((char_length + (char_length-args[0]->decimals)/3) *
collation.collation->mbmaxlen);
}
void fix_length_and_dec();
const char *func_name() const { return "format"; }
void print(String *);
};
......
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