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
|
#ifdef USE_PRAGMA_INTERFACE
#pragma interface /* gcc class implementation */
#endif
#ifndef DRIZZLED_FIELD_ITERATOR_H
#define DRIZZLED_FIELD_ITERATOR_H
class Table;
class TableList;
/*
Iterator over the fields of a generic table reference.
*/
class Field_iterator: public Sql_alloc
{
public:
Field_iterator() {} /* Remove gcc warning */
virtual ~Field_iterator() {}
virtual void set(TableList *)= 0;
virtual void next()= 0;
virtual bool end_of_fields()= 0; /* Return 1 at end of list */
virtual const char *name()= 0;
virtual Item *create_item(THD *)= 0;
virtual Field *field()= 0;
};
/*
Iterator over the fields of a base table, view with temporary
table, or subquery.
*/
class Field_iterator_table: public Field_iterator
{
Field **ptr;
public:
Field_iterator_table() :ptr(0) {}
void set(TableList *table);
void set_table(Table *table);
void next() { ptr++; }
bool end_of_fields() { return *ptr == 0; }
const char *name();
Item *create_item(THD *thd);
Field *field() { return *ptr; }
};
/* Iterator over the fields of a merge view. */
/*
Field_iterator interface to the list of materialized fields of a
NATURAL/USING join.
*/
class Field_iterator_natural_join: public Field_iterator
{
List_iterator_fast<Natural_join_column> column_ref_it;
Natural_join_column *cur_column_ref;
public:
Field_iterator_natural_join() :cur_column_ref(NULL) {}
~Field_iterator_natural_join() {}
void set(TableList *table);
void next();
bool end_of_fields() { return !cur_column_ref; }
const char *name() { return cur_column_ref->name(); }
Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); }
Field *field() { return cur_column_ref->field(); }
Natural_join_column *column_ref() { return cur_column_ref; }
};
/*
Generic iterator over the fields of an arbitrary table reference.
DESCRIPTION
This class unifies the various ways of iterating over the columns
of a table reference depending on the type of SQL entity it
represents. If such an entity represents a nested table reference,
this iterator encapsulates the iteration over the columns of the
members of the table reference.
IMPLEMENTATION
The implementation assumes that all underlying NATURAL/USING table
references already contain their result columns and are linked into
the list TableList::next_name_resolution_table.
*/
class Field_iterator_table_ref: public Field_iterator
{
TableList *table_ref, *first_leaf, *last_leaf;
Field_iterator_table table_field_it;
Field_iterator_natural_join natural_join_it;
Field_iterator *field_it;
void set_field_iterator();
public:
Field_iterator_table_ref() :field_it(NULL) {}
void set(TableList *table);
void next();
bool end_of_fields()
{ return (table_ref == last_leaf && field_it->end_of_fields()); }
const char *name() { return field_it->name(); }
const char *table_name();
const char *db_name();
Item *create_item(THD *thd) { return field_it->create_item(thd); }
Field *field() { return field_it->field(); }
Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
Natural_join_column *get_natural_column_ref();
};
#endif /* DRIZZLED_FIELD_ITERATOR_H */
|