~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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
353 by Brian Aker
Moved Field iterator out to its own definition.
20
21
#ifndef DRIZZLED_FIELD_ITERATOR_H
22
#define DRIZZLED_FIELD_ITERATOR_H
23
24
class Table;
25
class TableList;
26
27
/*
28
  Iterator over the fields of a generic table reference.
29
*/
30
31
class Field_iterator: public Sql_alloc
32
{
33
public:
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;
42
};
43
44
45
/* 
46
  Iterator over the fields of a base table, view with temporary
47
  table, or subquery.
48
*/
49
50
class Field_iterator_table: public Field_iterator
51
{
52
  Field **ptr;
53
public:
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; }
59
  const char *name();
60
  Item *create_item(THD *thd);
61
  Field *field() { return *ptr; }
62
};
63
64
65
/* Iterator over the fields of a merge view. */
66
67
/*
68
  Field_iterator interface to the list of materialized fields of a
69
  NATURAL/USING join.
70
*/
71
72
class Field_iterator_natural_join: public Field_iterator
73
{
74
  List_iterator_fast<Natural_join_column> column_ref_it;
75
  Natural_join_column *cur_column_ref;
76
public:
77
  Field_iterator_natural_join() :cur_column_ref(NULL) {}
78
  ~Field_iterator_natural_join() {}
79
  void set(TableList *table);
80
  void next();
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; }
86
};
87
88
89
/*
90
  Generic iterator over the fields of an arbitrary table reference.
91
92
  DESCRIPTION
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.
98
99
  IMPLEMENTATION
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.
103
*/
104
105
class Field_iterator_table_ref: public Field_iterator
106
{
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();
112
public:
113
  Field_iterator_table_ref() :field_it(NULL) {}
114
  void set(TableList *table);
115
  void next();
116
  bool end_of_fields()
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();
125
};
126
127
128
#endif /* DRIZZLED_FIELD_ITERATOR_H */