~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/field/boolean.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
 
22
22
#include <config.h>
23
 
 
24
23
#include <algorithm>
25
 
 
26
24
#include <drizzled/field/boolean.h>
27
25
#include <drizzled/type/boolean.h>
28
 
 
29
26
#include <drizzled/error.h>
30
27
#include <drizzled/internal/my_sys.h>
31
28
#include <drizzled/session.h>
32
29
#include <drizzled/table.h>
33
30
#include <drizzled/temporal.h>
34
31
 
35
 
union set_true_t {
36
 
  unsigned char byte;
37
 
  bool is_true:1;
38
 
 
39
 
  set_true_t()
40
 
  {
41
 
    is_true= true;
42
 
  }
43
 
} set_true;
44
 
 
45
 
namespace drizzled
46
 
{
47
 
namespace field
48
 
{
 
32
namespace drizzled {
 
33
namespace field {
49
34
 
50
35
Boolean::Boolean(unsigned char *ptr_arg,
51
36
                 uint32_t len_arg,
69
54
  return memcmp(a, b, sizeof(unsigned char));
70
55
}
71
56
 
72
 
int Boolean::store(const char *from, uint32_t length, const CHARSET_INFO * const )
 
57
int Boolean::store(const char *from, uint32_t length, const charset_info_st * const )
73
58
{
74
59
  ASSERT_COLUMN_MARKED_FOR_WRITE;
75
60
 
79
64
    my_error(ER_INVALID_BOOLEAN_VALUE, MYF(0), from);
80
65
    return 1;
81
66
  }
82
 
 
83
 
  if (result)
84
 
  {
85
 
    setTrue();
86
 
  }
87
 
  else
88
 
  {
89
 
    setFalse();
90
 
  }
91
 
 
 
67
  set(result);
92
68
  return 0;
93
69
}
94
70
 
95
 
int Boolean::store(int64_t nr, bool )
 
71
int Boolean::store(int64_t nr, bool)
96
72
{
97
73
  ASSERT_COLUMN_MARKED_FOR_WRITE;
98
 
  nr == 0 ? setFalse() : setTrue();
 
74
  set(nr != 0);
99
75
  return 0;
100
76
}
101
77
 
102
78
int  Boolean::store(double nr)
103
79
{
104
80
  ASSERT_COLUMN_MARKED_FOR_WRITE;
105
 
  nr == 0 ? setFalse() : setTrue();
 
81
  set(nr);
106
82
  return 0;
107
83
}
108
84
 
109
85
int Boolean::store_decimal(const drizzled::type::Decimal *dec)
110
86
{
111
87
  ASSERT_COLUMN_MARKED_FOR_WRITE;
112
 
  if (dec->isZero())
113
 
  {
114
 
    setFalse();
115
 
    return 0;
116
 
  }
117
 
 
118
 
  setTrue();
119
 
 
 
88
  set(not dec->isZero());
120
89
  return 0;
121
90
}
122
91
 
123
 
void Boolean::sql_type(String &res) const
124
 
{
125
 
  res.set_ascii(STRING_WITH_LEN("boolean"));
126
 
}
127
 
 
128
92
double Boolean::val_real() const
129
93
{
130
94
  ASSERT_COLUMN_MARKED_FOR_READ;
140
104
String *Boolean::val_str(String *val_buffer, String *) const
141
105
{
142
106
  ASSERT_COLUMN_MARKED_FOR_READ;
143
 
 
144
 
  (void)type::convert(*val_buffer, isTrue(), ansi_display);
145
 
 
 
107
  type::convert(*val_buffer, isTrue(), ansi_display);
146
108
  return val_buffer;
147
109
}
148
110
 
153
115
    int2_class_decimal(E_DEC_OK, 1, false, dec);
154
116
    return dec;
155
117
  }
156
 
 
157
118
  dec->set_zero();
158
 
 
159
119
  return dec;
160
120
}
161
121
 
164
124
  memcpy(to, ptr, length_arg);
165
125
}
166
126
 
167
 
void Boolean::setTrue()
168
 
{
169
 
  ptr[0]= set_true.byte;
170
 
}
171
 
 
172
127
} /* namespace field */
173
128
} /* namespace drizzled */