Drizzled Public API Documentation

field_iterator.h
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, Inc.
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 
20 
21 #pragma once
22 
23 #include <drizzled/memory/sql_alloc.h>
24 #include <drizzled/sql_list.h>
25 #include <drizzled/natural_join_column.h>
26 #include <drizzled/item/field.h>
27 
28 namespace drizzled {
29 
30 /*
31  Iterator over the fields of a generic table reference.
32 */
33 
35 {
36 public:
37  virtual ~Field_iterator() {}
38  virtual void set(TableList *)= 0;
39  virtual void next()= 0;
40  virtual bool end_of_fields() const= 0; /* Return true at end of list */
41  virtual const char *name() const= 0;
42  virtual Item *create_item(Session *)= 0;
43  virtual Field *field()= 0;
44 };
45 
46 
47 /*
48  Iterator over the fields of a base table, view with temporary
49  table, or subquery.
50 */
51 
53 {
54  Field **ptr;
55 public:
56  Field_iterator_table() :ptr(0) {}
57  void set(TableList *table);
58  void set_table(Table *table);
59  void next() { ptr++; }
60  bool end_of_fields() const { return *ptr == 0; }
61  const char *name() const;
62  Item *create_item(Session *session);
63  Field *field() { return *ptr; }
64 };
65 
66 
67 /* Iterator over the fields of a merge view. */
68 
69 /*
70  Field_iterator interface to the list of materialized fields of a
71  NATURAL/USING join.
72 */
73 
75 {
77  Natural_join_column *cur_column_ref;
78 public:
79  Field_iterator_natural_join() : cur_column_ref(NULL) {}
80  void set(TableList *table);
81  void next();
82  bool end_of_fields() const { return not cur_column_ref; }
83  const char *name() const { return cur_column_ref->name(); }
84  Item *create_item(Session *session) { return cur_column_ref->create_item(session); }
85  Field *field() { return cur_column_ref->field(); }
86  Natural_join_column *column_ref() { return cur_column_ref; }
87 };
88 
89 
90 /*
91  Generic iterator over the fields of an arbitrary table reference.
92 
93  DESCRIPTION
94  This class unifies the various ways of iterating over the columns
95  of a table reference depending on the type of SQL entity it
96  represents. If such an entity represents a nested table reference,
97  this iterator encapsulates the iteration over the columns of the
98  members of the table reference.
99 
100  IMPLEMENTATION
101  The implementation assumes that all underlying NATURAL/USING table
102  references already contain their result columns and are linked into
103  the list TableList::next_name_resolution_table.
104 */
105 
107 {
108  TableList *table_ref, *first_leaf, *last_leaf;
109  Field_iterator_table table_field_it;
110  Field_iterator_natural_join natural_join_it;
111  Field_iterator *field_it;
112  void set_field_iterator();
113 public:
114  Field_iterator_table_ref() :field_it(NULL) {}
115  void set(TableList *table);
116  void next();
117  bool end_of_fields() const
118  { return (table_ref == last_leaf && field_it->end_of_fields()); }
119  const char *name() const { return field_it->name(); }
120  const char *table_name();
121  const char *db_name();
122  Item *create_item(Session *session) { return field_it->create_item(session); }
123  Field *field() { return field_it->field(); }
124  Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
125  Natural_join_column *get_natural_column_ref();
126 };
127 
128 } /* namespace drizzled */
129