~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/enum.h

  • Committer: Jay Pipes
  • Date: 2009-03-16 15:20:27 UTC
  • mto: (934.3.7 mordred)
  • mto: This revision was merged to the branch mainline in revision 938.
  • Revision ID: jpipes@serialcoder-20090316152027-njlreaim8vxqta6c
Fixes ENUM field type to throw an error on bad data input.  0 is now not
allowed on insertion.  MySQL allows 0, in the manual it states 0 is "the
null string error index" whatever that means.  Drizzle doesn't allow it.

Corrected test cases.

Also cleans up indentation on JOIN::exec() which was bothering me.

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
 
#ifndef DRIZZLE_SERVER_FIELD_ENUM
22
 
#define DRIZZLE_SERVER_FIELD_ENUM
23
 
 
24
 
#include <drizzled/field/str.h>
25
 
 
26
 
class Field_enum :public Field_str {
 
21
#ifndef DRIZZLED_FIELD_ENUM_H
 
22
#define DRIZZLED_FIELD_ENUM_H
 
23
 
 
24
#include "drizzled/field/str.h"
 
25
 
 
26
class Field_enum :public Field_str 
 
27
{
27
28
protected:
28
29
  uint32_t packlength;
29
30
public:
33
34
  using Field::val_str;
34
35
  using Field::cmp;
35
36
 
 
37
  /** Internal storage for the string values of the ENUM */
36
38
  TYPELIB *typelib;
37
39
  Field_enum(unsigned char *ptr_arg, uint32_t len_arg, unsigned char *null_ptr_arg,
38
40
             unsigned char null_bit_arg,
47
49
      flags|=ENUM_FLAG;
48
50
  }
49
51
  Field *new_field(MEM_ROOT *root, Table *new_table, bool keep_type);
50
 
  enum_field_types type() const { return DRIZZLE_TYPE_ENUM; }
51
 
  enum Item_result cmp_type () const { return INT_RESULT; }
52
 
  enum Item_result cast_to_int_type () const { return INT_RESULT; }
53
52
  enum ha_base_keytype key_type() const;
54
 
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
 
53
  int  store(const char *to, uint32_t length, const CHARSET_INFO * const);
55
54
  int  store(double nr);
56
55
  int  store(int64_t nr, bool unsigned_val);
57
56
  double val_real(void);
58
57
  int64_t val_int(void);
59
 
  String *val_str(String*,String *);
60
 
  int cmp(const unsigned char *,const unsigned char *);
61
 
  void sort_string(unsigned char *buff,uint32_t length);
62
 
  uint32_t pack_length() const { return (uint32_t) packlength; }
 
58
  String *val_str(String*, String *);
 
59
  int cmp(const unsigned char *, const unsigned char *);
 
60
  void sort_string(unsigned char *buff, uint32_t length);
63
61
  void store_type(uint64_t value);
64
62
  void sql_type(String &str) const;
65
 
  uint32_t size_of() const { return sizeof(*this); }
66
 
  enum_field_types real_type() const { return DRIZZLE_TYPE_ENUM; }
 
63
  bool eq_def(Field *field);
 
64
  enum_field_types type() const
 
65
  {
 
66
    return DRIZZLE_TYPE_ENUM;
 
67
  }
 
68
  enum Item_result cmp_type () const
 
69
  {
 
70
    return INT_RESULT;
 
71
  }
 
72
  enum Item_result cast_to_int_type () const
 
73
  {
 
74
    return INT_RESULT;
 
75
  }
 
76
  uint32_t pack_length() const
 
77
  {
 
78
    return (uint32_t) packlength;
 
79
  }
 
80
  uint32_t size_of() const
 
81
  {
 
82
    return sizeof(*this);
 
83
  }
 
84
  enum_field_types real_type() const
 
85
  {
 
86
    return DRIZZLE_TYPE_ENUM;
 
87
  }
67
88
  uint32_t pack_length_from_metadata(uint32_t field_metadata)
68
 
  { return (field_metadata & 0x00ff); }
69
 
  uint32_t row_pack_length() { return pack_length(); }
70
 
  virtual bool zero_pack() const { return 0; }
71
 
  bool optimize_range(uint32_t, uint32_t)
72
 
  { return 0; }
73
 
  bool eq_def(Field *field);
74
 
  bool has_charset(void) const { return true; }
 
89
  {
 
90
    return (field_metadata & 0x00ff);
 
91
  }
 
92
  uint32_t row_pack_length()
 
93
  { 
 
94
    return pack_length();
 
95
  }
 
96
  virtual bool zero_pack() const
 
97
  {
 
98
    return false;
 
99
  }
 
100
  bool optimize_range(uint32_t, uint32_t) 
 
101
  {
 
102
    return false;
 
103
  }
 
104
  bool has_charset(void) const
 
105
  {
 
106
    return true;
 
107
  }
75
108
  /* enum and set are sorted as integers */
76
109
  const CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
77
110
private:
78
111
  int do_save_field_metadata(unsigned char *first_byte);
79
112
};
80
113
 
81
 
#endif
 
114
#endif /* DRIZZLED_FIELD_ENUM_H */