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
23
#include <drizzled/error.h>
24
#include <drizzled/function/cast/boolean.h>
25
#include <drizzled/lex_string.h>
26
#include <drizzled/type/boolean.h>
32
void Boolean::print(String *str, enum_query_type query_type)
34
str->append(STRING_WITH_LEN("cast("));
35
args[0]->print(str, query_type);
36
str->append(STRING_WITH_LEN(" as boolean)"));
39
drizzled::String *Boolean::val_str(drizzled::String *value)
41
switch (args[0]->result_type())
45
drizzled::String _res, *res;
47
if (not (res= args[0]->val_str(&_res)))
55
if (not type::convert(result, *res))
57
my_error(ER_INVALID_CAST_TO_BOOLEAN, MYF(0), res->c_ptr());
60
return evaluate(result, value);
68
bool tmp= args[0]->val_bool();
69
null_value=args[0]->null_value;
71
return evaluate(tmp, value);
75
// We should never reach this
76
return evaluate(false, value);
79
String *Boolean::evaluate(const bool &result, String *val_buffer)
81
const CHARSET_INFO * const cs= &my_charset_bin;
82
uint32_t mlength= (5) * cs->mbmaxlen;
84
val_buffer->alloc(mlength);
85
char *buffer=(char*) val_buffer->c_ptr();
89
memcpy(buffer, "TRUE", 4);
90
val_buffer->length(4);
94
memcpy(buffer, "FALSE", 5);
95
val_buffer->length(5);
102
} // namespace function
103
} // namespace drizzled