~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/create_field.h

  • Committer: Nathan Williams
  • Date: 2009-06-13 21:21:13 UTC
  • mfrom: (1062 staging)
  • mto: This revision was merged to the branch mainline in revision 1063.
  • Revision ID: nathanlws@gmail.com-20090613212113-liz01ojh1wxutgqx
Merged trunk and resolved conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include <vector>
 
24
 
 
25
/**
 
26
 * Class representing a field in a CREATE TABLE statement.
 
27
 *
 
28
 * Basically, all information for a new or altered field
 
29
 * definition is contained in the Create_field class.
 
30
 */
 
31
class CreateField :public Sql_alloc
 
32
{
 
33
public:
 
34
  const char *field_name; /**< Name of the field to be created */
 
35
  const char *change; /**< If done with alter table */
 
36
  const char *after; /**< Put this new Field after this Field */
 
37
  LEX_STRING comment; /**< A comment for this field */
 
38
  Item *def; /**< Default value for the new field */
 
39
  enum enum_field_types sql_type; /**< The data type of the new field */
 
40
  /**
 
41
   * At various stages in execution this can be length of field in bytes or
 
42
   * max number of characters.
 
43
   */
 
44
  uint32_t length;
 
45
  /**
 
46
   * The value of `length' as set by parser: is the number of characters
 
47
   * for most of the types, or of bytes for BLOBs or numeric types.
 
48
   */
 
49
  uint32_t char_length;
 
50
  uint32_t decimals;
 
51
  uint32_t flags;
 
52
  uint32_t pack_length;
 
53
  uint32_t key_length;
 
54
  Field::utype unireg_check; /**< See Field::unireg_check */
 
55
  TYPELIB *interval; /**< Which interval to use (ENUM types..) */
 
56
  std::vector<String*> interval_list;
 
57
  const CHARSET_INFO *charset; /**< Character set for the column -- @TODO should be deleted */
 
58
  Field *field; // For alter table
 
59
 
 
60
  uint8_t interval_id;  // For rea_create_table
 
61
  uint32_t offset;
 
62
  uint32_t pack_flag;
 
63
 
 
64
  CreateField() :after(0) {}
 
65
  CreateField(Field *field, Field *orig_field);
 
66
  /* Used to make a clone of this object for ALTER/CREATE TABLE */
 
67
  CreateField *clone(MEM_ROOT *mem_root) const
 
68
    { return new (mem_root) CreateField(*this); }
 
69
  void create_length_to_internal_length(void);
 
70
 
 
71
  inline enum column_format_type column_format() const
 
72
  {
 
73
    return (enum column_format_type)
 
74
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
 
75
  }
 
76
 
 
77
  /**
 
78
   * Init for a tmp table field. To be extended if need be. 
 
79
   *
 
80
   * @note This is currently ONLY used in Item_sum_distinct::setup()
 
81
   */
 
82
  void init_for_tmp_table(enum_field_types sql_type_arg,
 
83
                          uint32_t max_length,
 
84
                          uint32_t decimals,
 
85
                          bool maybe_null,
 
86
                          bool is_unsigned);
 
87
 
 
88
  /**
 
89
    Initialize field definition for create.
 
90
 
 
91
    @param session                   Thread handle
 
92
    @param fld_name              Field name
 
93
    @param fld_type              Field type
 
94
    @param fld_length            Field length
 
95
    @param fld_decimals          Decimal (if any)
 
96
    @param fld_type_modifier     Additional type information
 
97
    @param fld_default_value     Field default value (if any)
 
98
    @param fld_on_update_value   The value of ON UPDATE clause
 
99
    @param fld_comment           Field comment
 
100
    @param fld_change            Field change
 
101
    @param fld_interval_list     Interval list (if any)
 
102
    @param fld_charset           Field charset
 
103
 
 
104
    @retval
 
105
      false on success
 
106
    @retval
 
107
      true  on error
 
108
  */
 
109
  bool init(Session *session,
 
110
            char *field_name,
 
111
            enum_field_types type,
 
112
            char *length,
 
113
            char *decimals,
 
114
            uint32_t type_modifier,
 
115
            Item *default_value,
 
116
            Item *on_update_value,
 
117
            LEX_STRING *comment,
 
118
            char *change,
 
119
            List<String> *interval_list,
 
120
            const CHARSET_INFO * const cs,
 
121
            uint32_t uint_geom_type,
 
122
            enum column_format_type column_format);
 
123
};
 
124
 
 
125
#endif /* DRIZZLED_CREATE_FIELD_H */