~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
520.8.6 by Monty Taylor
Removed handler from common_includes.
24
#include <drizzled/sql_alloc.h>
25
#include <drizzled/sql_list.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
26
#include <drizzled/natural_join_column.h>
520.8.6 by Monty Taylor
Removed handler from common_includes.
27
353 by Brian Aker
Moved Field iterator out to its own definition.
28
class Table;
29
class TableList;
30
31
/*
32
  Iterator over the fields of a generic table reference.
33
*/
34
35
class Field_iterator: public Sql_alloc
36
{
37
public:
38
  Field_iterator() {}                         /* Remove gcc warning */
39
  virtual ~Field_iterator() {}
40
  virtual void set(TableList *)= 0;
41
  virtual void next()= 0;
42
  virtual bool end_of_fields()= 0;              /* Return 1 at end of list */
43
  virtual const char *name()= 0;
520.1.21 by Brian Aker
THD -> Session rename
44
  virtual Item *create_item(Session *)= 0;
353 by Brian Aker
Moved Field iterator out to its own definition.
45
  virtual Field *field()= 0;
46
};
47
48
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
49
/*
353 by Brian Aker
Moved Field iterator out to its own definition.
50
  Iterator over the fields of a base table, view with temporary
51
  table, or subquery.
52
*/
53
54
class Field_iterator_table: public Field_iterator
55
{
56
  Field **ptr;
57
public:
58
  Field_iterator_table() :ptr(0) {}
59
  void set(TableList *table);
60
  void set_table(Table *table);
61
  void next() { ptr++; }
62
  bool end_of_fields() { return *ptr == 0; }
63
  const char *name();
520.1.22 by Brian Aker
Second pass of thd cleanup
64
  Item *create_item(Session *session);
353 by Brian Aker
Moved Field iterator out to its own definition.
65
  Field *field() { return *ptr; }
66
};
67
68
69
/* Iterator over the fields of a merge view. */
70
71
/*
72
  Field_iterator interface to the list of materialized fields of a
73
  NATURAL/USING join.
74
*/
75
76
class Field_iterator_natural_join: public Field_iterator
77
{
78
  List_iterator_fast<Natural_join_column> column_ref_it;
79
  Natural_join_column *cur_column_ref;
80
public:
81
  Field_iterator_natural_join() :cur_column_ref(NULL) {}
82
  ~Field_iterator_natural_join() {}
83
  void set(TableList *table);
84
  void next();
85
  bool end_of_fields() { return !cur_column_ref; }
86
  const char *name() { return cur_column_ref->name(); }
520.1.22 by Brian Aker
Second pass of thd cleanup
87
  Item *create_item(Session *session) { return cur_column_ref->create_item(session); }
353 by Brian Aker
Moved Field iterator out to its own definition.
88
  Field *field() { return cur_column_ref->field(); }
89
  Natural_join_column *column_ref() { return cur_column_ref; }
90
};
91
92
93
/*
94
  Generic iterator over the fields of an arbitrary table reference.
95
96
  DESCRIPTION
97
    This class unifies the various ways of iterating over the columns
98
    of a table reference depending on the type of SQL entity it
99
    represents. If such an entity represents a nested table reference,
100
    this iterator encapsulates the iteration over the columns of the
101
    members of the table reference.
102
103
  IMPLEMENTATION
104
    The implementation assumes that all underlying NATURAL/USING table
105
    references already contain their result columns and are linked into
106
    the list TableList::next_name_resolution_table.
107
*/
108
109
class Field_iterator_table_ref: public Field_iterator
110
{
111
  TableList *table_ref, *first_leaf, *last_leaf;
112
  Field_iterator_table        table_field_it;
113
  Field_iterator_natural_join natural_join_it;
114
  Field_iterator *field_it;
115
  void set_field_iterator();
116
public:
117
  Field_iterator_table_ref() :field_it(NULL) {}
118
  void set(TableList *table);
119
  void next();
120
  bool end_of_fields()
121
  { return (table_ref == last_leaf && field_it->end_of_fields()); }
122
  const char *name() { return field_it->name(); }
123
  const char *table_name();
124
  const char *db_name();
520.1.22 by Brian Aker
Second pass of thd cleanup
125
  Item *create_item(Session *session) { return field_it->create_item(session); }
353 by Brian Aker
Moved Field iterator out to its own definition.
126
  Field *field() { return field_it->field(); }
127
  Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
128
  Natural_join_column *get_natural_column_ref();
129
};
130
131
132
#endif /* DRIZZLED_FIELD_ITERATOR_H */