Drizzled Public API Documentation

cache_row.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 
00031 void Item_cache_row::make_field(SendField *)
00032 {
00033   illegal_method_call((const char*)"make_field");
00034 }
00035 
00036 
00037 double Item_cache_row::val_real()
00038 {
00039   illegal_method_call((const char*)"val");
00040   return 0;
00041 }
00042 
00043 
00044 int64_t Item_cache_row::val_int()
00045 {
00046   illegal_method_call((const char*)"val_int");
00047   return 0;
00048 }
00049 
00050 
00051 String *Item_cache_row::val_str(String *)
00052 {
00053   illegal_method_call((const char*)"val_str");
00054   return 0;
00055 }
00056 
00057 
00058 type::Decimal *Item_cache_row::val_decimal(type::Decimal *)
00059 {
00060   illegal_method_call((const char*)"val_decimal");
00061   return 0;
00062 }
00063 
00064 
00065 enum Item_result Item_cache_row::result_type() const
00066 {
00067   return ROW_RESULT;
00068 }
00069 
00070 
00071 uint32_t Item_cache_row::cols()
00072 {
00073   return item_count;
00074 }
00075 
00076 
00077 Item *Item_cache_row::element_index(uint32_t i)
00078 {
00079   return values[i];
00080 }
00081 
00082 
00083 Item **Item_cache_row::addr(uint32_t i)
00084 {
00085   return (Item **) (values + i);
00086 }
00087 
00088 
00089 bool Item_cache_row::allocate(uint32_t num)
00090 {
00091   item_count= num;
00092   return (!(values=
00093             (Item_cache **) getSession().calloc(sizeof(Item_cache *)*item_count)));
00094 }
00095 
00096 
00097 bool Item_cache_row::setup(Item * item)
00098 {
00099   example= item;
00100   if (!values && allocate(item->cols()))
00101     return 1;
00102   for (uint32_t i= 0; i < item_count; i++)
00103   {
00104     Item *el= item->element_index(i);
00105     Item_cache *tmp;
00106     if (!(tmp= values[i]= Item_cache::get_cache(el)))
00107       return 1;
00108     tmp->setup(el);
00109   }
00110   return 0;
00111 }
00112 
00113 
00114 void Item_cache_row::store(Item * item)
00115 {
00116   null_value= 0;
00117   item->bring_value();
00118   for (uint32_t i= 0; i < item_count; i++)
00119   {
00120     values[i]->store(item->element_index(i));
00121     null_value|= values[i]->null_value;
00122   }
00123 }
00124 
00125 
00126 void Item_cache_row::illegal_method_call(const char *)
00127 {
00128   assert(0);
00129   my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
00130   return;
00131 }
00132 
00133 
00134 bool Item_cache_row::check_cols(uint32_t c)
00135 {
00136   if (c != item_count)
00137   {
00138     my_error(ER_OPERAND_COLUMNS, MYF(0), c);
00139     return 1;
00140   }
00141   return 0;
00142 }
00143 
00144 
00145 bool Item_cache_row::null_inside()
00146 {
00147   for (uint32_t i= 0; i < item_count; i++)
00148   {
00149     if (values[i]->cols() > 1)
00150     {
00151       if (values[i]->null_inside())
00152         return 1;
00153     }
00154     else
00155     {
00156       values[i]->update_null_value();
00157       if (values[i]->null_value)
00158         return 1;
00159     }
00160   }
00161   return 0;
00162 }
00163 
00164 
00165 void Item_cache_row::bring_value()
00166 {
00167   for (uint32_t i= 0; i < item_count; i++)
00168     values[i]->bring_value();
00169   return;
00170 }
00171 
00172 
00173 void Item_cache_row::keep_array()
00174 {
00175   save_array= 1;
00176 }
00177 
00178 
00179 void Item_cache_row::cleanup()
00180 {
00181   Item_cache::cleanup();
00182   if (save_array)
00183     memset(values, 0, item_count*sizeof(Item**));
00184   else
00185     values= 0;
00186   return;
00187 }
00188 
00189 
00190 } /* namespace drizzled */