~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/int.cc

  • Committer: Jay Pipes
  • Date: 2008-07-17 18:48:58 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080717184858-2mbouxl8xi41gcge
Removed DBUG from CSV and Blackhole storage engines

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
 
22
 
#include <drizzled/charset_info.h>
23
 
#include <drizzled/field.h>
24
 
#include <drizzled/internal/m_string.h>
25
 
#include <drizzled/item/int.h>
26
 
 
27
 
namespace drizzled
28
 
{
29
 
 
30
 
/**
31
 
  Create an item from a string we KNOW points to a valid int64_t
32
 
  end \\0 terminated number string.
33
 
  This is always 'signed'. Unsigned values are created with Item_uint()
34
 
*/
35
 
 
36
 
Item_int::Item_int(const char *str_arg, uint32_t length)
37
 
{
38
 
  char *end_ptr= (char*) str_arg + length;
39
 
  int error;
40
 
  value= internal::my_strtoll10(str_arg, &end_ptr, &error);
41
 
  max_length= (uint32_t) (end_ptr - str_arg);
42
 
  name= (char*) str_arg;
43
 
  fixed= 1;
44
 
}
45
 
 
46
 
type::Decimal *Item_int::val_decimal(type::Decimal *decimal_value)
47
 
{
48
 
  int2_class_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_value);
49
 
  return decimal_value;
50
 
}
51
 
 
52
 
String *Item_int::val_str(String *str)
53
 
{
54
 
  // following assert is redundant, because fixed=1 assigned in constructor
55
 
  assert(fixed == 1);
56
 
  str->set(value, &my_charset_bin);
57
 
  return str;
58
 
}
59
 
 
60
 
void Item_int::print(String *str, enum_query_type)
61
 
{
62
 
  // my_charset_bin is good enough for numbers
63
 
  str_value.set(value, &my_charset_bin);
64
 
  str->append(str_value);
65
 
}
66
 
 
67
 
int Item_int::save_in_field(Field *field, bool)
68
 
{
69
 
  int64_t nr=val_int();
70
 
  if (null_value)
71
 
    return set_field_to_null(field);
72
 
  field->set_notnull();
73
 
  return field->store(nr, unsigned_flag);
74
 
}
75
 
 
76
 
bool Item_int::eq(const Item *arg, bool) const
77
 
{
78
 
  /* No need to check for null value as basic constant can't be NULL */
79
 
  if (arg->basic_const_item() && arg->type() == type())
80
 
  {
81
 
    /*
82
 
      We need to cast off const to call val_int(). This should be OK for
83
 
      a basic constant.
84
 
    */
85
 
    Item *item= (Item*) arg;
86
 
    return item->val_int() == value && item->unsigned_flag == unsigned_flag;
87
 
  }
88
 
  return false;
89
 
}
90
 
 
91
 
 
92
 
} /* namespace drizzled */