~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

Merged from fix-headers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef drizzled_item_h
21
 
#define drizzled_item_h
 
20
#ifndef DRIZZLED_ITEM_H
 
21
#define DRIZZLED_ITEM_H
22
22
 
23
23
#include <drizzled/dtcollation.h>
24
24
 
26
26
struct TableList;
27
27
void item_init(void);                   /* Init item functions */
28
28
class Item_field;
29
 
 
 
29
class Name_resolution_context;
30
30
 
31
31
void dummy_error_processor(Session *session, void *data);
32
32
 
33
33
void view_error_processor(Session *session, void *data);
34
34
 
35
 
/*
36
 
  Instances of Name_resolution_context store the information necesary for
37
 
  name resolution of Items and other context analysis of a query made in
38
 
  fix_fields().
39
 
 
40
 
  This structure is a part of SELECT_LEX, a pointer to this structure is
41
 
  assigned when an item is created (which happens mostly during  parsing
42
 
  (sql_yacc.yy)), but the structure itself will be initialized after parsing
43
 
  is complete
44
 
 
45
 
  TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
46
 
  separate SELECT_LEX which allow to remove tricks of changing this
47
 
  structure before and after INSERT/CREATE and its SELECT to make correct
48
 
  field name resolution.
49
 
*/
50
 
struct Name_resolution_context: Sql_alloc
51
 
{
52
 
  /*
53
 
    The name resolution context to search in when an Item cannot be
54
 
    resolved in this context (the context of an outer select)
55
 
  */
56
 
  Name_resolution_context *outer_context;
57
 
 
58
 
  /*
59
 
    List of tables used to resolve the items of this context.  Usually these
60
 
    are tables from the FROM clause of SELECT statement.  The exceptions are
61
 
    INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
62
 
    subquery is not moved to a separate SELECT_LEX.  For these types of
63
 
    statements we have to change this member dynamically to ensure correct
64
 
    name resolution of different parts of the statement.
65
 
  */
66
 
  TableList *table_list;
67
 
  /*
68
 
    In most cases the two table references below replace 'table_list' above
69
 
    for the purpose of name resolution. The first and last name resolution
70
 
    table references allow us to search only in a sub-tree of the nested
71
 
    join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
72
 
    and JOIN ... ON. 
73
 
  */
74
 
  TableList *first_name_resolution_table;
75
 
  /*
76
 
    Last table to search in the list of leaf table references that begins
77
 
    with first_name_resolution_table.
78
 
  */
79
 
  TableList *last_name_resolution_table;
80
 
 
81
 
  /*
82
 
    SELECT_LEX item belong to, in case of merged VIEW it can differ from
83
 
    SELECT_LEX where item was created, so we can't use table_list/field_list
84
 
    from there
85
 
  */
86
 
  st_select_lex *select_lex;
87
 
 
88
 
  /*
89
 
    Processor of errors caused during Item name resolving, now used only to
90
 
    hide underlying tables in errors about views (i.e. it substitute some
91
 
    errors for views)
92
 
  */
93
 
  void (*error_processor)(Session *, void *);
94
 
  void *error_processor_data;
95
 
 
96
 
  /*
97
 
    When true items are resolved in this context both against the
98
 
    SELECT list and this->table_list. If false, items are resolved
99
 
    only against this->table_list.
100
 
  */
101
 
  bool resolve_in_select_list;
102
 
 
103
 
  /*
104
 
    Security context of this name resolution context. It's used for views
105
 
    and is non-zero only if the view is defined with SQL SECURITY DEFINER.
106
 
  */
107
 
  Security_context *security_ctx;
108
 
 
109
 
  Name_resolution_context()
110
 
    :outer_context(0), table_list(0), select_lex(0),
111
 
    error_processor_data(0),
112
 
    security_ctx(0)
113
 
    {}
114
 
 
115
 
  void init()
116
 
  {
117
 
    resolve_in_select_list= false;
118
 
    error_processor= &dummy_error_processor;
119
 
    first_name_resolution_table= NULL;
120
 
    last_name_resolution_table= NULL;
121
 
  }
122
 
 
123
 
  void resolve_in_table_list_only(TableList *tables)
124
 
  {
125
 
    table_list= first_name_resolution_table= tables;
126
 
    resolve_in_select_list= false;
127
 
  }
128
 
 
129
 
  void process_error(Session *session)
130
 
  {
131
 
    (*error_processor)(session, error_processor_data);
132
 
  }
133
 
};
134
 
 
135
 
 
136
 
/*
137
 
  Store and restore the current state of a name resolution context.
138
 
*/
139
 
 
140
 
class Name_resolution_context_state
141
 
{
142
 
private:
143
 
  TableList *save_table_list;
144
 
  TableList *save_first_name_resolution_table;
145
 
  TableList *save_next_name_resolution_table;
146
 
  bool        save_resolve_in_select_list;
147
 
  TableList *save_next_local;
148
 
 
149
 
public:
150
 
  Name_resolution_context_state() {}          /* Remove gcc warning */
151
 
 
152
 
public:
153
 
  /* Save the state of a name resolution context. */
154
 
  void save_state(Name_resolution_context *context, TableList *table_list)
155
 
  {
156
 
    save_table_list=                  context->table_list;
157
 
    save_first_name_resolution_table= context->first_name_resolution_table;
158
 
    save_resolve_in_select_list=      context->resolve_in_select_list;
159
 
    save_next_local=                  table_list->next_local;
160
 
    save_next_name_resolution_table=  table_list->next_name_resolution_table;
161
 
  }
162
 
 
163
 
  /* Restore a name resolution context from saved state. */
164
 
  void restore_state(Name_resolution_context *context, TableList *table_list)
165
 
  {
166
 
    table_list->next_local=                save_next_local;
167
 
    table_list->next_name_resolution_table= save_next_name_resolution_table;
168
 
    context->table_list=                   save_table_list;
169
 
    context->first_name_resolution_table=  save_first_name_resolution_table;
170
 
    context->resolve_in_select_list=       save_resolve_in_select_list;
171
 
  }
172
 
 
173
 
  TableList *get_first_name_resolution_table()
174
 
  {
175
 
    return save_first_name_resolution_table;
176
 
  }
177
 
};
178
35
 
