~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_iterator.h

  • Committer: Monty Taylor
  • Date: 2008-08-02 00:06:32 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080802000632-jsse0zdd9r6ic5ku
Actually turn gettext on...

Show diffs side-by-side

added added

removed removed

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