00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <drizzled/item/basic_constant.h>
00023 #include <drizzled/item/field.h>
00024 #include <drizzled/item/ident.h>
00025 #include <drizzled/type/decimal.h>
00026 #include <drizzled/util/test.h>
00027
00028 namespace drizzled {
00029
00030 class Item_cache : public Item_basic_constant
00031 {
00032 protected:
00033 Item *example;
00034 table_map used_table_map;
00035
00036
00037
00038
00039
00040
00041 Field *cached_field;
00042 enum enum_field_types cached_field_type;
00043 public:
00044 Item_cache():
00045 example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
00046 {
00047 fixed= 1;
00048 null_value= 1;
00049 }
00050 Item_cache(enum_field_types field_type_arg):
00051 example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
00052 {
00053 fixed= 1;
00054 null_value= 1;
00055 }
00056
00057 void set_used_tables(table_map map) { used_table_map= map; }
00058
00059 virtual void allocate(uint32_t) {};
00060 virtual bool setup(Item *item)
00061 {
00062 example= item;
00063 max_length= item->max_length;
00064 decimals= item->decimals;
00065 collation.set(item->collation);
00066 unsigned_flag= item->unsigned_flag;
00067 if (item->type() == FIELD_ITEM)
00068 cached_field= ((Item_field *)item)->field;
00069 return 0;
00070 };
00071 virtual void store(Item *)= 0;
00072 enum Type type() const { return CACHE_ITEM; }
00073 enum_field_types field_type() const { return cached_field_type; }
00074 static Item_cache* get_cache(const Item *item);
00075 table_map used_tables() const { return used_table_map; }
00076 virtual void keep_array() {}
00077 virtual void print(String *str);
00078 bool eq_def(Field *field);
00079 bool eq(const Item *item, bool) const
00080 {
00081 return this == item;
00082 }
00083 bool basic_const_item() const
00084 {
00085 return test(example && example->basic_const_item());
00086 }
00087 };
00088
00089 }
00090