~ubuntu-branches/ubuntu/trusty/drizzle/trusty

1 by Monty Taylor
Import upstream version 2010.03.1347
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1.2.4 by Monty Taylor
Import upstream version 2010.12.06
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
1 by Monty Taylor
Import upstream version 2010.03.1347
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
1.2.9 by Monty Taylor
Import upstream version 2011.03.11
21
#include <config.h>
1.2.8 by Monty Taylor
Import upstream version 2011.02.10
22
23
#include <drizzled/definitions.h>
24
#include <drizzled/field.h>
25
#include <drizzled/hybrid_type.h>
26
#include <drizzled/hybrid_type_traits_integer.h>
27
#include <drizzled/item.h>
1 by Monty Taylor
Import upstream version 2010.03.1347
28
29
namespace drizzled
30
{
31
32
/* Hybrid_type_traits_integer */
33
static const Hybrid_type_traits_integer integer_traits_instance;
34
35
36
Item_result Hybrid_type_traits_integer::type() const
37
{
38
  return INT_RESULT;
39
}
40
41
42
void
43
Hybrid_type_traits_integer::fix_length_and_dec(Item *item, Item *) const
44
{
45
  item->decimals= 0;
46
  item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
47
  item->unsigned_flag= 0;
48
}
49
50
51
/* Hybrid_type operations. */
52
void Hybrid_type_traits_integer::set_zero(Hybrid_type *val) const
53
{
54
  val->integer= 0;
55
}
56
57
58
void Hybrid_type_traits_integer::add(Hybrid_type *val, Field *f) const
59
{
60
  val->integer+= f->val_int();
61
}
62
63
64
void Hybrid_type_traits_integer::div(Hybrid_type *val, uint64_t u) const
65
{
66
  val->integer/= (int64_t) u;
67
}
68
69
70
int64_t Hybrid_type_traits_integer::val_int(Hybrid_type *val, bool) const
71
{
72
  return val->integer;
73
}
74
75
76
double Hybrid_type_traits_integer::val_real(Hybrid_type *val) const
77
{
78
  return (double) val->integer;
79
}
80
81
11 by Monty Taylor
* Fixed missing build depends.
82
type::Decimal *Hybrid_type_traits_integer::val_decimal(Hybrid_type *val,
83
                                                    type::Decimal *) const
1 by Monty Taylor
Import upstream version 2010.03.1347
84
{
11 by Monty Taylor
* Fixed missing build depends.
85
  int2_class_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
1 by Monty Taylor
Import upstream version 2010.03.1347
86
  return &val->dec_buf[2];
87
}
88
89
90
String *Hybrid_type_traits_integer::val_str(Hybrid_type *val, String *buf,
91
                                            uint8_t) const
92
{
93
  buf->set(val->integer, &my_charset_bin);
94
  return buf;
95
}
96
97
98
const Hybrid_type_traits_integer *Hybrid_type_traits_integer::instance()
99
{
100
  return &integer_traits_instance;
101
}
102
103
104
Hybrid_type_traits_integer::Hybrid_type_traits_integer()
105
{}
106
107
108
} /* namespace drizzled */