179
36
 
180
37
/*************************************************************************/
1876
1733
  virtual Item *real_item() { return ref; }
1877
1734
};
1878
1735
 
1879
 
#ifdef DRIZZLE_SERVER
1880
 
#include "item_sum.h"
1881
 
#include "item_func.h"
1882
 
#include "item_row.h"
1883
 
#include "item_cmpfunc.h"
1884
 
#include "item_strfunc.h"
1885
 
#include "item_timefunc.h"
1886
 
#include "item_subselect.h"
1887
 
#endif
1888
1736
 
1889
1737
class Item_copy_string :public Item
1890
1738
{
2201
2049
  int save_in_field(Field *field, bool no_conversions);
2202
2050
};
2203
2051
 
2204
 
class Item_cache_row: public Item_cache
2205
 
{
2206
 
  Item_cache  **values;
2207
 
  uint32_t item_count;
2208
 
  bool save_array;
2209
 
public:
2210
 
  Item_cache_row()
2211
 
    :Item_cache(), values(0), item_count(2), save_array(0) {}
2212
 
  
2213
 
  /*
2214
 
    'allocate' used only in row transformer, to preallocate space for row 
2215
 
    cache.
2216
 
  */
2217
 
  bool allocate(uint32_t num);
2218
 
  /*
2219
 
    'setup' is needed only by row => it not called by simple row subselect
2220
 
    (only by IN subselect (in subselect optimizer))
2221
 
  */
2222
 
  bool setup(Item *item);
2223
 
  void store(Item *item);
2224
 
  void illegal_method_call(const char *);
2225
 
  void make_field(Send_field *)
2226
 
  {
2227
 
    illegal_method_call((const char*)"make_field");
2228
 
  };
2229
 
  double val_real()
2230
 
  {
2231
 
    illegal_method_call((const char*)"val");
2232
 
    return 0;
2233
 
  };
2234
 
  int64_t val_int()
2235
 
  {
2236
 
    illegal_method_call((const char*)"val_int");
2237
 
    return 0;
2238
 
  };
2239
 
  String *val_str(String *)
2240
 
  {
2241
 
    illegal_method_call((const char*)"val_str");
2242
 
    return 0;
2243
 
  };
2244
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
2245
 
  {
2246
 
    illegal_method_call((const char*)"val_decimal");
2247
 
    return 0;
2248
 
  };
2249
 
 
2250
 
  enum Item_result result_type() const { return ROW_RESULT; }
2251
 
  
2252
 
  uint32_t cols() { return item_count; }
2253
 
  Item *element_index(uint32_t i) { return values[i]; }
2254
 
  Item **addr(uint32_t i) { return (Item **) (values + i); }
2255
 
  bool check_cols(uint32_t c);
2256
 
  bool null_inside();
2257
 
  void bring_value();
2258
 
  void keep_array() { save_array= 1; }
2259
 
  void cleanup()
2260
 
  {
2261
 
    Item_cache::cleanup();
2262
 
    if (save_array)
2263
 
      memset(values, 0, item_count*sizeof(Item**));
2264
 
    else
2265
 
      values= 0;
2266
 
    return;
2267
 
  }
2268
 
};
2269
 
 
2270
 
 
2271
 
/*
2272
 
  Item_type_holder used to store type. name, length of Item for UNIONS &
2273
 
  derived tables.
2274
 
 
2275
 
  Item_type_holder do not need cleanup() because its time of live limited by
2276
 
  single SP/PS execution.
2277
 
*/
2278
 
class Item_type_holder: public Item
2279
 
{
2280
 
protected:
2281
 
  TYPELIB *enum_set_typelib;
2282
 
  enum_field_types fld_type;
2283
 
 
2284
 
  void get_full_info(Item *item);
2285
 
 
2286
 
  /* It is used to count decimal precision in join_types */
2287
 
  int prev_decimal_int_part;
2288
 
public:
2289
 
  Item_type_holder(Session*, Item*);
2290
 
 
2291
 
  Item_result result_type() const;
2292
 
  enum_field_types field_type() const { return fld_type; };
2293
 
  enum Type type() const { return TYPE_HOLDER; }
2294
 
  double val_real();
2295
 
  int64_t val_int();
2296
 
  my_decimal *val_decimal(my_decimal *);
2297
 
  String *val_str(String*);
2298
 
  bool join_types(Session *session, Item *);
2299
 
  Field *make_field_by_type(Table *table);
2300
 
  static uint32_t display_length(Item *item);
2301
 
  static enum_field_types get_real_type(Item *);
2302
 
};
2303
 
 
2304
2052
 
2305
2053
class st_select_lex;
2306
2054
void mark_select_range_as_dependent(Session *session,
2354
2102
                        bool make_copy_field,
2355
2103
                        uint32_t convert_blob_length);
2356
2104
 
2357
 
#endif
 
2105
#endif /* DRIZZLED_ITEM_H */