Drizzled Public API Documentation

make_set.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/function/str/make_set.h>
00023 #include <drizzled/session.h>
00024 
00025 namespace drizzled {
00026 
00027 void Item_func_make_set::update_used_tables()
00028 {
00029   Item_func::update_used_tables();
00030   item->update_used_tables();
00031   used_tables_cache|=item->used_tables();
00032   const_item_cache&=item->const_item();
00033 }
00034 
00035 
00036 void Item_func_make_set::split_sum_func(Session *session_arg, Item **ref_pointer_array,
00037           List<Item> &fields)
00038 {
00039   item->split_sum_func(session_arg, ref_pointer_array, fields, &item, true);
00040   Item_str_func::split_sum_func(session_arg, ref_pointer_array, fields);
00041 }
00042 
00043 
00044 void Item_func_make_set::fix_length_and_dec()
00045 {
00046   max_length=arg_count-1;
00047 
00048   if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
00049     return;
00050 
00051   for (uint32_t i=0 ; i < arg_count ; i++)
00052     max_length+=args[i]->max_length;
00053 
00054   used_tables_cache|=   item->used_tables();
00055   not_null_tables_cache&= item->not_null_tables();
00056   const_item_cache&=    item->const_item();
00057   with_sum_func= with_sum_func || item->with_sum_func;
00058 }
00059 
00060 String *Item_func_make_set::val_str(String *str)
00061 {
00062   assert(fixed == 1);
00063   uint64_t bits;
00064   bool first_found=0;
00065   Item **ptr=args;
00066   String *result=&my_empty_string;
00067 
00068   bits=item->val_int();
00069   if ((null_value=item->null_value))
00070     return NULL;
00071 
00072   if (arg_count < 64)
00073     bits &= ((uint64_t) 1 << arg_count)-1;
00074 
00075   for (; bits; bits >>= 1, ptr++)
00076   {
00077     if (bits & 1)
00078     {
00079       String *res= (*ptr)->val_str(str);
00080       if (res)          // Skip nulls
00081       {
00082   if (!first_found)
00083   {         // First argument
00084     first_found=1;
00085     if (res != str)
00086       result=res;       // Use original string
00087     else
00088     {
00089       tmp_str.copy(*res);
00090       result= &tmp_str;
00091     }
00092   }
00093   else
00094   {
00095     if (result != &tmp_str)
00096     {         // Copy data to tmp_str
00097       tmp_str.alloc(result->length()+res->length()+1);
00098       tmp_str.copy(*result);
00099       result= &tmp_str;
00100     }
00101     tmp_str.append(STRING_WITH_LEN(","));
00102     tmp_str.append(*res);
00103   }
00104       }
00105     }
00106   }
00107   return result;
00108 }
00109 
00110 
00111 Item *Item_func_make_set::transform(Item_transformer transformer, unsigned char *arg)
00112 {
00113   Item *new_item= item->transform(transformer, arg);
00114   if (!new_item)
00115     return 0;
00116   item= new_item;
00117   return Item_str_func::transform(transformer, arg);
00118 }
00119 
00120 
00121 void Item_func_make_set::print(String *str)
00122 {
00123   str->append(STRING_WITH_LEN("make_set("));
00124   item->print(str);
00125   if (arg_count)
00126   {
00127     str->append(',');
00128     print_args(str, 0);
00129   }
00130   str->append(')');
00131 }
00132 
00133 } /* namespace drizzled */