1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* Copyright (C) 2008 Sun Microsystems
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DRIZZLED_NAME_RESOLUTION_CONTEXT_H
#define DRIZZLED_NAME_RESOLUTION_CONTEXT_H
class TableList;
class Security_context;
class Session;
class Select_Lex;
/*
Instances of Name_resolution_context store the information necesary for
name resolution of Items and other context analysis of a query made in
fix_fields().
This structure is a part of Select_Lex, a pointer to this structure is
assigned when an item is created (which happens mostly during parsing
(sql_yacc.yy)), but the structure itself will be initialized after parsing
is complete
TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
separate Select_Lex which allow to remove tricks of changing this
structure before and after INSERT/CREATE and its SELECT to make correct
field name resolution.
*/
class Name_resolution_context: public Sql_alloc
{
public:
/*
The name resolution context to search in when an Item cannot be
resolved in this context (the context of an outer select)
*/
Name_resolution_context *outer_context;
/*
List of tables used to resolve the items of this context. Usually these
are tables from the FROM clause of SELECT statement. The exceptions are
INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
subquery is not moved to a separate Select_Lex. For these types of
statements we have to change this member dynamically to ensure correct
name resolution of different parts of the statement.
*/
TableList *table_list;
/*
In most cases the two table references below replace 'table_list' above
for the purpose of name resolution. The first and last name resolution
table references allow us to search only in a sub-tree of the nested
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
and JOIN ... ON.
*/
TableList *first_name_resolution_table;
/*
Last table to search in the list of leaf table references that begins
with first_name_resolution_table.
*/
TableList *last_name_resolution_table;
/*
Select_Lex item belong to, in case of merged VIEW it can differ from
Select_Lex where item was created, so we can't use table_list/field_list
from there
*/
Select_Lex *select_lex;
/*
Processor of errors caused during Item name resolving, now used only to
hide underlying tables in errors about views (i.e. it substitute some
errors for views)
*/
void (*error_processor)(Session *, void *);
void *error_processor_data;
/*
When true items are resolved in this context both against the
SELECT list and this->table_list. If false, items are resolved
only against this->table_list.
*/
bool resolve_in_select_list;
/*
Security context of this name resolution context. It's used for views
and is non-zero only if the view is defined with SQL SECURITY DEFINER.
*/
Security_context *security_ctx;
Name_resolution_context()
:outer_context(0), table_list(0), select_lex(0),
error_processor_data(0),
security_ctx(0)
{}
void init()
{
resolve_in_select_list= false;
error_processor= &dummy_error_processor;
first_name_resolution_table= NULL;
last_name_resolution_table= NULL;
}
void resolve_in_table_list_only(TableList *tables)
{
table_list= first_name_resolution_table= tables;
resolve_in_select_list= false;
}
void process_error(Session *session)
{
(*error_processor)(session, error_processor_data);
}
};
#endif /* DRIZZLED_NAME_RESOLUTION_CONTEXT_H */
|