1
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
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.
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.
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
26
#include <drizzled/field/boolean.h>
27
#include <drizzled/type/boolean.h>
29
#include <drizzled/error.h>
30
#include <drizzled/internal/my_sys.h>
31
#include <drizzled/session.h>
32
#include <drizzled/table.h>
33
#include <drizzled/temporal.h>
50
Boolean::Boolean(unsigned char *ptr_arg,
52
unsigned char *null_ptr_arg,
53
unsigned char null_bit_arg,
54
const char *field_name_arg,
55
bool ansi_display_arg) :
56
Field(ptr_arg, len_arg,
61
ansi_display(ansi_display_arg)
64
flags|= UNSIGNED_FLAG;
67
int Boolean::cmp(const unsigned char *a, const unsigned char *b)
69
return memcmp(a, b, sizeof(unsigned char));
72
int Boolean::store(const char *from, uint32_t length, const CHARSET_INFO * const )
74
ASSERT_COLUMN_MARKED_FOR_WRITE;
77
if (not type::convert(result, from, length))
79
my_error(ER_INVALID_BOOLEAN_VALUE, MYF(0), from);
95
int Boolean::store(int64_t nr, bool )
97
ASSERT_COLUMN_MARKED_FOR_WRITE;
98
nr == 0 ? setFalse() : setTrue();
102
int Boolean::store(double nr)
104
ASSERT_COLUMN_MARKED_FOR_WRITE;
105
nr == 0 ? setFalse() : setTrue();
109
int Boolean::store_decimal(const drizzled::type::Decimal *dec)
111
ASSERT_COLUMN_MARKED_FOR_WRITE;
123
void Boolean::sql_type(String &res) const
125
res.set_ascii(STRING_WITH_LEN("boolean"));
128
double Boolean::val_real() const
130
ASSERT_COLUMN_MARKED_FOR_READ;
134
int64_t Boolean::val_int() const
136
ASSERT_COLUMN_MARKED_FOR_READ;
140
String *Boolean::val_str(String *val_buffer, String *) const
142
ASSERT_COLUMN_MARKED_FOR_READ;
144
(void)type::convert(*val_buffer, isTrue(), ansi_display);
149
type::Decimal *Boolean::val_decimal(type::Decimal *dec) const
153
int2_class_decimal(E_DEC_OK, 1, false, dec);
162
void Boolean::sort_string(unsigned char *to, uint32_t length_arg)
164
memcpy(to, ptr, length_arg);
167
void Boolean::setTrue()
169
ptr[0]= set_true.byte;
172
} /* namespace field */
173
} /* namespace drizzled */