00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <drizzled/error.h>
00023 #include <drizzled/table.h>
00024 #include <drizzled/session.h>
00025
00026 #include <drizzled/item/cache_row.h>
00027
00028 namespace drizzled {
00029
00030 void Item_cache_row::make_field(SendField *)
00031 {
00032 illegal_method_call("make_field");
00033 }
00034
00035 double Item_cache_row::val_real()
00036 {
00037 illegal_method_call("val");
00038 return 0;
00039 }
00040
00041 int64_t Item_cache_row::val_int()
00042 {
00043 illegal_method_call("val_int");
00044 return 0;
00045 }
00046
00047 String *Item_cache_row::val_str(String *)
00048 {
00049 illegal_method_call("val_str");
00050 return 0;
00051 }
00052
00053 type::Decimal *Item_cache_row::val_decimal(type::Decimal *)
00054 {
00055 illegal_method_call("val_decimal");
00056 return 0;
00057 }
00058
00059 enum Item_result Item_cache_row::result_type() const
00060 {
00061 return ROW_RESULT;
00062 }
00063
00064 uint32_t Item_cache_row::cols()
00065 {
00066 return item_count;
00067 }
00068
00069 Item *Item_cache_row::element_index(uint32_t i)
00070 {
00071 return values[i];
00072 }
00073
00074 Item **Item_cache_row::addr(uint32_t i)
00075 {
00076 return (Item **) (values + i);
00077 }
00078
00079 void Item_cache_row::allocate(uint32_t num)
00080 {
00081 item_count= num;
00082 values= (Item_cache **) getSession().mem.calloc(sizeof(Item_cache *)*item_count);
00083 }
00084
00085 bool Item_cache_row::setup(Item * item)
00086 {
00087 example= item;
00088 if (!values)
00089 allocate(item->cols());
00090 for (uint32_t i= 0; i < item_count; i++)
00091 {
00092 Item *el= item->element_index(i);
00093 Item_cache *tmp= values[i]= Item_cache::get_cache(el);
00094 if (!tmp)
00095 return 1;
00096 tmp->setup(el);
00097 }
00098 return 0;
00099 }
00100
00101 void Item_cache_row::store(Item * item)
00102 {
00103 null_value= 0;
00104 item->bring_value();
00105 for (uint32_t i= 0; i < item_count; i++)
00106 {
00107 values[i]->store(item->element_index(i));
00108 null_value|= values[i]->null_value;
00109 }
00110 }
00111
00112 void Item_cache_row::illegal_method_call(const char*)
00113 {
00114 assert(false);
00115 my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
00116 }
00117
00118 bool Item_cache_row::check_cols(uint32_t c)
00119 {
00120 if (c != item_count)
00121 {
00122 my_error(ER_OPERAND_COLUMNS, MYF(0), c);
00123 return 1;
00124 }
00125 return 0;
00126 }
00127
00128 bool Item_cache_row::null_inside()
00129 {
00130 for (uint32_t i= 0; i < item_count; i++)
00131 {
00132 if (values[i]->cols() > 1)
00133 {
00134 if (values[i]->null_inside())
00135 return 1;
00136 }
00137 else
00138 {
00139 values[i]->update_null_value();
00140 if (values[i]->null_value)
00141 return 1;
00142 }
00143 }
00144 return 0;
00145 }
00146
00147 void Item_cache_row::bring_value()
00148 {
00149 for (uint32_t i= 0; i < item_count; i++)
00150 values[i]->bring_value();
00151 return;
00152 }
00153
00154 void Item_cache_row::keep_array()
00155 {
00156 save_array= 1;
00157 }
00158
00159 void Item_cache_row::cleanup()
00160 {
00161 Item_cache::cleanup();
00162 if (save_array)
00163 memset(values, 0, item_count*sizeof(Item**));
00164 else
00165 values= 0;
00166 return;
00167 }
00168
00169 }