Drizzled Public API Documentation

outer_ref.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 #pragma once
00021 
00022 #include <drizzled/item/ref.h>
00023 #include <drizzled/item/direct_ref.h>
00024 #include <drizzled/item/field.h>
00025 
00026 /*
00027   Class for outer fields.
00028   An object of this class is created when the select where the outer field was
00029   resolved is a grouping one. After it has been fixed the ref field will point
00030   to either an Item_ref or an Item_direct_ref object which will be used to
00031   access the field.
00032   See also comments for the fix_inner_refs() and the
00033   Item_field::fix_outer_field() functions.
00034 */
00035 
00036 namespace drizzled
00037 {
00038 
00039 class Item_outer_ref :public Item_direct_ref
00040 {
00041 public:
00042   Item *outer_ref;
00043   /* The aggregate function under which this outer ref is used, if any. */
00044   Item_sum *in_sum_func;
00045   /*
00046     true <=> that the outer_ref is already present in the select list
00047     of the outer select.
00048   */
00049   bool found_in_select_list;
00050   Item_outer_ref(Name_resolution_context *context_arg,
00051                  Item_field *outer_field_arg)
00052     :Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
00053                      outer_field_arg->field_name),
00054     outer_ref(outer_field_arg), in_sum_func(0),
00055     found_in_select_list(0)
00056   {
00057     ref= &outer_ref;
00058     set_properties();
00059     fixed= 0;
00060   }
00061   Item_outer_ref(Name_resolution_context *context_arg, Item **item,
00062                  const char *table_name_arg, const char *field_name_arg,
00063                  bool alias_name_used_arg)
00064     :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
00065                      alias_name_used_arg),
00066     outer_ref(0), in_sum_func(0), found_in_select_list(1)
00067   {}
00068   void save_in_result_field(bool)
00069   {
00070     outer_ref->save_org_in_field(result_field);
00071   }
00072   bool fix_fields(Session *, Item **);
00073   void fix_after_pullout(Select_Lex *new_parent, Item **ref);
00074   table_map used_tables() const
00075   {
00076     return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
00077   }
00078   virtual Ref_Type ref_type() { return OUTER_REF; }
00079 };
00080 
00081 } /* namespace drizzled */
00082