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"
28
#include "drizzled/error.h"
29
#include "drizzled/internal/my_sys.h"
30
#include "drizzled/session.h"
31
#include "drizzled/table.h"
32
#include "drizzled/temporal.h"
49
Boolean::Boolean(unsigned char *ptr_arg,
51
unsigned char *null_ptr_arg,
52
unsigned char null_bit_arg,
53
const char *field_name_arg,
54
bool ansi_display_arg) :
55
Field(ptr_arg, len_arg,
60
ansi_display(ansi_display_arg)
64
int Boolean::cmp(const unsigned char *a, const unsigned char *b)
66
return memcmp(a, b, sizeof(unsigned char));
69
int Boolean::store(const char *from, uint32_t length, const CHARSET_INFO * const )
71
ASSERT_COLUMN_MARKED_FOR_WRITE;
78
case 't': case 'T': // PG compatibility
83
case 'f': case 'F': // PG compatibility
88
my_error(ER_INVALID_BOOLEAN_VALUE, MYF(0), from);
92
else if ((length == 5) and (strcasecmp(from, "FALSE") == 0))
96
if ((length == 4) and (strcasecmp(from, "TRUE") == 0))
100
else if ((length == 5) and (strcasecmp(from, "FALSE") == 0))
104
else if ((length == 3) and (strcasecmp(from, "YES") == 0))
108
else if ((length == 2) and (strcasecmp(from, "NO") == 0))
114
my_error(ER_INVALID_BOOLEAN_VALUE, MYF(0), from);
121
int Boolean::store(int64_t nr, bool )
123
ASSERT_COLUMN_MARKED_FOR_WRITE;
124
nr == 0 ? setFalse() : setTrue();
128
int Boolean::store(double nr)
130
ASSERT_COLUMN_MARKED_FOR_WRITE;
131
nr == 0 ? setFalse() : setTrue();
135
int Boolean::store_decimal(const drizzled::my_decimal *dec)
137
ASSERT_COLUMN_MARKED_FOR_WRITE;
138
if (my_decimal_is_zero(dec))
149
void Boolean::sql_type(String &res) const
151
res.set_ascii(STRING_WITH_LEN("boolean"));
154
double Boolean::val_real()
156
ASSERT_COLUMN_MARKED_FOR_READ;
160
int64_t Boolean::val_int()
162
ASSERT_COLUMN_MARKED_FOR_READ;
166
String *Boolean::val_str(String *val_buffer, String *)
168
ASSERT_COLUMN_MARKED_FOR_READ;
169
const CHARSET_INFO * const cs= &my_charset_bin;
170
uint32_t mlength= (5) * cs->mbmaxlen;
172
val_buffer->alloc(mlength);
173
char *buffer=(char*) val_buffer->ptr();
179
memcpy(buffer, "YES", 3);
180
val_buffer->length(3);
184
memcpy(buffer, "TRUE", 4);
185
val_buffer->length(4);
192
memcpy(buffer, "NO", 2);
193
val_buffer->length(2);
197
memcpy(buffer, "FALSE", 5);
198
val_buffer->length(5);
205
my_decimal *Boolean::val_decimal(my_decimal *dec)
209
int2my_decimal(E_DEC_OK, 1, false, dec);
213
my_decimal_set_zero(dec);
218
void Boolean::sort_string(unsigned char *to, uint32_t length_arg)
220
memcpy(to, ptr, length_arg);
223
void Boolean::setTrue()
225
ptr[0]= set_true.byte;
228
} /* namespace field */
229
} /* namespace drizzled */