~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/enum.cc

  • Committer: Monty Taylor
  • Date: 2010-10-02 20:07:26 UTC
  • mto: (1812.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1813.
  • Revision ID: mordred@inaugust.com-20101002200726-sglji5raadtpebif
Update COPYING file to have current FSF address in it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
22
 
#include <boost/lexical_cast.hpp>
23
 
#include <drizzled/field/enum.h>
24
 
#include <drizzled/error.h>
25
 
#include <drizzled/table.h>
26
 
#include <drizzled/session.h>
27
 
#include <drizzled/strfunc.h>
28
 
#include <drizzled/typelib.h>
 
21
 
 
22
#include "config.h"
 
23
#include "drizzled/field/enum.h"
 
24
#include "drizzled/error.h"
 
25
#include "drizzled/table.h"
 
26
#include "drizzled/session.h"
 
27
#include "drizzled/strfunc.h"
29
28
 
30
29
#include <sstream>
31
30
#include <string>
44
43
  value--; /* we store as starting from 0, although SQL starts from 1 */
45
44
 
46
45
#ifdef WORDS_BIGENDIAN
47
 
  if (getTable()->getShare()->db_low_byte_first)
 
46
  if (getTable()->s->db_low_byte_first)
48
47
  {
49
48
    int4store(ptr, (unsigned short) value);
50
49
  }
66
65
 
67
66
  /* Remove end space */
68
67
  length= field_charset->cset->lengthsp(field_charset, from, length);
69
 
  tmp= typelib->find_type2(from, length, field_charset);
 
68
  tmp= find_type2(typelib, from, length, field_charset);
70
69
  if (! tmp)
71
70
  {
72
71
    if (length < 6) /* Can't be more than 99999 enums */
111
110
 
112
111
  if (from <= 0 || (uint64_t) from > typelib->count)
113
112
  {
114
 
    /* Convert the integer to a string using boost::lexical_cast */
115
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
113
    /* Convert the integer to a string using stringstream */
 
114
    std::stringstream ss;
 
115
    std::string tmp;
 
116
    ss << from; ss >> tmp;
116
117
 
117
118
    my_error(ER_INVALID_ENUM_VALUE, MYF(ME_FATALERROR), tmp.c_str());
118
119
    return 1;
121
122
  return 0;
122
123
}
123
124
 
124
 
double Field_enum::val_real(void) const
 
125
double Field_enum::val_real(void)
125
126
{
126
127
  return (double) Field_enum::val_int();
127
128
}
128
129
 
129
 
int64_t Field_enum::val_int(void) const
 
130
int64_t Field_enum::val_int(void)
130
131
{
131
132
  ASSERT_COLUMN_MARKED_FOR_READ;
132
133
 
133
134
  uint16_t tmp;
134
135
#ifdef WORDS_BIGENDIAN
135
 
  if (getTable()->getShare()->db_low_byte_first)
 
136
  if (getTable()->s->db_low_byte_first)
136
137
    tmp= sint4korr(ptr);
137
138
  else
138
139
#endif
140
141
  return ((int64_t) tmp) + 1; /* SQL is from 1, we store from 0 */
141
142
}
142
143
 
143
 
String *Field_enum::val_str(String *, String *val_ptr) const
 
144
String *Field_enum::val_str(String *, String *val_ptr)
144
145
{
145
146
  uint32_t tmp=(uint32_t) Field_enum::val_int();
146
147
 
147
148
  ASSERT_COLUMN_MARKED_FOR_READ;
148
149
 
149
 
  if (not tmp || tmp > typelib->count)
 
150
  if (!tmp || tmp > typelib->count)
150
151
  {
151
152
    val_ptr->set("", 0, field_charset);
152
153
  }
192
193
  uint32_t *len= typelib->type_lengths;
193
194
  for (const char **pos= typelib->type_names; *pos; pos++, len++)
194
195
  {
195
 
    size_t dummy_errors;
 
196
    uint32_t dummy_errors;
196
197
    if (flag)
197
198
      res.append(',');
198
199
    /* convert to res.charset() == utf8, then quote */
209
210
  Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);
210
211
  if (res)
211
212
  {
212
 
    res->typelib= typelib->copy_typelib(root);
 
213
    res->typelib= copy_typelib(root, typelib);
213
214
  }
214
215
  return res;
215
216
}