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)
65
int Boolean::cmp(const unsigned char *a, const unsigned char *b)
67
return memcmp(a, b, sizeof(unsigned char));
70
int Boolean::store(const char *from, uint32_t length, const CHARSET_INFO * const )
72
ASSERT_COLUMN_MARKED_FOR_WRITE;
75
if (not type::convert(result, from, length))
77
my_error(ER_INVALID_BOOLEAN_VALUE, MYF(0), from);
93
int Boolean::store(int64_t nr, bool )
95
ASSERT_COLUMN_MARKED_FOR_WRITE;
96
nr == 0 ? setFalse() : setTrue();
100
int Boolean::store(double nr)
102
ASSERT_COLUMN_MARKED_FOR_WRITE;
103
nr == 0 ? setFalse() : setTrue();
107
int Boolean::store_decimal(const drizzled::type::Decimal *dec)
109
ASSERT_COLUMN_MARKED_FOR_WRITE;
121
void Boolean::sql_type(String &res) const
123
res.set_ascii(STRING_WITH_LEN("boolean"));
126
double Boolean::val_real()
128
ASSERT_COLUMN_MARKED_FOR_READ;
132
int64_t Boolean::val_int()
134
ASSERT_COLUMN_MARKED_FOR_READ;
138
String *Boolean::val_str(String *val_buffer, String *)
140
ASSERT_COLUMN_MARKED_FOR_READ;
142
(void)type::convert(*val_buffer, isTrue(), ansi_display);
147
type::Decimal *Boolean::val_decimal(type::Decimal *dec)
151
int2_class_decimal(E_DEC_OK, 1, false, dec);
160
void Boolean::sort_string(unsigned char *to, uint32_t length_arg)
162
memcpy(to, ptr, length_arg);
165
void Boolean::setTrue()
167
ptr[0]= set_true.byte;
170
} /* namespace field */
171
} /* namespace drizzled */