Drizzled Public API Documentation

row.cc
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #include <config.h>
00017 #include <drizzled/error.h>
00018 #include <drizzled/session.h>
00019 #include <drizzled/item/row.h>
00020 
00021 namespace drizzled {
00022 
00037 Item_row::Item_row(List<Item> &arg):
00038   Item(), used_tables_cache(0), const_item_cache(1), with_null(0)
00039 {
00040 
00041   //TODO: think placing 2-3 component items in item (as it done for function)
00042   if ((arg_count= arg.size()))
00043     items= (Item**) memory::sql_alloc(sizeof(Item*)*arg_count);
00044   else
00045     items= 0;
00046   List<Item>::iterator li(arg.begin());
00047   uint32_t i= 0;
00048   while (Item* item= li++)
00049   {
00050     items[i]= item;
00051     i++;
00052   }
00053 }
00054 
00055 void Item_row::illegal_method_call(const char *)
00056 {
00057   assert(false);
00058   my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
00059 }
00060 
00061 bool Item_row::fix_fields(Session *session, Item **)
00062 {
00063   assert(fixed == 0);
00064   null_value= 0;
00065   maybe_null= 0;
00066   Item **arg, **arg_end;
00067   for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
00068   {
00069     if ((*arg)->fix_fields(session, arg))
00070       return true;
00071     // we can't assign 'item' before, because fix_fields() can change arg
00072     Item *item= *arg;
00073     used_tables_cache |= item->used_tables();
00074     const_item_cache&= item->const_item() && !with_null;
00075     if (const_item_cache)
00076     {
00077       if (item->cols() > 1)
00078   with_null|= item->null_inside();
00079       else
00080       {
00081   if (item->is_null())
00082           with_null|= 1;
00083       }
00084     }
00085     maybe_null|= item->maybe_null;
00086     with_sum_func= with_sum_func || item->with_sum_func;
00087   }
00088   fixed= 1;
00089   return false;
00090 }
00091 
00092 
00093 void Item_row::cleanup()
00094 {
00095   Item::cleanup();
00096   /* Reset to the original values */
00097   used_tables_cache= 0;
00098   const_item_cache= true;
00099   with_null= 0;
00100 
00101   return;
00102 }
00103 
00104 
00105 void Item_row::split_sum_func(Session *session, Item **ref_pointer_array,
00106                               List<Item> &fields)
00107 {
00108   Item **arg, **arg_end;
00109   for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
00110     (*arg)->split_sum_func(session, ref_pointer_array, fields, arg, true);
00111 }
00112 
00113 
00114 void Item_row::update_used_tables()
00115 {
00116   used_tables_cache= 0;
00117   const_item_cache= true;
00118   for (uint32_t i= 0; i < arg_count; i++)
00119   {
00120     items[i]->update_used_tables();
00121     used_tables_cache|= items[i]->used_tables();
00122     const_item_cache&= items[i]->const_item();
00123   }
00124 }
00125 
00126 void Item_row::fix_after_pullout(Select_Lex *new_parent, Item **)
00127 {
00128   used_tables_cache= 0;
00129   const_item_cache= true;
00130   for (uint32_t i= 0; i < arg_count; i++)
00131   {
00132     items[i]->fix_after_pullout(new_parent, &items[i]);
00133     used_tables_cache|= items[i]->used_tables();
00134     const_item_cache&= items[i]->const_item();
00135   }
00136 }
00137 
00138 bool Item_row::check_cols(uint32_t c)
00139 {
00140   if (c != arg_count)
00141   {
00142     my_error(ER_OPERAND_COLUMNS, MYF(0), c);
00143     return 1;
00144   }
00145   return 0;
00146 }
00147 
00148 void Item_row::print(String *str)
00149 {
00150   str->append('(');
00151   for (uint32_t i= 0; i < arg_count; i++)
00152   {
00153     if (i)
00154       str->append(',');
00155     items[i]->print(str);
00156   }
00157   str->append(')');
00158 }
00159 
00160 
00161 bool Item_row::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
00162 {
00163   for (uint32_t i= 0; i < arg_count; i++)
00164   {
00165     if (items[i]->walk(processor, walk_subquery, arg))
00166       return 1;
00167   }
00168   return (this->*processor)(arg);
00169 }
00170 
00171 
00172 Item *Item_row::transform(Item_transformer transformer, unsigned char *arg)
00173 {
00174   for (uint32_t i= 0; i < arg_count; i++)
00175   {
00176     Item *new_item= items[i]->transform(transformer, arg);
00177     if (!new_item)
00178       return 0;
00179       items[i]= new_item;
00180   }
00181   return (this->*transformer)(arg);
00182 }
00183 
00184 void Item_row::bring_value()
00185 {
00186   for (uint32_t i= 0; i < arg_count; i++)
00187     items[i]->bring_value();
00188 }
00189 
00190 } /* namespace drizzled */