~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_iterator.h

  • Committer: Brian Aker
  • Date: 2008-08-19 17:29:21 UTC
  • Revision ID: brian@tangent.org-20080819172921-bc3kpgsrzsdv338l
Moved Field iterator out to its own definition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef USE_PRAGMA_INTERFACE
 
2
#pragma interface                       /* gcc class implementation */
 
3
#endif
 
4
 
 
5
 
 
6
#ifndef DRIZZLED_FIELD_ITERATOR_H
 
7
#define DRIZZLED_FIELD_ITERATOR_H
 
8
 
 
9
class Table;
 
10
class TableList;
 
11
 
 
12
/*
 
13
  Iterator over the fields of a generic table reference.
 
14
*/
 
15
 
 
16
class Field_iterator: public Sql_alloc
 
17
{
 
18
public:
 
19
  Field_iterator() {}                         /* Remove gcc warning */
 
20
  virtual ~Field_iterator() {}
 
21
  virtual void set(TableList *)= 0;
 
22
  virtual void next()= 0;
 
23
  virtual bool end_of_fields()= 0;              /* Return 1 at end of list */
 
24
  virtual const char *name()= 0;
 
25
  virtual Item *create_item(THD *)= 0;
 
26
  virtual Field *field()= 0;
 
27
};
 
28
 
 
29
 
 
30
/* 
 
31
  Iterator over the fields of a base table, view with temporary
 
32
  table, or subquery.
 
33
*/
 
34
 
 
35
class Field_iterator_table: public Field_iterator
 
36
{
 
37
  Field **ptr;
 
38
public:
 
39
  Field_iterator_table() :ptr(0) {}
 
40
  void set(TableList *table);
 
41
  void set_table(Table *table);
 
42
  void next() { ptr++; }
 
43
  bool end_of_fields() { return *ptr == 0; }
 
44
  const char *name();
 
45
  Item *create_item(THD *thd);
 
46
  Field *field() { return *ptr; }
 
47
};
 
48
 
 
49
 
 
50
/* Iterator over the fields of a merge view. */
 
51
 
 
52
/*
 
53
  Field_iterator interface to the list of materialized fields of a
 
54
  NATURAL/USING join.
 
55
*/
 
56
 
 
57
class Field_iterator_natural_join: public Field_iterator
 
58
{
 
59
  List_iterator_fast<Natural_join_column> column_ref_it;
 
60
  Natural_join_column *cur_column_ref;
 
61
public:
 
62
  Field_iterator_natural_join() :cur_column_ref(NULL) {}
 
63
  ~Field_iterator_natural_join() {}
 
64
  void set(TableList *table);
 
65
  void next();
 
66
  bool end_of_fields() { return !cur_column_ref; }
 
67
  const char *name() { return cur_column_ref->name(); }
 
68
  Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); }
 
69
  Field *field() { return cur_column_ref->field(); }
 
70
  Natural_join_column *column_ref() { return cur_column_ref; }
 
71
};
 
72
 
 
73
 
 
74
/*
 
75
  Generic iterator over the fields of an arbitrary table reference.
 
76
 
 
77
  DESCRIPTION
 
78
    This class unifies the various ways of iterating over the columns
 
79
    of a table reference depending on the type of SQL entity it
 
80
    represents. If such an entity represents a nested table reference,
 
81
    this iterator encapsulates the iteration over the columns of the
 
82
    members of the table reference.
 
83
 
 
84
  IMPLEMENTATION
 
85
    The implementation assumes that all underlying NATURAL/USING table
 
86
    references already contain their result columns and are linked into
 
87
    the list TableList::next_name_resolution_table.
 
88
*/
 
89
 
 
90
class Field_iterator_table_ref: public Field_iterator
 
91
{
 
92
  TableList *table_ref, *first_leaf, *last_leaf;
 
93
  Field_iterator_table        table_field_it;
 
94
  Field_iterator_natural_join natural_join_it;
 
95
  Field_iterator *field_it;
 
96
  void set_field_iterator();
 
97
public:
 
98
  Field_iterator_table_ref() :field_it(NULL) {}
 
99
  void set(TableList *table);
 
100
  void next();
 
101
  bool end_of_fields()
 
102
  { return (table_ref == last_leaf && field_it->end_of_fields()); }
 
103
  const char *name() { return field_it->name(); }
 
104
  const char *table_name();
 
105
  const char *db_name();
 
106
  Item *create_item(THD *thd) { return field_it->create_item(thd); }
 
107
  Field *field() { return field_it->field(); }
 
108
  Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
 
109
  Natural_join_column *get_natural_column_ref();
 
110
};
 
111
 
 
112
 
 
113
#endif /* DRIZZLED_FIELD_ITERATOR_H */