~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/create_field.h

  • Committer: Brian Aker
  • Date: 2008-10-18 15:43:20 UTC
  • mto: (492.3.20 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081018154320-jc9jyij3mdf08abp
Updating tests.

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