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 
00020 #include <drizzled/item/row.h>
00021 
00022 namespace drizzled
00023 {
00024 
00039 Item_row::Item_row(List<Item> &arg):
00040   Item(), used_tables_cache(0), const_item_cache(1), with_null(0)
00041 {
00042 
00043   //TODO: think placing 2-3 component items in item (as it done for function)
00044   if ((arg_count= arg.size()))
00045     items= (Item**) memory::sql_alloc(sizeof(Item*)*arg_count);
00046   else
00047     items= 0;
00048   List<Item>::iterator li(arg.begin());
00049   uint32_t i= 0;
00050   Item *item;
00051   while ((item= li++))
00052   {
00053     items[i]= item;
00054     i++;
00055   }
00056 }
00057 
00058 void Item_row::illegal_method_call(const char *)
00059 {
00060   assert(0);
00061   my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
00062   return;
00063 }
00064 
00065 bool Item_row::fix_fields(Session *session, Item **)
00066 {
00067   assert(fixed == 0);
00068   null_value= 0;
00069   maybe_null= 0;
00070   Item **arg, **arg_end;
00071   for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
00072   {
00073     if ((*arg)->fix_fields(session, arg))
00074       return true;
00075     // we can't assign 'item' before, because fix_fields() can change arg
00076     Item *item= *arg;
00077     used_tables_cache |= item->used_tables();
00078     const_item_cache&= item->const_item() && !with_null;
00079     if (const_item_cache)
00080     {
00081       if (item->cols() > 1)
00082   with_null|= item->null_inside();
00083       else
00084       {
00085   if (item->is_null())
00086           with_null|= 1;
00087       }
00088     }
00089     maybe_null|= item->maybe_null;
00090     with_sum_func= with_sum_func || item->with_sum_func;
00091   }
00092   fixed= 1;
00093   return false;
00094 }
00095 
00096 
00097 void Item_row::cleanup()
00098 {
00099   Item::cleanup();
00100   /* Reset to the original values */
00101   used_tables_cache= 0;
00102   const_item_cache= true;
00103   with_null= 0;
00104 
00105   return;
00106 }
00107 
00108 
00109 void Item_row::split_sum_func(Session *session, Item **ref_pointer_array,
00110                               List<Item> &fields)
00111 {
00112   Item **arg, **arg_end;
00113   for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
00114     (*arg)->split_sum_func(session, ref_pointer_array, fields, arg, true);
00115 }
00116 
00117 
00118 void Item_row::update_used_tables()
00119 {
00120   used_tables_cache= 0;
00121   const_item_cache= true;
00122   for (uint32_t i= 0; i < arg_count; i++)
00123   {
00124     items[i]->update_used_tables();
00125     used_tables_cache|= items[i]->used_tables();
00126     const_item_cache&= items[i]->const_item();
00127   }
00128 }
00129 
00130 void Item_row::fix_after_pullout(Select_Lex *new_parent, Item **)
00131 {
00132   used_tables_cache= 0;
00133   const_item_cache= true;
00134   for (uint32_t i= 0; i < arg_count; i++)
00135   {
00136     items[i]->fix_after_pullout(new_parent, &items[i]);
00137     used_tables_cache|= items[i]->used_tables();
00138     const_item_cache&= items[i]->const_item();
00139   }
00140 }
00141 
00142 bool Item_row::check_cols(uint32_t c)
00143 {
00144   if (c != arg_count)
00145   {
00146     my_error(ER_OPERAND_COLUMNS, MYF(0), c);
00147     return 1;
00148   }
00149   return 0;
00150 }
00151 
00152 void Item_row::print(String *str)
00153 {
00154   str->append('(');
00155   for (uint32_t i= 0; i < arg_count; i++)
00156   {
00157     if (i)
00158       str->append(',');
00159     items[i]->print(str);
00160   }
00161   str->append(')');
00162 }
00163 
00164 
00165 bool Item_row::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
00166 {
00167   for (uint32_t i= 0; i < arg_count; i++)
00168   {
00169     if (items[i]->walk(processor, walk_subquery, arg))
00170       return 1;
00171   }
00172   return (this->*processor)(arg);
00173 }
00174 
00175 
00176 Item *Item_row::transform(Item_transformer transformer, unsigned char *arg)
00177 {
00178   for (uint32_t i= 0; i < arg_count; i++)
00179   {
00180     Item *new_item= items[i]->transform(transformer, arg);
00181     if (!new_item)
00182       return 0;
00183       items[i]= new_item;
00184   }
00185   return (this->*transformer)(arg);
00186 }
00187 
00188 void Item_row::bring_value()
00189 {
00190   for (uint32_t i= 0; i < arg_count; i++)
00191     items[i]->bring_value();
00192 }
00193 
00194 } /* namespace drizzled */