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/bool.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
Bool::Bool(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 Bool::cmp(const unsigned char *a, const unsigned char *b)
66
return memcmp(a, b, sizeof(unsigned char));
69
int Bool::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_BOOL_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_BOOL_VALUE, MYF(0), from);
121
int Bool::store(int64_t nr, bool )
123
ASSERT_COLUMN_MARKED_FOR_WRITE;
124
nr == 0 ? setFalse() : setTrue();
128
int Bool::store(double nr)
130
ASSERT_COLUMN_MARKED_FOR_WRITE;
131
nr == 0 ? setFalse() : setTrue();
135
int Bool::store_decimal(const drizzled::my_decimal*)
137
ASSERT_COLUMN_MARKED_FOR_WRITE;
138
my_error(ER_INVALID_BOOL_VALUE, MYF(ME_FATALERROR), " ");
142
void Bool::sql_type(String &res) const
144
res.set_ascii(STRING_WITH_LEN("bool"));
147
double Bool::val_real()
149
ASSERT_COLUMN_MARKED_FOR_READ;
153
int64_t Bool::val_int()
155
ASSERT_COLUMN_MARKED_FOR_READ;
159
String *Bool::val_str(String *val_buffer, String *)
161
ASSERT_COLUMN_MARKED_FOR_READ;
162
const CHARSET_INFO * const cs= &my_charset_bin;
163
uint32_t mlength= (5) * cs->mbmaxlen;
165
val_buffer->alloc(mlength);
166
char *buffer=(char*) val_buffer->ptr();
172
memcpy(buffer, "YES", 3);
173
val_buffer->length(3);
177
memcpy(buffer, "TRUE", 4);
178
val_buffer->length(4);
185
memcpy(buffer, "NO", 2);
186
val_buffer->length(2);
190
memcpy(buffer, "FALSE", 5);
191
val_buffer->length(5);
198
void Bool::sort_string(unsigned char *to, uint32_t length_arg)
200
memcpy(to, ptr, length_arg);
205
ptr[0]= set_true.byte;
208
} /* namespace field */
209
} /* namespace drizzled */