Drizzled Public API Documentation

int_val.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/type/decimal.h>
00023 #include <drizzled/function/math/int_val.h>
00024 
00025 namespace drizzled
00026 {
00027 
00028 void Item_func_int_val::fix_num_length_and_dec()
00029 {
00030   max_length= args[0]->max_length - (args[0]->decimals ?
00031                                      args[0]->decimals + 1 :
00032                                      0) + 2;
00033   uint32_t tmp= float_length(decimals);
00034   set_if_smaller(max_length,tmp);
00035   decimals= 0;
00036 }
00037 
00038 void Item_func_int_val::find_num_type()
00039 {
00040   switch(hybrid_type= args[0]->result_type())
00041   {
00042   case STRING_RESULT:
00043   case REAL_RESULT:
00044     hybrid_type= REAL_RESULT;
00045     max_length= float_length(decimals);
00046     break;
00047   case INT_RESULT:
00048   case DECIMAL_RESULT:
00049     /*
00050       -2 because in most high position can't be used any digit for int64_t
00051       and one position for increasing value during operation
00052     */
00053     if ((args[0]->max_length - args[0]->decimals) >=
00054         (DECIMAL_LONGLONG_DIGITS - 2))
00055     {
00056       hybrid_type= DECIMAL_RESULT;
00057     }
00058     else
00059     {
00060       unsigned_flag= args[0]->unsigned_flag;
00061       hybrid_type= INT_RESULT;
00062     }
00063     break;
00064   default:
00065     assert(0);
00066   }
00067   return;
00068 }
00069 
00070 } /* namespace drizzled */