Drizzled Public API Documentation

elt.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 "elt.h"
00023 
00024 namespace drizzled
00025 {
00026 
00027 void Item_func_elt::fix_length_and_dec()
00028 {
00029   max_length=0;
00030   decimals=0;
00031 
00032   if (agg_arg_charsets(collation, args+1, arg_count-1, MY_COLL_ALLOW_CONV, 1))
00033     return;
00034 
00035   for (uint32_t i= 1 ; i < arg_count ; i++)
00036   {
00037     set_if_bigger(max_length,args[i]->max_length);
00038     set_if_bigger(decimals,args[i]->decimals);
00039   }
00040   maybe_null=1;                                 // NULL if wrong first arg
00041 }
00042 
00043 
00044 double Item_func_elt::val_real()
00045 {
00046   assert(fixed == 1);
00047   uint32_t tmp;
00048   null_value=1;
00049   if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
00050     return 0.0;
00051   double result= args[tmp]->val_real();
00052   null_value= args[tmp]->null_value;
00053   return result;
00054 }
00055 
00056 int64_t Item_func_elt::val_int()
00057 {
00058   assert(fixed == 1);
00059   uint32_t tmp;
00060   null_value=1;
00061   if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
00062     return 0;
00063 
00064   int64_t result= args[tmp]->val_int();
00065   null_value= args[tmp]->null_value;
00066   return result;
00067 }
00068 
00069 
00070 String *Item_func_elt::val_str(String *str)
00071 {
00072   assert(fixed == 1);
00073   uint32_t tmp;
00074   null_value=1;
00075   if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
00076     return NULL;
00077 
00078   String *result= args[tmp]->val_str(str);
00079   if (result)
00080     result->set_charset(collation.collation);
00081   null_value= args[tmp]->null_value;
00082   return result;
00083 }
00084 
00085 } /* namespace drizzled */