~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/boolean.cc

  • Committer: Stewart Smith
  • Date: 2011-01-13 06:27:34 UTC
  • mto: This revision was merged to the branch mainline in revision 2083.
  • Revision ID: stewart@flamingspork.com-20110113062734-m3dg1vz2ussyykmy
remove suppressions from valgrind.supp for bug 582486 which seems to have been fixed at some point in the past.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <algorithm>
25
25
 
26
26
#include "drizzled/field/boolean.h"
27
 
#include "drizzled/type/boolean.h"
28
27
 
29
28
#include "drizzled/error.h"
30
29
#include "drizzled/internal/my_sys.h"
71
70
{
72
71
  ASSERT_COLUMN_MARKED_FOR_WRITE;
73
72
 
74
 
  bool result;
75
 
  if (not type::convert(result, from, length))
 
73
  if (length == 1)
 
74
  {
 
75
    switch (from[0])
 
76
    {
 
77
    case 'y': case 'Y':
 
78
    case 't': case 'T': // PG compatibility
 
79
      setTrue();
 
80
      return 0;
 
81
 
 
82
    case 'n': case 'N':
 
83
    case 'f': case 'F': // PG compatibility
 
84
      setFalse();
 
85
      return 0;
 
86
 
 
87
    default:
 
88
      my_error(ER_INVALID_BOOLEAN_VALUE, MYF(0), from);
 
89
      return 1; // invalid
 
90
    }
 
91
  }
 
92
  else if ((length == 5) and (strcasecmp(from, "FALSE") == 0))
 
93
  {
 
94
    setFalse();
 
95
  }
 
96
  if ((length == 4) and (strcasecmp(from, "TRUE") == 0))
 
97
  {
 
98
    setTrue();
 
99
  }
 
100
  else if ((length == 5) and (strcasecmp(from, "FALSE") == 0))
 
101
  {
 
102
    setFalse();
 
103
  }
 
104
  else if ((length == 3) and (strcasecmp(from, "YES") == 0))
 
105
  {
 
106
    setTrue();
 
107
  }
 
108
  else if ((length == 2) and (strcasecmp(from, "NO") == 0))
 
109
  {
 
110
    setFalse();
 
111
  }
 
112
  else
76
113
  {
77
114
    my_error(ER_INVALID_BOOLEAN_VALUE, MYF(0), from);
78
 
    return 1;
79
 
  }
80
 
 
81
 
  if (result)
82
 
  {
83
 
    setTrue();
84
 
  }
85
 
  else
86
 
  {
87
 
    setFalse();
 
115
    return 1; // invalid
88
116
  }
89
117
 
90
118
  return 0;
107
135
int Boolean::store_decimal(const drizzled::type::Decimal *dec)
108
136
{
109
137
  ASSERT_COLUMN_MARKED_FOR_WRITE;
110
 
  if (dec->isZero())
 
138
  if (dec->is_zero())
111
139
  {
112
140
    setFalse();
113
141
    return 0;
138
166
String *Boolean::val_str(String *val_buffer, String *)
139
167
{
140
168
  ASSERT_COLUMN_MARKED_FOR_READ;
141
 
 
142
 
  (void)type::convert(*val_buffer, isTrue(), ansi_display);
 
169
  const CHARSET_INFO * const cs= &my_charset_bin;
 
170
  uint32_t mlength= (5) * cs->mbmaxlen;
 
171
 
 
172
  val_buffer->alloc(mlength);
 
173
  char *buffer=(char*) val_buffer->c_ptr();
 
174
 
 
175
  if (isTrue())
 
176
  {
 
177
    if (ansi_display)
 
178
    {
 
179
      memcpy(buffer, "YES", 3);
 
180
      val_buffer->length(3);
 
181
    }
 
182
    else
 
183
    {
 
184
      memcpy(buffer, "TRUE", 4);
 
185
      val_buffer->length(4);
 
186
    }
 
187
  }
 
188
  else
 
189
  {
 
190
    if (ansi_display)
 
191
    {
 
192
      memcpy(buffer, "NO", 2);
 
193
      val_buffer->length(2);
 
194
    }
 
195
    else
 
196
    {
 
197
      memcpy(buffer, "FALSE", 5);
 
198
      val_buffer->length(5);
 
199
    }
 
200
  }
143
201
 
144
202
  return val_buffer;
145
203
}