summaryrefslogtreecommitdiff
path: root/sql/item.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item.h')
-rw-r--r--sql/item.h78
1 files changed, 50 insertions, 28 deletions
diff --git a/sql/item.h b/sql/item.h
index 584fad9eede..35e5d4a3666 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -125,8 +125,8 @@ public:
top AND/OR ctructure of WHERE clause to protect it of
optimisation changes in prepared statements
*/
- Item(THD *thd, Item &item);
- virtual ~Item() { name=0; cleanup(); } /*lint -e1509 */
+ Item(THD *thd, Item *item);
+ virtual ~Item() { name=0; } /*lint -e1509 */
void set_name(const char *str,uint length, CHARSET_INFO *cs);
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
virtual void cleanup() { fixed=0; }
@@ -205,6 +205,7 @@ public:
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
CHARSET_INFO *default_charset() const;
+ virtual CHARSET_INFO *compare_collation() { return NULL; }
virtual bool walk(Item_processor processor, byte *arg)
{
@@ -231,6 +232,10 @@ public:
/* Used in sql_select.cc:eliminate_not_funcs() */
virtual Item *neg_transformer() { return NULL; }
+ void delete_self()
+ {
+ cleanup();
+ delete this;
};
@@ -339,7 +344,7 @@ public:
st_select_lex *depended_from;
Item_ident(const char *db_name_par,const char *table_name_par,
const char *field_name_par);
- Item_ident(THD *thd, Item_ident &item);
+ Item_ident(THD *thd, Item_ident *item);
const char *full_name() const;
bool remove_dependence_processor(byte * arg);
@@ -358,7 +363,7 @@ public:
:Item_ident(db_par,table_name_par,field_name_par),field(0),result_field(0)
{ collation.set(DERIVATION_IMPLICIT); }
// Constructor need to process subselect with temporary tables (see Item)
- Item_field(THD *thd, Item_field &item);
+ Item_field(THD *thd, Item_field *item);
Item_field(Field *field);
enum Type type() const { return FIELD_ITEM; }
bool eq(const Item *item, bool binary_cmp) const;
@@ -389,6 +394,7 @@ public:
bool get_time(TIME *ltime);
bool is_null() { return field->is_null(); }
Item *get_tmp_table_item(THD *thd);
+ void cleanup();
friend class Item_default_value;
friend class Item_insert_value;
};
@@ -576,7 +582,7 @@ public:
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
{
collation.set(cs, dv);
- str_value.set(str,length,cs);
+ str_value.set_or_copy_aligned(str,length,cs);
/*
We have to have a different max_length than 'length' here to
ensure that we get the right length if we do use the item
@@ -592,12 +598,11 @@ public:
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
{
collation.set(cs, dv);
- str_value.set(str,length,cs);
+ str_value.set_or_copy_aligned(str,length,cs);
max_length= str_value.numchars()*cs->mbmaxlen;
set_name(name_par,0,cs);
decimals=NOT_FIXED_DEC;
}
- ~Item_string() {}
enum Type type() const { return STRING_ITEM; }
double val()
{
@@ -664,7 +669,6 @@ class Item_varbinary :public Item
{
public:
Item_varbinary(const char *str,uint str_length);
- ~Item_varbinary() {}
enum Type type() const { return VARBIN_ITEM; }
double val() { return (double) Item_varbinary::val_int(); }
longlong val_int();
@@ -681,8 +685,8 @@ public:
Field *result_field; /* Save result here */
Item_result_field() :result_field(0) {}
// Constructor used for Item_sum/Item_cond_and/or (see Item comment)
- Item_result_field(THD *thd, Item_result_field &item):
- Item(thd, item), result_field(item.result_field)
+ Item_result_field(THD *thd, Item_result_field *item):
+ Item(thd, item), result_field(item->result_field)
{}
~Item_result_field() {} /* Required with gcc 2.95 */
Field *get_tmp_table_field() { return result_field; }
@@ -701,20 +705,25 @@ public:
class Item_ref :public Item_ident
{
public:
- Field *result_field; /* Save result here */
+ Field *result_field; /* Save result here */
Item **ref;
- Item_ref(const char *db_par, const char *table_name_par,
- const char *field_name_par)
- :Item_ident(db_par,table_name_par,field_name_par),ref(0) {}
- Item_ref(Item **item, const char *table_name_par, const char *field_name_par)
- :Item_ident(NullS,table_name_par,field_name_par),ref(item) {}
+ Item **hook_ptr; /* These two to restore */
+ Item *orig_item; /* things in 'cleanup()' */
+ Item_ref(Item **hook, Item *original,const char *db_par,
+ const char *table_name_par, const char *field_name_par)
+ :Item_ident(db_par,table_name_par,field_name_par),ref(0), hook_ptr(hook),
+ orig_item(original) {}
+ Item_ref(Item **item, Item **hook,
+ const char *table_name_par, const char *field_name_par)
+ :Item_ident(NullS,table_name_par,field_name_par),
+ ref(item), hook_ptr(hook), orig_item(hook ? *hook:0) {}
// Constructor need to process subselect with temporary tables (see Item)
- Item_ref(THD *thd, Item_ref &item)
- :Item_ident(thd, item), ref(item.ref) {}
+ Item_ref(THD *thd, Item_ref *item, Item **hook)
+ :Item_ident(thd, item), ref(item->ref),
+ hook_ptr(hook), orig_item(hook ? *hook : 0) {}
enum Type type() const { return REF_ITEM; }
bool eq(const Item *item, bool binary_cmp) const
{ return ref && (*ref)->eq(item, binary_cmp); }
- ~Item_ref() { if (ref && (*ref) && (*ref) != this) delete *ref; }
double val()
{
double tmp=(*ref)->val_result();
@@ -759,6 +768,7 @@ public:
}
Item *real_item() { return *ref; }
void print(String *str);
+ void cleanup();
};
class Item_in_subselect;
@@ -769,7 +779,7 @@ protected:
public:
Item_ref_null_helper(Item_in_subselect* master, Item **item,
const char *table_name_par, const char *field_name_par):
- Item_ref(item, table_name_par, field_name_par), owner(master) {}
+ Item_ref(item, NULL, table_name_par, field_name_par), owner(master) {}
double val();
longlong val_int();
String* val_str(String* s);
@@ -833,7 +843,6 @@ public:
name=item->name;
cached_field_type= item->field_type();
}
- ~Item_copy_string() { delete item; }
enum Type type() const { return COPY_STR_ITEM; }
enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return cached_field_type; }
@@ -977,13 +986,15 @@ public:
void set_used_tables(table_map map) { used_table_map= map; }
virtual bool allocate(uint i) { return 0; };
- virtual bool setup(Item *item) { example= item; return 0; };
- virtual void store(Item *)= 0;
- void set_len_n_dec(uint32 max_len, uint8 dec)
+ virtual bool setup(Item *item)
{
- max_length= max_len;
- decimals= dec;
- }
+ example= item;
+ max_length= item->max_length;
+ decimals= item->decimals;
+ collation.set(item->collation);
+ return 0;
+ };
+ virtual void store(Item *)= 0;
enum Type type() const { return CACHE_ITEM; }
static Item_cache* get_cache(Item_result type);
table_map used_tables() const { return used_table_map; }
@@ -1008,7 +1019,7 @@ class Item_cache_real: public Item_cache
double value;
public:
Item_cache_real(): Item_cache() {}
-
+
void store(Item *item);
double val() { return value; }
longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5)); }
@@ -1081,6 +1092,11 @@ public:
bool check_cols(uint c);
bool null_inside();
void bring_value();
+ void cleanup()
+ {
+ Item_cache::cleanup();
+ values= 0;
+ }
};
@@ -1091,6 +1107,7 @@ class Item_type_holder: public Item
{
protected:
Item_result item_type;
+ Item_result orig_type;
Field *field_example;
public:
Item_type_holder(THD*, Item*);
@@ -1102,6 +1119,11 @@ public:
String *val_str(String*);
bool join_types(THD *thd, Item *);
Field *example() { return field_example; }
+ void cleanup()
+ {
+ Item::cleanup();
+ item_type= orig_type;
+ }
};