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
00031 class Item_cache: public Item_basic_constant
00032 {
00033 protected:
00034 Item *example;
00035 table_map used_table_map;
00036
00037
00038
00039
00040
00041
00042 Field *cached_field;
00043 enum enum_field_types cached_field_type;
00044 public:
00045 Item_cache():
00046 example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
00047 {
00048 fixed= 1;
00049 null_value= 1;
00050 }
00051 Item_cache(enum_field_types field_type_arg):
00052 example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
00053 {
00054 fixed= 1;
00055 null_value= 1;
00056 }
00057
00058 void set_used_tables(table_map map) { used_table_map= map; }
00059
00060 virtual bool allocate(uint32_t)
00061 { return 0; }
00062 virtual bool setup(Item *item)
00063 {
00064 example= item;
00065 max_length= item->max_length;
00066 decimals= item->decimals;
00067 collation.set(item->collation);
00068 unsigned_flag= item->unsigned_flag;
00069 if (item->type() == FIELD_ITEM)
00070 cached_field= ((Item_field *)item)->field;
00071 return 0;
00072 };
00073 virtual void store(Item *)= 0;
00074 enum Type type() const { return CACHE_ITEM; }
00075 enum_field_types field_type() const { return cached_field_type; }
00076 static Item_cache* get_cache(const Item *item);
00077 table_map used_tables() const { return used_table_map; }
00078 virtual void keep_array() {}
00079 virtual void print(String *str);
00080 bool eq_def(Field *field);
00081 bool eq(const Item *item, bool) const
00082 {
00083 return this == item;
00084 }
00085 bool basic_const_item() const
00086 {
00087 return test(example && example->basic_const_item());
00088 }
00089 };
00090
00091 }
00092