Drizzled Public API Documentation

int.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/charset_info.h>
00023 #include <drizzled/field.h>
00024 #include <drizzled/internal/m_string.h>
00025 #include <drizzled/item/int.h>
00026 
00027 namespace drizzled
00028 {
00029 
00036 Item_int::Item_int(const char *str_arg, uint32_t length)
00037 {
00038   char *end_ptr= (char*) str_arg + length;
00039   int error;
00040   value= internal::my_strtoll10(str_arg, &end_ptr, &error);
00041   max_length= (uint32_t) (end_ptr - str_arg);
00042   name= (char*) str_arg;
00043   fixed= 1;
00044 }
00045 
00046 type::Decimal *Item_int::val_decimal(type::Decimal *decimal_value)
00047 {
00048   int2_class_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_value);
00049   return decimal_value;
00050 }
00051 
00052 String *Item_int::val_str(String *str)
00053 {
00054   // following assert is redundant, because fixed=1 assigned in constructor
00055   assert(fixed == 1);
00056   str->set(value, &my_charset_bin);
00057   return str;
00058 }
00059 
00060 void Item_int::print(String *str)
00061 {
00062   // my_charset_bin is good enough for numbers
00063   str_value.set(value, &my_charset_bin);
00064   str->append(str_value);
00065 }
00066 
00067 int Item_int::save_in_field(Field *field, bool)
00068 {
00069   int64_t nr=val_int();
00070   if (null_value)
00071     return set_field_to_null(field);
00072   field->set_notnull();
00073   return field->store(nr, unsigned_flag);
00074 }
00075 
00076 bool Item_int::eq(const Item *arg, bool) const
00077 {
00078   /* No need to check for null value as basic constant can't be NULL */
00079   if (arg->basic_const_item() && arg->type() == type())
00080   {
00081     /*
00082       We need to cast off const to call val_int(). This should be OK for
00083       a basic constant.
00084     */
00085     Item *item= (Item*) arg;
00086     return item->val_int() == value && item->unsigned_flag == unsigned_flag;
00087   }
00088   return false;
00089 }
00090 
00091 
00092 } /* namespace drizzled */