~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/name_resolution_context.h

  • Committer: Monty Taylor
  • Date: 2008-11-16 06:29:53 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116062953-ivdltjmfe009b5fr
Moved stuff into item/

Show diffs side-by-side

added added

removed removed

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