~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/name_resolution_context.h

Merge Valgrind.

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_NAME_RESOLUTION_CONTEXT_H
 
21
#define DRIZZLED_NAME_RESOLUTION_CONTEXT_H
 
22
 
 
23
#include "drizzled/item.h"
 
24
 
 
25
class TableList;
 
26
class Security_context;
 
27
class Session;
 
28
class Select_Lex;
 
29
 
 
30
/**
 
31
 * Instances of Name_resolution_context store the information necesary for
 
32
 * name resolution of Items and other context analysis of a query made in
 
33
 * fix_fields().
 
34
 *
 
35
 * This structure is a part of Select_Lex, a pointer to this structure is
 
36
 * assigned when an item is created (which happens mostly during  parsing
 
37
 * (sql_yacc.yy)), but the structure itself will be initialized after parsing
 
38
 * is complete
 
39
 *
 
40
 * @todo
 
41
 *
 
42
 * Move subquery of INSERT ... SELECT and CREATE ... SELECT to
 
43
 * separate Select_Lex which allow to remove tricks of changing this
 
44
 * structure before and after INSERT/CREATE and its SELECT to make correct
 
45
 * field name resolution.
 
46
 */
 
47
class Name_resolution_context: public Sql_alloc
 
48
{
 
49
public:
 
50
  /**
 
51
   * The name resolution context to search in when an Item cannot be
 
52
   * resolved in this context (the context of an outer select)
 
53
   */
 
54
  Name_resolution_context *outer_context;
 
55
 
 
56
  /**
 
57
   * List of tables used to resolve the items of this context.  Usually these
 
58
   * are tables from the FROM clause of SELECT statement.  The exceptions are
 
59
   * INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
 
60
   * subquery is not moved to a separate Select_Lex.  For these types of
 
61
   * statements we have to change this member dynamically to ensure correct
 
62
   * name resolution of different parts of the statement.
 
63
   */
 
64
  TableList *table_list;
 
65
  /**
 
66
   * In most cases the two table references below replace 'table_list' above
 
67
   * for the purpose of name resolution. The first and last name resolution
 
68
   * table references allow us to search only in a sub-tree of the nested
 
69
   * join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
 
70
   * and JOIN ... ON.
 
71
   */
 
72
  TableList *first_name_resolution_table;
 
73
  /**
 
74
   * Last table to search in the list of leaf table references that begins
 
75
   * with first_name_resolution_table.
 
76
   */
 
77
  TableList *last_name_resolution_table;
 
78
 
 
79
  /**
 
80
   * Select_Lex item belong to, in case of merged VIEW it can differ from
 
81
   * Select_Lex where item was created, so we can't use table_list/field_list
 
82
   * from there
 
83
   */
 
84
  Select_Lex *select_lex;
 
85
 
 
86
  /**
 
87
   * Processor of errors caused during Item name resolving, now used only to
 
88
   * hide underlying tables in errors about views (i.e. it substitute some
 
89
   * errors for views)
 
90
   */
 
91
  void (*error_processor)(Session *, void *);
 
92
  void *error_processor_data;
 
93
 
 
94
  /**
 
95
   * When true items are resolved in this context both against the
 
96
   * SELECT list and this->table_list. If false, items are resolved
 
97
   * only against this->table_list.
 
98
   */
 
99
  bool resolve_in_select_list;
 
100
 
 
101
  /**
 
102
   * Security context of this name resolution context. It's used for views
 
103
   * and is non-zero only if the view is defined with SQL SECURITY DEFINER.
 
104
   */
 
105
  Security_context *security_ctx;
 
106
 
 
107
  Name_resolution_context()
 
108
    :
 
109
      outer_context(0), 
 
110
      table_list(0), 
 
111
      select_lex(0),
 
112
      error_processor_data(0),
 
113
      security_ctx(0)
 
114
    {}
 
115
 
 
116
  inline void init()
 
117
  {
 
118
    resolve_in_select_list= false;
 
119
    error_processor= &dummy_error_processor;
 
120
    first_name_resolution_table= NULL;
 
121
    last_name_resolution_table= NULL;
 
122
  }
 
123
 
 
124
  inline void resolve_in_table_list_only(TableList *tables)
 
125
  {
 
126
    table_list= first_name_resolution_table= tables;
 
127
    resolve_in_select_list= false;
 
128
  }
 
129
 
 
130
  inline void process_error(Session *session)
 
131
  {
 
132
    (*error_processor)(session, error_processor_data);
 
133
  }
 
134
};
 
135
 
 
136
#endif /* DRIZZLED_NAME_RESOLUTION_CONTEXT_H */