drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
type/boolean.cc
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2011 Brian Aker
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <config.h>
22
23#include <drizzled/sql_string.h>
24#include <drizzled/type/boolean.h>
25#include <drizzled/charset.h>
26
27namespace drizzled {
28namespace type {
29
30const char* convert(bool source, bool ansi_display)
31{
32 if (source)
33 return ansi_display ? "YES" : "TRUE";
34 return ansi_display ? "NO" : "FALSE";
35}
36
37void convert(String& destination, bool source, bool ansi_display)
38{
39 const char* v= convert(source, ansi_display);
40 destination.alloc(strlen(v));
41 strcpy(destination.c_ptr(), v);
42 destination.length(strlen(v));
43}
44
45bool convert(bool &destination, const char *source, const size_t source_length)
46{
47 switch (source_length)
48 {
49 case 1:
50 {
51 switch (source[0])
52 {
53 case 'y': case 'Y':
54 case 't': case 'T': // PG compatibility
55 destination= true;
56 return true;
57
58 case 'n': case 'N':
59 case 'f': case 'F': // PG compatibility
60 destination= false;
61 return true;
62 }
63 }
64 break;
65
66 case 5:
67 if (not (system_charset_info->strcasecmp(source, "FALSE")))
68 {
69 destination= false;
70 return true;
71 }
72 break;
73
74 case 4:
75 if (not (system_charset_info->strcasecmp(source, "TRUE")))
76 {
77 destination= true;
78 return true;
79 }
80 break;
81
82 case 3:
83 if (not (system_charset_info->strcasecmp(source, "YES")))
84 {
85 destination= true;
86 return true;
87 }
88 break;
89
90 case 2:
91 if (not (system_charset_info->strcasecmp(source, "NO")))
92 {
93 destination= false;
94 return true;
95 }
96 break;
97 }
98
99 // Failure to match
100 destination= false;
101 return false;
102}
103
104bool convert(bool &destination, String &source)
105{
106 return convert(destination, source.c_ptr(), source.length());
107}
108
109} /* namespace type */
110} /* namespace drizzled */
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.