~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 *
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#pragma once

#include <drizzled/field.h>

namespace drizzled {

/**
 * Class representing a field in a CREATE TABLE statement.
 *
 * Basically, all information for a new or altered field
 * definition is contained in the Create_field class.
 */
class CreateField :public memory::SqlAlloc
{
public:
  const char *field_name; /**< Name of the field to be created */
  const char *change; /**< If done with alter table */
  const char *after; /**< Put this new Field after this Field */
  LEX_STRING comment; /**< A comment for this field */
  Item *def; /**< Default value for the new field */
  enum enum_field_types sql_type; /**< The data type of the new field */

  enum_field_types type() const
  {
    return sql_type;
  }

  /**
   * At various stages in execution this can be length of field in bytes or
   * max number of characters.
   */
  uint32_t length;
  /**
   * The value of `length' as set by parser: is the number of characters
   * for most of the types, or of bytes for BLOBs or numeric types.
   */
  uint32_t char_length;
  uint32_t decimals;
  uint32_t flags;
  uint32_t pack_length;
  uint32_t key_length;
  Field::utype unireg_check; /**< See Field::unireg_check */
  TYPELIB *interval; /**< Which interval to use (ENUM types..) */
  List<String> interval_list;
  const charset_info_st *charset; /**< Character set for the column -- @TODO should be deleted */
  Field *field; // For alter table

  uint8_t interval_id;	// For rea_create_table
  uint32_t offset;

  CreateField() :after(0) {}
  CreateField(Field *field, Field *orig_field);
  void create_length_to_internal_length(void);

  inline enum column_format_type column_format() const
  {
    return (enum column_format_type)
      ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
  }

  /**
   * Init for a tmp table field. To be extended if need be. 
   *
   * @note This is currently ONLY used in Item_sum_distinct::setup()
   */
  void init_for_tmp_table(enum_field_types sql_type_arg,
                          uint32_t max_length,
                          uint32_t decimals,
                          bool maybe_null);

  /**
    Initialize field definition for create.

    @param session                   Thread handle
    @param fld_name              Field name
    @param fld_type              Field type
    @param fld_length            Field length
    @param fld_decimals          Decimal (if any)
    @param fld_type_modifier     Additional type information
    @param fld_default_value     Field default value (if any)
    @param fld_on_update_value   The value of ON UPDATE clause
    @param fld_comment           Field comment
    @param fld_change            Field change
    @param fld_interval_list     Interval list (if any)
    @param fld_charset           Field charset

    @retval
      false on success
    @retval
      true  on error
  */
  bool init(Session *session,
            char *field_name,
            enum_field_types type,
            char *length,
            char *decimals,
            uint32_t type_modifier,
            LEX_STRING *comment,
            char *change,
            List<String> *interval_list,
            const charset_info_st * const cs,
            uint32_t uint_geom_type,
            enum column_format_type column_format);

  bool setDefaultValue(Item *default_value, Item *on_update_item);
};

std::ostream& operator<<(std::ostream& output, const CreateField &field);

} /* namespace drizzled */