~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/create_field.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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