~drizzle-trunk/drizzle/development

2023.2.1 by Brian Aker
Merge in BOOL type.
1
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 Brian Aker
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; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
21
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
22
#include <config.h>
2023.2.1 by Brian Aker
Merge in BOOL type.
23
#include <algorithm>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
24
#include <drizzled/field/boolean.h>
25
#include <drizzled/type/boolean.h>
26
#include <drizzled/error.h>
27
#include <drizzled/internal/my_sys.h>
28
#include <drizzled/session.h>
29
#include <drizzled/table.h>
30
#include <drizzled/temporal.h>
2023.2.1 by Brian Aker
Merge in BOOL type.
31
2318.6.11 by Olaf van der Spek
Refactor
32
namespace drizzled {
33
namespace field {
2023.2.1 by Brian Aker
Merge in BOOL type.
34
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
35
Boolean::Boolean(unsigned char *ptr_arg,
36
                 uint32_t len_arg,
37
                 unsigned char *null_ptr_arg,
38
                 unsigned char null_bit_arg,
39
                 const char *field_name_arg,
40
                 bool ansi_display_arg) :
2023.2.1 by Brian Aker
Merge in BOOL type.
41
  Field(ptr_arg, len_arg,
42
        null_ptr_arg,
43
        null_bit_arg,
44
        Field::NONE,
45
        field_name_arg),
46
  ansi_display(ansi_display_arg)
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
47
  {
2187.3.6 by Monty Taylor
Actually differentiate with the flag and fix up client output properly.
48
    if (ansi_display)
49
      flags|= UNSIGNED_FLAG;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
50
  }
2023.2.1 by Brian Aker
Merge in BOOL type.
51
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
52
int Boolean::cmp(const unsigned char *a, const unsigned char *b)
2023.2.1 by Brian Aker
Merge in BOOL type.
53
{ 
54
  return memcmp(a, b, sizeof(unsigned char));
55
}
56
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
57
int Boolean::store(const char *from, uint32_t length, const charset_info_st * const )
2023.2.1 by Brian Aker
Merge in BOOL type.
58
{
59
  ASSERT_COLUMN_MARKED_FOR_WRITE;
60
2136.3.2 by Brian Aker
Merge in boolean convert function so we use the same code for conversion.
61
  bool result;
62
  if (not type::convert(result, from, length))
2023.2.1 by Brian Aker
Merge in BOOL type.
63
  {
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
64
    my_error(ER_INVALID_BOOLEAN_VALUE, MYF(0), from);
2136.3.2 by Brian Aker
Merge in boolean convert function so we use the same code for conversion.
65
    return 1;
66
  }
2318.6.11 by Olaf van der Spek
Refactor
67
  set(result);
2023.2.1 by Brian Aker
Merge in BOOL type.
68
  return 0;
69
}
70
2318.6.11 by Olaf van der Spek
Refactor
71
int Boolean::store(int64_t nr, bool)
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
72
{
73
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2318.6.17 by Olaf van der Spek
Silly icc
74
  set(nr != 0);
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
75
  return 0;
76
}
77
78
int  Boolean::store(double nr)
79
{
80
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2318.6.11 by Olaf van der Spek
Refactor
81
  set(nr);
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
82
  return 0;
83
}
84
2030.1.4 by Brian Aker
Change my_decimal to Decimal
85
int Boolean::store_decimal(const drizzled::type::Decimal *dec)
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
86
{
87
  ASSERT_COLUMN_MARKED_FOR_WRITE;
2318.6.11 by Olaf van der Spek
Refactor
88
  set(not dec->isZero());
2023.2.3 by Brian Aker
Merge in fixes for DD to make use of BOOLEAN as a type.
89
  return 0;
2023.2.1 by Brian Aker
Merge in BOOL type.
90
}
91
2181.2.1 by Brian Aker
Protect all of the val_* methods from modification.
92
double Boolean::val_real() const
93
{
94
  ASSERT_COLUMN_MARKED_FOR_READ;
95
  return isTrue();
96
}
97
98
int64_t Boolean::val_int() const
99
{
100
  ASSERT_COLUMN_MARKED_FOR_READ;
101
  return isTrue();
102
}
103
104
String *Boolean::val_str(String *val_buffer, String *) const
2023.2.1 by Brian Aker
Merge in BOOL type.
105
{
106
  ASSERT_COLUMN_MARKED_FOR_READ;
2318.7.7 by Olaf van der Spek
Refactor type::Boolean::convert
107
  type::convert(*val_buffer, isTrue(), ansi_display);
2023.2.1 by Brian Aker
Merge in BOOL type.
108
  return val_buffer;
109
}
110
2181.2.1 by Brian Aker
Protect all of the val_* methods from modification.
111
type::Decimal *Boolean::val_decimal(type::Decimal *dec) const
2023.2.3 by Brian Aker
Merge in fixes for DD to make use of BOOLEAN as a type.
112
{
113
  if (isTrue())
114
  {
2030.1.3 by Brian Aker
Second pass through function names.
115
    int2_class_decimal(E_DEC_OK, 1, false, dec);
2023.2.3 by Brian Aker
Merge in fixes for DD to make use of BOOLEAN as a type.
116
    return dec;
117
  }
2034.2.4 by Brian Aker
Further encapsulation for DECIMAL.
118
  dec->set_zero();
2023.2.3 by Brian Aker
Merge in fixes for DD to make use of BOOLEAN as a type.
119
  return dec;
120
}
121
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
122
void Boolean::sort_string(unsigned char *to, uint32_t length_arg)
2023.2.1 by Brian Aker
Merge in BOOL type.
123
{
124
  memcpy(to, ptr, length_arg);
125
}
126
127
} /* namespace field */
128
} /* namespace drizzled */