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 class Table;
00031 class TableList;
00032 
00033 /*
00034   Iterator over the fields of a generic table reference.
00035 */
00036 
00037 class Field_iterator: public memory::SqlAlloc
00038 {
00039 public:
00040   Field_iterator() {}                         /* Remove gcc warning */
00041   virtual ~Field_iterator() {}
00042   virtual void set(TableList *)= 0;
00043   virtual void next()= 0;
00044   virtual bool end_of_fields()= 0;              /* Return 1 at end of list */
00045   virtual const char *name()= 0;
00046   virtual Item *create_item(Session *)= 0;
00047   virtual Field *field()= 0;
00048 };
00049 
00050 
00051 /*
00052   Iterator over the fields of a base table, view with temporary
00053   table, or subquery.
00054 */
00055 
00056 class Field_iterator_table: public Field_iterator
00057 {
00058   Field **ptr;
00059 public:
00060   Field_iterator_table() :ptr(0) {}
00061   void set(TableList *table);
00062   void set_table(Table *table);
00063   void next() { ptr++; }
00064   bool end_of_fields() { return *ptr == 0; }
00065   const char *name();
00066   Item *create_item(Session *session);
00067   Field *field() { return *ptr; }
00068 };
00069 
00070 
00071 /* Iterator over the fields of a merge view. */
00072 
00073 /*
00074   Field_iterator interface to the list of materialized fields of a
00075   NATURAL/USING join.
00076 */
00077 
00078 class Field_iterator_natural_join: public Field_iterator
00079 {
00080   List<Natural_join_column>::iterator column_ref_it;
00081   Natural_join_column *cur_column_ref;
00082 public:
00083   Field_iterator_natural_join() :cur_column_ref(NULL) {}
00084   ~Field_iterator_natural_join() {}
00085   void set(TableList *table);
00086   void next();
00087   bool end_of_fields() { return !cur_column_ref; }
00088   const char *name() { return cur_column_ref->name(); }
00089   Item *create_item(Session *session) { return cur_column_ref->create_item(session); }
00090   Field *field() { return cur_column_ref->field(); }
00091   Natural_join_column *column_ref() { return cur_column_ref; }
00092 };
00093 
00094 
00095 /*
00096   Generic iterator over the fields of an arbitrary table reference.
00097 
00098   DESCRIPTION
00099     This class unifies the various ways of iterating over the columns
00100     of a table reference depending on the type of SQL entity it
00101     represents. If such an entity represents a nested table reference,
00102     this iterator encapsulates the iteration over the columns of the
00103     members of the table reference.
00104 
00105   IMPLEMENTATION
00106     The implementation assumes that all underlying NATURAL/USING table
00107     references already contain their result columns and are linked into
00108     the list TableList::next_name_resolution_table.
00109 */
00110 
00111 class Field_iterator_table_ref: public Field_iterator
00112 {
00113   TableList *table_ref, *first_leaf, *last_leaf;
00114   Field_iterator_table        table_field_it;
00115   Field_iterator_natural_join natural_join_it;
00116   Field_iterator *field_it;
00117   void set_field_iterator();
00118 public:
00119   Field_iterator_table_ref() :field_it(NULL) {}
00120   void set(TableList *table);
00121   void next();
00122   bool end_of_fields()
00123   { return (table_ref == last_leaf && field_it->end_of_fields()); }
00124   const char *name() { return field_it->name(); }
00125   const char *table_name();
00126   const char *db_name();
00127   Item *create_item(Session *session) { return field_it->create_item(session); }
00128   Field *field() { return field_it->field(); }
00129   Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
00130   Natural_join_column *get_natural_column_ref();
00131 };
00132 
00133 } /* namespace drizzled */
00134