~drizzle-trunk/drizzle/development

466 by Monty Taylor
Fixed modelines... these files are c++.
1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
438.4.1 by Lee
breaking out enum field classes
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 MySQL
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
934.4.1 by Jay Pipes
Fixes ENUM field type to throw an error on bad data input. 0 is now not
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
{
438.4.1 by Lee
breaking out enum field classes
28
protected:
482 by Brian Aker
Remove uint.
29
  uint32_t packlength;
438.4.1 by Lee
breaking out enum field classes
30
public:
892.1.2 by Monty Taylor
Fixed solaris warnings.
31
32
  using Field::store;
33
  using Field::val_int;
34
  using Field::val_str;
35
  using Field::cmp;
36
934.4.1 by Jay Pipes
Fixes ENUM field type to throw an error on bad data input. 0 is now not
37
  /** Internal storage for the string values of the ENUM */
438.4.1 by Lee
breaking out enum field classes
38
  TYPELIB *typelib;
481 by Brian Aker
Remove all of uchar.
39
  Field_enum(unsigned char *ptr_arg, uint32_t len_arg, unsigned char *null_ptr_arg,
40
             unsigned char null_bit_arg,
438.4.1 by Lee
breaking out enum field classes
41
             enum utype unireg_check_arg, const char *field_name_arg,
482 by Brian Aker
Remove uint.
42
             uint32_t packlength_arg,
438.4.1 by Lee
breaking out enum field classes
43
             TYPELIB *typelib_arg,
44
             const CHARSET_INFO * const charset_arg)
45
    :Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
46
	       unireg_check_arg, field_name_arg, charset_arg),
47
    packlength(packlength_arg),typelib(typelib_arg)
48
  {
49
      flags|=ENUM_FLAG;
50
  }
51
  Field *new_field(MEM_ROOT *root, Table *new_table, bool keep_type);
52
  enum ha_base_keytype key_type() const;
934.4.1 by Jay Pipes
Fixes ENUM field type to throw an error on bad data input. 0 is now not
53
  int  store(const char *to, uint32_t length, const CHARSET_INFO * const);
438.4.1 by Lee
breaking out enum field classes
54
  int  store(double nr);
55
  int  store(int64_t nr, bool unsigned_val);
56
  double val_real(void);
57
  int64_t val_int(void);
934.4.1 by Jay Pipes
Fixes ENUM field type to throw an error on bad data input. 0 is now not
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);
438.4.1 by Lee
breaking out enum field classes
61
  void store_type(uint64_t value);
62
  void sql_type(String &str) const;
934.4.1 by Jay Pipes
Fixes ENUM field type to throw an error on bad data input. 0 is now not
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
  }
482 by Brian Aker
Remove uint.
88
  uint32_t pack_length_from_metadata(uint32_t field_metadata)
934.4.1 by Jay Pipes
Fixes ENUM field type to throw an error on bad data input. 0 is now not
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
  }
438.4.1 by Lee
breaking out enum field classes
108
  /* enum and set are sorted as integers */
109
  const CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; }
110
private:
481 by Brian Aker
Remove all of uchar.
111
  int do_save_field_metadata(unsigned char *first_byte);
438.4.1 by Lee
breaking out enum field classes
112
};
113
934.4.1 by Jay Pipes
Fixes ENUM field type to throw an error on bad data input. 0 is now not
114
#endif /* DRIZZLED_FIELD_ENUM_H */