Drizzled Public API Documentation

field_iterator.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 
00021 #pragma once
00022 
00023 #include <drizzled/memory/sql_alloc.h>
00024 #include <drizzled/sql_list.h>
00025 #include <drizzled/natural_join_column.h>
00026 #include <drizzled/item/field.h>
00027 
00028 namespace drizzled {
00029 
00030 /*
00031   Iterator over the fields of a generic table reference.
00032 */
00033 
00034 class Field_iterator : public memory::SqlAlloc
00035 {
00036 public:
00037   virtual ~Field_iterator() {}
00038   virtual void set(TableList *)= 0;
00039   virtual void next()= 0;
00040   virtual bool end_of_fields() const= 0;              /* Return true at end of list */
00041   virtual const char *name() const= 0;
00042   virtual Item *create_item(Session *)= 0;
00043   virtual Field *field()= 0;
00044 };
00045 
00046 
00047 /*
00048   Iterator over the fields of a base table, view with temporary
00049   table, or subquery.
00050 */
00051 
00052 class Field_iterator_table : public Field_iterator
00053 {
00054   Field **ptr;
00055 public:
00056   Field_iterator_table() :ptr(0) {}
00057   void set(TableList *table);
00058   void set_table(Table *table);
00059   void next() { ptr++; }
00060   bool end_of_fields() const { return *ptr == 0; }
00061   const char *name() const;
00062   Item *create_item(Session *session);
00063   Field *field() { return *ptr; }
00064 };
00065 
00066 
00067 /* Iterator over the fields of a merge view. */
00068 
00069 /*
00070   Field_iterator interface to the list of materialized fields of a
00071   NATURAL/USING join.
00072 */
00073 
00074 class Field_iterator_natural_join: public Field_iterator
00075 {
00076   List<Natural_join_column>::iterator column_ref_it;
00077   Natural_join_column *cur_column_ref;
00078 public:
00079   Field_iterator_natural_join() : cur_column_ref(NULL) {}
00080   void set(TableList *table);
00081   void next();
00082   bool end_of_fields() const { return not cur_column_ref; }
00083   const char *name() const { return cur_column_ref->name(); }
00084   Item *create_item(Session *session) { return cur_column_ref->create_item(session); }
00085   Field *field() { return cur_column_ref->field(); }
00086   Natural_join_column *column_ref() { return cur_column_ref; }
00087 };
00088 
00089 
00090 /*
00091   Generic iterator over the fields of an arbitrary table reference.
00092 
00093   DESCRIPTION
00094     This class unifies the various ways of iterating over the columns
00095     of a table reference depending on the type of SQL entity it
00096     represents. If such an entity represents a nested table reference,
00097     this iterator encapsulates the iteration over the columns of the
00098     members of the table reference.
00099 
00100   IMPLEMENTATION
00101     The implementation assumes that all underlying NATURAL/USING table
00102     references already contain their result columns and are linked into
00103     the list TableList::next_name_resolution_table.
00104 */
00105 
00106 class Field_iterator_table_ref: public Field_iterator
00107 {
00108   TableList *table_ref, *first_leaf, *last_leaf;
00109   Field_iterator_table        table_field_it;
00110   Field_iterator_natural_join natural_join_it;
00111   Field_iterator *field_it;
00112   void set_field_iterator();
00113 public:
00114   Field_iterator_table_ref() :field_it(NULL) {}
00115   void set(TableList *table);
00116   void next();
00117   bool end_of_fields() const
00118   { return (table_ref == last_leaf && field_it->end_of_fields()); }
00119   const char *name() const { return field_it->name(); }
00120   const char *table_name();
00121   const char *db_name();
00122   Item *create_item(Session *session) { return field_it->create_item(session); }
00123   Field *field() { return field_it->field(); }
00124   Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
00125   Natural_join_column *get_natural_column_ref();
00126 };
00127 
00128 } /* namespace drizzled */
00129