~capttofu/drizzle/drizzle_memcached

« back to all changes in this revision

Viewing changes to drizzled/item/type_holder.h

  • Committer: Brian Aker
  • Date: 2008-11-18 23:19:19 UTC
  • mfrom: (584.1.16 devel)
  • Revision ID: brian@tangent.org-20081118231919-w9sr347dtiwhccml
Merge of Monty's work.

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 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_ITEM_TYPE_HOLDER_H
 
21
#define DRIZZLED_ITEM_TYPE_HOLDER_H
 
22
 
 
23
typedef struct st_typelib TYPELIB;
 
24
class String;
 
25
class my_decimal;
 
26
class Session;
 
27
class Item;
 
28
 
 
29
/*
 
30
  Item_type_holder used to store type. name, length of Item for UNIONS &
 
31
  derived tables.
 
32
 
 
33
  Item_type_holder do not need cleanup() because its time of live limited by
 
34
  single SP/PS execution.
 
35
*/
 
36
class Item_type_holder: public Item
 
37
{
 
38
protected:
 
39
  TYPELIB *enum_set_typelib;
 
40
  enum_field_types fld_type;
 
41
 
 
42
  /**
 
43
    Get full information from Item about enum/set fields to be able to create
 
44
    them later.
 
45
 
 
46
    @param item    Item for information collection
 
47
  */
 
48
  void get_full_info(Item *item);
 
49
 
 
50
  /* It is used to count decimal precision in join_types */
 
51
  int prev_decimal_int_part;
 
52
public:
 
53
  Item_type_holder(Session *session, Item *item);
 
54
 
 
55
  /**
 
56
     Return expression type of Item_type_holder.
 
57
 
 
58
     @return
 
59
     Item_result (type of internal Drizzle expression result)
 
60
  */
 
61
  Item_result result_type() const;
 
62
 
 
63
  enum_field_types field_type() const { return fld_type; };
 
64
  enum Type type() const { return TYPE_HOLDER; }
 
65
  double val_real();
 
66
  int64_t val_int();
 
67
  my_decimal *val_decimal(my_decimal *val);
 
68
  String *val_str(String* val);
 
69
 
 
70
  /**
 
71
    Find field type which can carry current Item_type_holder type and
 
72
    type of given Item.
 
73
 
 
74
    @param session     thread handler
 
75
    @param item    given item to join its parameters with this item ones
 
76
 
 
77
    @retval
 
78
      true   error - types are incompatible
 
79
    @retval
 
80
      false  OK
 
81
  */
 
82
  bool join_types(Session *session, Item *item);
 
83
 
 
84
  /**
 
85
    Make temporary table field according collected information about type
 
86
    of UNION result.
 
87
 
 
88
    @param table  temporary table for which we create fields
 
89
 
 
90
    @return
 
91
      created field
 
92
  */
 
93
  Field *make_field_by_type(Table *table);
 
94
 
 
95
  /**
 
96
    Calculate lenth for merging result for given Item type.
 
97
 
 
98
    @param item  Item for length detection
 
99
 
 
100
    @return
 
101
      length
 
102
  */
 
103
  static uint32_t display_length(Item *item);
 
104
 
 
105
  /**
 
106
     Find real field type of item.
 
107
 
 
108
     @return
 
109
     type of field which should be created to store item value
 
110
  */
 
111
  static enum_field_types get_real_type(Item *item);
 
112
};
 
113
 
 
114
 
 
115
#endif /* DRIZZLED_ITEM_TYPE_HOLDER_H */