~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/item/type_holder.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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