1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
21
#ifndef DRIZZLED_FIELD_ITERATOR_H
22
#define DRIZZLED_FIELD_ITERATOR_H
28
Iterator over the fields of a generic table reference.
31
class Field_iterator: public Sql_alloc
34
Field_iterator() {} /* Remove gcc warning */
35
virtual ~Field_iterator() {}
36
virtual void set(TableList *)= 0;
37
virtual void next()= 0;
38
virtual bool end_of_fields()= 0; /* Return 1 at end of list */
39
virtual const char *name()= 0;
40
virtual Item *create_item(THD *)= 0;
41
virtual Field *field()= 0;
46
Iterator over the fields of a base table, view with temporary
50
class Field_iterator_table: public Field_iterator
54
Field_iterator_table() :ptr(0) {}
55
void set(TableList *table);
56
void set_table(Table *table);
57
void next() { ptr++; }
58
bool end_of_fields() { return *ptr == 0; }
60
Item *create_item(THD *thd);
61
Field *field() { return *ptr; }
65
/* Iterator over the fields of a merge view. */
68
Field_iterator interface to the list of materialized fields of a
72
class Field_iterator_natural_join: public Field_iterator
74
List_iterator_fast<Natural_join_column> column_ref_it;
75
Natural_join_column *cur_column_ref;
77
Field_iterator_natural_join() :cur_column_ref(NULL) {}
78
~Field_iterator_natural_join() {}
79
void set(TableList *table);
81
bool end_of_fields() { return !cur_column_ref; }
82
const char *name() { return cur_column_ref->name(); }
83
Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); }
84
Field *field() { return cur_column_ref->field(); }
85
Natural_join_column *column_ref() { return cur_column_ref; }
90
Generic iterator over the fields of an arbitrary table reference.
93
This class unifies the various ways of iterating over the columns
94
of a table reference depending on the type of SQL entity it
95
represents. If such an entity represents a nested table reference,
96
this iterator encapsulates the iteration over the columns of the
97
members of the table reference.
100
The implementation assumes that all underlying NATURAL/USING table
101
references already contain their result columns and are linked into
102
the list TableList::next_name_resolution_table.
105
class Field_iterator_table_ref: public Field_iterator
107
TableList *table_ref, *first_leaf, *last_leaf;
108
Field_iterator_table table_field_it;
109
Field_iterator_natural_join natural_join_it;
110
Field_iterator *field_it;
111
void set_field_iterator();
113
Field_iterator_table_ref() :field_it(NULL) {}
114
void set(TableList *table);
117
{ return (table_ref == last_leaf && field_it->end_of_fields()); }
118
const char *name() { return field_it->name(); }
119
const char *table_name();
120
const char *db_name();
121
Item *create_item(THD *thd) { return field_it->create_item(thd); }
122
Field *field() { return field_it->field(); }
123
Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
124
Natural_join_column *get_natural_column_ref();
128
#endif /* DRIZZLED_FIELD_ITERATOR_H */