~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/enum.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include "config.h"
 
22
#include "drizzled/server_includes.h"
23
23
#include "drizzled/field/enum.h"
24
24
#include "drizzled/error.h"
25
25
#include "drizzled/table.h"
26
26
#include "drizzled/session.h"
27
 
#include "drizzled/strfunc.h"
28
27
 
29
28
#include <sstream>
30
29
#include <string>
31
30
 
32
 
namespace drizzled
33
 
{
34
 
 
35
31
/****************************************************************************
36
32
** enum type.
37
33
** This is a string which only can have a selection of different values.
96
92
{
97
93
  uint32_t tmp;
98
94
 
99
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
100
 
 
101
95
  /* Remove end space */
102
96
  length= field_charset->cset->lengthsp(field_charset, from, length);
103
97
  tmp= find_type2(typelib, from, length, field_charset);
141
135
 */
142
136
int Field_enum::store(int64_t from, bool)
143
137
{
144
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
145
 
 
146
138
  if (from <= 0 || (uint64_t) from > typelib->count)
147
139
  {
148
140
    /* Convert the integer to a string using stringstream */
164
156
 
165
157
int64_t Field_enum::val_int(void)
166
158
{
167
 
  ASSERT_COLUMN_MARKED_FOR_READ;
168
 
 
169
159
  switch (packlength) {
170
160
  case 1:
171
161
    return (int64_t) ptr[0];
208
198
  return 0;                                     // impossible
209
199
}
210
200
 
 
201
/**
 
202
   Save the field metadata for enum fields.
 
203
 
 
204
   Saves the real type in the first byte and the pack length in the
 
205
   second byte of the field metadata array at index of *metadata_ptr and
 
206
   *(metadata_ptr + 1).
 
207
 
 
208
   @param   metadata_ptr   First byte of field metadata
 
209
 
 
210
   @returns number of bytes written to metadata_ptr
 
211
*/
 
212
int Field_enum::do_save_field_metadata(unsigned char *metadata_ptr)
 
213
{
 
214
  *metadata_ptr= real_type();
 
215
  *(metadata_ptr + 1)= pack_length();
 
216
  return 2;
 
217
}
 
218
 
211
219
String *Field_enum::val_str(String *, String *val_ptr)
212
220
{
213
221
  uint32_t tmp=(uint32_t) Field_enum::val_int();
214
 
 
215
 
  ASSERT_COLUMN_MARKED_FOR_READ;
216
 
 
217
222
  if (!tmp || tmp > typelib->count)
218
223
    val_ptr->set("", 0, field_charset);
219
224
  else
268
273
  res.append(')');
269
274
}
270
275
 
271
 
Field *Field_enum::new_field(memory::Root *root, Table *new_table,
 
276
Field *Field_enum::new_field(MEM_ROOT *root, Table *new_table,
272
277
                             bool keep_type)
273
278
{
274
279
  Field_enum *res= (Field_enum*) Field::new_field(root, new_table, keep_type);
276
281
    res->typelib= copy_typelib(root, typelib);
277
282
  return res;
278
283
}
279
 
 
280
 
} /* namespace drizzled */