fixed printability of Items (all items except subselects)

(SCRUM) (WL#1274)
parent d6d6c5e1
......@@ -474,9 +474,19 @@ String *Item_real::val_str(String *str)
void Item_string::print(String *str)
{
str->append('_');
str->append(collation.collation->csname);
if (varbin)
{
str->append(' ');
str->append(full_name());
}
else
{
str->append('\'');
str->append(full_name());
str->append('\'');
}
}
bool Item_null::eq(const Item *item, bool binary_cmp) const
......
......@@ -449,9 +449,11 @@ public:
class Item_string :public Item
{
bool varbin;
public:
Item_string(const char *str,uint length,
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
:varbin(0)
{
collation.set(cs, dv);
str_value.set(str,length,cs);
......@@ -461,6 +463,7 @@ public:
}
Item_string(const char *name_par, const char *str, uint length,
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
:varbin(0)
{
collation.set(cs, dv);
str_value.set(str,length,cs);
......@@ -494,6 +497,7 @@ public:
}
String *const_string() { return &str_value; }
inline void append(char *str, uint length) { str_value.append(str, length); }
inline void set_varbin_name(char *nm) { name= nm; varbin= 1; }
void print(String *str);
};
......@@ -646,7 +650,7 @@ public:
bool get_date(TIME *ltime, bool fuzzydate);
void print(String *str)
{
str->append("ref_null_helper(");
str->append("<ref_null_helper>(");
if (ref && *ref)
(*ref)->print(str);
else
......@@ -664,6 +668,12 @@ public:
:Item_ref_null_helper(master, &store, table_name_par, field_name_par),
store(item)
{}
void print(String *str)
{
str->append("<null_helper>(");
store->print(str);
str->append(')');
}
};
/*
......
......@@ -704,6 +704,18 @@ longlong Item_func_between::val_int()
return 0;
}
void Item_func_between::print(String *str)
{
str->append('(');
args[0]->print(str);
str->append(" between ");
args[1]->print(str);
str->append(" and ");
args[2]->print(str);
str->append(')');
}
void
Item_func_ifnull::fix_length_and_dec()
{
......@@ -1097,7 +1109,27 @@ void Item_func_case::fix_length_and_dec()
void Item_func_case::print(String *str)
{
str->append("case "); // Not yet complete
str->append("(case ");
if (first_expr_num != -1)
{
args[first_expr_num]->print(str);
str->append(' ');
}
for (uint i=0 ; i < ncases ; i+=2)
{
str->append("when ");
args[i]->print(str);
str->append(" then ");
args[i+1]->print(str);
str->append(' ');
}
if (else_expr_num != -1)
{
str->append("else ");
args[else_expr_num]->print(str);
str->append(' ');
}
str->append("end)");
}
/*
......@@ -1504,8 +1536,15 @@ void Item_func_in::fix_length_and_dec()
void Item_func_in::print(String *str)
{
str->append('(');
Item_func::print(str);
str->append(')');
args[0]->print(str);
str->append(" IN (");
for (uint i=1 ; i < arg_count ; i++)
{
if (i > 1)
str->append(',');
args[i]->print(str);
}
str->append("))");
}
......@@ -1866,12 +1905,21 @@ void Item_is_not_null_test::update_used_tables()
}
}
longlong Item_func_isnotnull::val_int()
{
return args[0]->is_null() ? 0 : 1;
}
void Item_func_isnotnull::print(String *str)
{
str->append('(');
args[0]->print(str);
str->append(" is not null)");
}
longlong Item_func_like::val_int()
{
String* res = args[0]->val_str(&tmp_value1);
......
......@@ -105,7 +105,7 @@ public:
Item_in_optimizer return NULL, else it evaluate Item_in_subselect.
*/
longlong val_int();
const char *func_name() const { return "IN_OPTIMIZER"; }
const char *func_name() const { return "<in_optimizer>"; }
Item_cache **get_cache() { return &cache; }
};
......@@ -262,6 +262,7 @@ public:
enum Functype functype() const { return BETWEEN; }
const char *func_name() const { return "between"; }
void fix_length_and_dec();
void print(String *str);
};
......@@ -704,7 +705,7 @@ public:
{}
enum Functype functype() const { return ISNOTNULLTEST_FUNC; }
longlong val_int();
const char *func_name() const { return "is_not_null_test"; }
const char *func_name() const { return "<is_not_null_test>"; }
void update_used_tables();
};
......@@ -722,6 +723,7 @@ public:
const char *func_name() const { return "isnotnull"; }
optimize_type select_optimize() const { return OPTIMIZE_NULL; }
table_map not_null_tables() const { return 0; }
void print(String *str);
};
......@@ -775,6 +777,7 @@ public:
longlong val_int();
bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref);
const char *func_name() const { return "regex"; }
void print(String *str) { print_op(str); }
};
#else
......@@ -785,6 +788,7 @@ public:
Item_func_regex(Item *a,Item *b) :Item_bool_func(a,b) {}
longlong val_int() { return 0;}
const char *func_name() const { return "regex"; }
void print(String *str) { print_op(str); }
};
#endif /* USE_REGEX */
......
......@@ -462,6 +462,24 @@ String *Item_num_op::val_str(String *str)
}
void Item_func_signed::print(String *str)
{
str->append("cast(");
args[0]->print(str);
str->append("as signed)");
}
void Item_func_unsigned::print(String *str)
{
str->append("cast(");
args[0]->print(str);
str->append("as unsigned)");
}
double Item_func_plus::val()
{
double value=args[0]->val()+args[1]->val();
......@@ -2762,6 +2780,26 @@ double Item_func_match::val()
DBUG_RETURN(ft_handler->please->find_relevance(ft_handler, record, 0));
}
void Item_func_match::print(String *str)
{
str->append("(match ");
List_iterator_fast<Item> li(fields);
Item *item;
bool first= 1;
while ((item= li++))
{
if (first)
first= 0;
else
str->append(',');
item->print(str);
}
str->append(" against (");
args[0]->print(str);
if (mode == FT_BOOL)
str->append(" in boolean mode");
str->append("))");
}
longlong Item_func_bit_xor::val_int()
{
......
......@@ -214,6 +214,7 @@ public:
longlong val_int() { return args[0]->val_int(); }
void fix_length_and_dec()
{ max_length=args[0]->max_length; unsigned_flag=0; }
void print(String *str);
};
......@@ -225,6 +226,7 @@ public:
longlong val_int() { return args[0]->val_int(); }
void fix_length_and_dec()
{ max_length=args[0]->max_length; unsigned_flag=1; }
void print(String *str);
};
......@@ -662,6 +664,7 @@ public:
longlong val_int();
const char *func_name() const { return "|"; }
void fix_length_and_dec() { unsigned_flag=1; }
void print(String *str) { print_op(str); }
};
class Item_func_bit_and :public Item_int_func
......@@ -671,6 +674,7 @@ public:
longlong val_int();
const char *func_name() const { return "&"; }
void fix_length_and_dec() { unsigned_flag=1; }
void print(String *str) { print_op(str); }
};
class Item_func_bit_count :public Item_int_func
......@@ -689,6 +693,7 @@ public:
longlong val_int();
const char *func_name() const { return "<<"; }
void fix_length_and_dec() { unsigned_flag=1; }
void print(String *str) { print_op(str); }
};
class Item_func_shift_right :public Item_int_func
......@@ -697,6 +702,7 @@ public:
Item_func_shift_right(Item *a,Item *b) :Item_int_func(a,b) {}
longlong val_int();
const char *func_name() const { return ">>"; }
void print(String *str) { print_op(str); }
};
class Item_func_bit_neg :public Item_int_func
......@@ -996,6 +1002,7 @@ public:
bool eq(const Item *, bool binary_cmp) const;
longlong val_int() { return val()!=0.0; }
double val();
void print(String *str);
bool fix_index();
void init_search(bool no_order);
......@@ -1031,6 +1038,7 @@ public:
longlong val_int();
const char *func_name() const { return "^"; }
void fix_length_xor_dec() { unsigned_flag=1; }
void print(String *str) { print_op(str); }
};
class Item_func_is_free_lock :public Item_int_func
......
......@@ -118,6 +118,7 @@ public:
case SP_EXTERIORRING:
return "exteriorring";
default:
DBUG_ASSERT(0); // Should never happened
return "spatial_decomp_unknown";
}
}
......@@ -142,6 +143,7 @@ public:
case SP_INTERIORRINGN:
return "interiorringn";
default:
DBUG_ASSERT(0); // Should never happened
return "spatial_decomp_n_unknown";
}
}
......@@ -210,6 +212,7 @@ public:
case SP_OVERLAPS_FUNC:
return "overlaps";
default:
DBUG_ASSERT(0); // Should never happened
return "sp_unknown";
}
}
......
......@@ -118,6 +118,18 @@ bool Item_row::check_cols(uint c)
return 0;
}
void Item_row::print(String *str)
{
str->append('(');
for (uint i= 0; i < arg_count; i++)
{
if (i)
str->append(',');
items[i]->print(str);
}
str->append(')');
}
bool Item_row::walk(Item_processor processor, byte *arg)
{
for (uint i= 0; i < arg_count; i++)
......
......@@ -68,6 +68,7 @@ public:
bool const_item() const { return const_item_cache; };
enum Item_result result_type() const { return ROW_RESULT; }
void update_used_tables();
void print(String *str);
bool walk(Item_processor processor, byte *arg);
......
......@@ -2269,6 +2269,14 @@ String *Item_func_hex::val_str(String *str)
}
void Item_func_binary::print(String *str)
{
str->append("cast(");
args[0]->print(str);
str->append("as binary)");
}
#include <my_dir.h> // For my_stat
String *Item_load_file::val_str(String *str)
......
......@@ -120,6 +120,7 @@ public:
Item_func_reverse(Item *a) :Item_str_func(a) {}
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "reverse"; }
};
......@@ -324,10 +325,12 @@ public:
Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b) {}
String *val_str(String *);
void fix_length_and_dec() { maybe_null=1; max_length = 13; }
const char *func_name() const { return "ecrypt"; }
};
#include "sql_crypt.h"
class Item_func_encode :public Item_str_func
{
protected:
......@@ -337,13 +340,16 @@ public:
Item_str_func(a),sql_crypt(seed) {}
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "encode"; }
};
class Item_func_decode :public Item_func_encode
{
public:
Item_func_decode(Item *a, char *seed): Item_func_encode(a,seed) {}
String *val_str(String *);
const char *func_name() const { return "decode"; }
};
......@@ -520,7 +526,6 @@ class Item_func_binary :public Item_str_func
{
public:
Item_func_binary(Item *a) :Item_str_func(a) {}
const char *func_name() const { return "binary"; }
String *val_str(String *a)
{
String *tmp=args[0]->val_str(a);
......@@ -534,7 +539,7 @@ public:
collation.set(&my_charset_bin);
max_length=args[0]->max_length;
}
void print(String *str) { print_op(str); }
void print(String *str);
};
......
......@@ -1343,6 +1343,14 @@ longlong Item_sum_count_distinct::val_int()
return table->file->records;
}
void Item_sum_count_distinct::print(String *str)
{
str->append("count(distinct ");
args[0]->print(str);
str->append(')');
}
/****************************************************************************
** Functions to handle dynamic loadable aggregates
** Original source by: Alexis Mikhailov <root@medinf.chuvashia.su>
......@@ -1936,3 +1944,28 @@ String* Item_func_group_concat::val_str(String* str)
}
return &result;
}
void Item_func_group_concat::print(String *str)
{
str->append("group concat(");
if (distinct)
str->append(" distinct ");
for (uint i= 0; i < arg_count; i++)
{
if (i)
str->append(',');
args[i]->print(str);
}
if (arg_count_order)
{
for (uint i= 0 ; i < arg_count_order ; i++)
{
if (i)
str->append(',');
(*order[i]->item)->print(str);
}
}
str->append(" seperator \'");
str->append(*separator);
str->append("\')");
}
......@@ -238,6 +238,7 @@ class Item_sum_count_distinct :public Item_sum_int
void make_unique();
Item *copy_or_same(THD* thd);
void no_rows_in_result() {}
void print(String *str);
};
......@@ -736,4 +737,5 @@ class Item_func_group_concat : public Item_sum
String* val_str(String* str);
Item *copy_or_same(THD* thd);
void no_rows_in_result() {}
void print(String *str);
};
......@@ -1359,6 +1359,35 @@ longlong Item_date_add_interval::val_int()
((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second;
}
static const char *interval_names[]=
{
"year", "month", "day", "hour", "minute",
"second", "microsecond", "year_month",
"day_hour", "day_minute", "day_second",
"hour_minute", "hour_second", "minute_second",
"day_microsecond", "hour_microsecond",
"minute_microsecond", "second_microsecond"
};
void Item_date_add_interval::print(String *str)
{
str->append('(');
args[0]->print(str);
str->append(date_sub_interval?" - interval ":" + interval ");
args[1]->print(str);
str->append(interval_names[int_type]);
str->append(')');
}
void Item_extract::print(String *str)
{
str->append("extract(");
str->append(interval_names[int_type]);
str->append(' ');
args[0]->print(str);
str->append(')');
}
void Item_extract::fix_length_and_dec()
{
value.alloc(32); // alloc buffer
......@@ -1467,10 +1496,31 @@ bool Item_extract::eq(const Item *item, bool binary_cmp) const
void Item_typecast::print(String *str)
{
str->append("CAST(");
str->append("cast(");
args[0]->print(str);
str->append(" AS ");
str->append(func_name());
str->append(" as ");
str->append(cast_type());
str->append(')');
}
void Item_char_typecast::print(String *str)
{
str->append("cast(");
args[0]->print(str);
str->append(" as char");
if (cast_length >= 0)
{
str->append('(');
char buff[10];
snprintf(buff, 10, "%d", cast_length);
str->append(buff);
str->append(')');
}
if (cast_cs)
{
str->append(" charset ");
str->append(cast_cs->name);
}
str->append(')');
}
......@@ -1740,6 +1790,28 @@ null_date:
return 0;
}
void Item_func_add_time::print(String *str)
{
if (is_date)
{
DBUG_ASSERT(sign > 0);
str->append("timestamp(");
}
else
{
if (sign > 0)
str->append("addtime(");
else
str->append("subtime(");
}
args[0]->print(str);
str->append(',');
args[0]->print(str);
str->append(')');
}
/*
TIMEDIFF(t,s) is a time function that calculates the
time value between a start and end time.
......
......@@ -544,13 +544,13 @@ public:
enum interval_type
{
INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY, INTERVAL_HOUR, INTERVAL_MINUTE,
INTERVAL_SECOND, INTERVAL_MICROSECOND ,INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR,
INTERVAL_DAY_MINUTE, INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE,
INTERVAL_HOUR_SECOND, INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND,
INTERVAL_HOUR_MICROSECOND, INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND
INTERVAL_SECOND, INTERVAL_MICROSECOND ,INTERVAL_YEAR_MONTH,
INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE, INTERVAL_DAY_SECOND,
INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND, INTERVAL_MINUTE_SECOND,
INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND,
INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND
};
class Item_date_add_interval :public Item_date_func
{
const interval_type int_type;
......@@ -568,6 +568,7 @@ public:
double val() { return (double) val_int(); }
longlong val_int();
bool get_date(TIME *res,bool fuzzy_date);
void print(String *str);
};
......@@ -583,6 +584,7 @@ class Item_extract :public Item_int_func
const char *func_name() const { return "extract"; }
void fix_length_and_dec();
bool eq(const Item *item, bool binary_cmp) const;
void print(String *str);
};
......@@ -590,7 +592,6 @@ class Item_typecast :public Item_str_func
{
public:
Item_typecast(Item *a) :Item_str_func(a) {}
const char *func_name() const { return "char"; }
String *val_str(String *a)
{
String *tmp=args[0]->val_str(a);
......@@ -604,6 +605,7 @@ public:
collation.set(default_charset());
max_length=args[0]->max_length;
}
virtual const char* cast_type() const= 0;
void print(String *str);
};
......@@ -617,8 +619,10 @@ class Item_char_typecast :public Item_typecast
public:
Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg)
:Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {}
const char* cast_type() const { return "char"; };
String *val_str(String *a);
void fix_length_and_dec();
void print(String *str);
};
......@@ -628,7 +632,7 @@ public:
Item_date_typecast(Item *a) :Item_typecast(a) {}
String *val_str(String *str);
bool get_date(TIME *ltime, bool fuzzy_date);
const char *func_name() const { return "date"; }
const char *cast_type() const { return "date"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
Field *tmp_table_field(TABLE *t_arg)
{
......@@ -643,7 +647,7 @@ public:
Item_time_typecast(Item *a) :Item_typecast(a) {}
String *val_str(String *str);
bool get_time(TIME *ltime);
const char *func_name() const { return "time"; }
const char *cast_type() const { return "time"; }
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
Field *tmp_table_field(TABLE *t_arg)
{
......@@ -657,7 +661,7 @@ class Item_datetime_typecast :public Item_typecast
public:
Item_datetime_typecast(Item *a) :Item_typecast(a) {}
String *val_str(String *str);
const char *func_name() const { return "datetime"; }
const char *cast_type() const { return "datetime"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
Field *tmp_table_field(TABLE *t_arg)
{
......@@ -694,7 +698,6 @@ public:
Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg)
:Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; }
String *val_str(String *str);
const char *func_name() const { return "addtime"; }
enum_field_types field_type() const { return cached_field_type; }
void fix_length_and_dec();
......@@ -711,6 +714,7 @@ public:
return (new Field_datetime(maybe_null, name, t_arg, &my_charset_bin));
return (new Field_string(max_length, maybe_null, name, t_arg, &my_charset_bin));
}
void print(String *str);
};
class Item_func_timediff :public Item_str_func
......
......@@ -29,6 +29,7 @@ public:
:Item_real_func(list) {}
double val() { return 0.0; }
void fix_length_and_dec() { decimals=0; max_length=6; }
void print(String *str) { str->append("0.0"); }
};
......@@ -54,4 +55,5 @@ public:
{
return new Item_sum_unique_users(thd, *this);
}
void print(String *str) { str->append("0.0"); }
};
......@@ -2887,7 +2887,9 @@ opt_gorder_clause:
| order_clause
{
LEX *lex=Lex;
lex->gorder_list= (SQL_LIST*) sql_memdup((char*) &lex->current_select->order_list,sizeof(st_sql_list));
lex->gorder_list=
(SQL_LIST*) sql_memdup((char*) &lex->current_select->order_list,
sizeof(st_sql_list));
lex->current_select->order_list.empty();
};
......@@ -4289,8 +4291,11 @@ literal:
{
Item *tmp= new Item_varbinary($2.str,$2.length);
String *str= tmp ? tmp->val_str((String*) 0) : (String*) 0;
$$ = new Item_string(str ? str->ptr() : "", str ? str->length() :
Item_string *item = new Item_string(str ? str->ptr() : "",
str ? str->length() :
0, Lex->charset);
item->set_varbin_name(tmp->name);
$$= item;
}
| DATE_SYM text_literal { $$ = $2; }
| TIME_SYM text_literal { $$ = $2; }
......
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