~posulliv/drizzle/memcached_applier

1039.12.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008-2009 Sun Microsystems
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; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
#ifndef DRIZZLED_CREATE_FIELD_H
21
#define DRIZZLED_CREATE_FIELD_H
22
23
/**
24
 * Class representing a field in a CREATE TABLE statement.
25
 *
26
 * Basically, all information for a new or altered field
27
 * definition is contained in the Create_field class.
28
 */
1039.16.7 by Nathan Williams
Merged trunk and resolved conflicts.
29
class CreateField :public Sql_alloc
1039.12.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
30
{
31
public:
32
  const char *field_name; /**< Name of the field to be created */
33
  const char *change; /**< If done with alter table */
34
  const char *after; /**< Put this new Field after this Field */
35
  LEX_STRING comment; /**< A comment for this field */
36
  Item *def; /**< Default value for the new field */
37
  enum enum_field_types sql_type; /**< The data type of the new field */
38
  /**
39
   * At various stages in execution this can be length of field in bytes or
40
   * max number of characters.
41
   */
42
  uint32_t length;
43
  /**
44
   * The value of `length' as set by parser: is the number of characters
45
   * for most of the types, or of bytes for BLOBs or numeric types.
46
   */
47
  uint32_t char_length;
48
  uint32_t decimals;
49
  uint32_t flags;
50
  uint32_t pack_length;
51
  uint32_t key_length;
52
  Field::utype unireg_check; /**< See Field::unireg_check */
53
  TYPELIB *interval; /**< Which interval to use (ENUM types..) */
1039.97.1 by Nathan Williams
Reverted CreateField::interval_list to a List<String>. Fixes memory leaks I introduced by converting it to a vector in branch listed below.
54
  List<String> interval_list;
1039.12.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
55
  const CHARSET_INFO *charset; /**< Character set for the column -- @TODO should be deleted */
56
  Field *field; // For alter table
57
58
  uint8_t interval_id;	// For rea_create_table
59
  uint32_t offset;
60
  uint32_t pack_flag;
61
1039.92.24 by Monty Taylor
Reverted my change to interval_list
62
  CreateField() :after(0) {}
1039.16.7 by Nathan Williams
Merged trunk and resolved conflicts.
63
  CreateField(Field *field, Field *orig_field);
1039.12.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
64
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
1039.16.7 by Nathan Williams
Merged trunk and resolved conflicts.
65
  CreateField *clone(MEM_ROOT *mem_root) const
66
    { return new (mem_root) CreateField(*this); }
1039.12.8 by Jay Pipes
Breaks Create_field definition out into its own header file. More documentation and style cleanups around Create_field.
67
  void create_length_to_internal_length(void);
68
69
  inline enum column_format_type column_format() const
70
  {
71
    return (enum column_format_type)
72
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
73
  }
74
75
  /**
76
   * Init for a tmp table field. To be extended if need be. 
77
   *
78
   * @note This is currently ONLY used in Item_sum_distinct::setup()
79
   */
80
  void init_for_tmp_table(enum_field_types sql_type_arg,
81
                          uint32_t max_length,
82
                          uint32_t decimals,
83
                          bool maybe_null,
84
                          bool is_unsigned);
85
86
  /**
87
    Initialize field definition for create.
88
89
    @param session                   Thread handle
90
    @param fld_name              Field name
91
    @param fld_type              Field type
92
    @param fld_length            Field length
93
    @param fld_decimals          Decimal (if any)
94
    @param fld_type_modifier     Additional type information
95
    @param fld_default_value     Field default value (if any)
96
    @param fld_on_update_value   The value of ON UPDATE clause
97
    @param fld_comment           Field comment
98
    @param fld_change            Field change
99
    @param fld_interval_list     Interval list (if any)
100
    @param fld_charset           Field charset
101
102
    @retval
103
      false on success
104
    @retval
105
      true  on error
106
  */
107
  bool init(Session *session,
108
            char *field_name,
109
            enum_field_types type,
110
            char *length,
111
            char *decimals,
112
            uint32_t type_modifier,
113
            Item *default_value,
114
            Item *on_update_value,
115
            LEX_STRING *comment,
116
            char *change,
117
            List<String> *interval_list,
118
            const CHARSET_INFO * const cs,
119
            uint32_t uint_geom_type,
120
            enum column_format_type column_format);
121
};
122
123
#endif /* DRIZZLED_CREATE_FIELD_H */