~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/enum.cc

  • Committer: pcrews
  • Date: 2011-05-24 17:36:24 UTC
  • mfrom: (1099.4.232 drizzle)
  • Revision ID: pcrews@lucid32-20110524173624-mwr1bvq6fa1r01ao
Updated translations + 2011.05.18 tarball tag

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"
 
21
#include <config.h>
22
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"
 
23
#include <drizzled/field/enum.h>
 
24
#include <drizzled/error.h>
 
25
#include <drizzled/table.h>
 
26
#include <drizzled/session.h>
 
27
#include <drizzled/typelib.h>
28
28
 
29
29
#include <sstream>
30
30
#include <string>
31
31
 
32
 
namespace drizzled
33
 
{
 
32
namespace drizzled {
34
33
 
35
34
/****************************************************************************
36
35
** enum type.
57
56
 * and stores the found key.  Upon not finding an entry in the typelib,
58
57
 * we always throw an error.
59
58
 */
60
 
int Field_enum::store(const char *from, uint32_t length, const CHARSET_INFO * const)
 
59
int Field_enum::store(const char *from, uint32_t length, const charset_info_st * const)
61
60
{
62
61
  uint32_t tmp;
63
62
 
65
64
 
66
65
  /* Remove end space */
67
66
  length= field_charset->cset->lengthsp(field_charset, from, length);
68
 
  tmp= find_type2(typelib, from, length, field_charset);
 
67
  tmp= typelib->find_type2(from, length, field_charset);
69
68
  if (! tmp)
70
69
  {
71
70
    if (length < 6) /* Can't be more than 99999 enums */
120
119
  return 0;
121
120
}
122
121
 
123
 
double Field_enum::val_real(void)
 
122
double Field_enum::val_real(void) const
124
123
{
125
124
  return (double) Field_enum::val_int();
126
125
}
127
126
 
128
 
int64_t Field_enum::val_int(void)
 
127
int64_t Field_enum::val_int(void) const
129
128
{
130
129
  ASSERT_COLUMN_MARKED_FOR_READ;
131
130
 
139
138
  return ((int64_t) tmp) + 1; /* SQL is from 1, we store from 0 */
140
139
}
141
140
 
142
 
String *Field_enum::val_str(String *, String *val_ptr)
 
141
String *Field_enum::val_str(String *, String *val_ptr) const
143
142
{
144
143
  uint32_t tmp=(uint32_t) Field_enum::val_int();
145
144
 
191
190
  uint32_t *len= typelib->type_lengths;
192
191
  for (const char **pos= typelib->type_names; *pos; pos++, len++)
193
192
  {
194
 
    size_t dummy_errors;
195
193
    if (flag)
196
194
      res.append(',');
197
195
    /* convert to res.charset() == utf8, then quote */
198
 
    enum_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
 
196
    enum_item.copy(*pos, *len, res.charset());
199
197
    append_unescaped(&res, enum_item.c_ptr(), enum_item.length());
200
198
    flag= 1;
201
199
  }
208
206
  Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);
209
207
  if (res)
210
208
  {
211
 
    res->typelib= typelib->copy_typelib(root);
 
209
    res->typelib= typelib->copy_typelib(*root);
212
210
  }
213
211
  return res;
214
212
}