~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Monty Taylor
  • Date: 2008-11-16 04:24:21 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116042421-26x6lxwfezf7rr3c
SplitĀ outĀ Name_resolution_context.

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
/*************************************************************************/
2354
2211
                        bool make_copy_field,
2355
2212
                        uint32_t convert_blob_length);
2356
2213
 
2357
 
#endif
 
2214
#endif /* DRIZZLED_ITEM_H */