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 class Item_outer_ref : public Item_direct_ref
00039 {
00040 public:
00041   Item *outer_ref;
00042   /* The aggregate function under which this outer ref is used, if any. */
00043   Item_sum *in_sum_func;
00044   /*
00045     true <=> that the outer_ref is already present in the select list
00046     of the outer select.
00047   */
00048   bool found_in_select_list;
00049   Item_outer_ref(Name_resolution_context *context_arg,
00050                  Item_field *outer_field_arg)
00051     :Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
00052                      outer_field_arg->field_name),
00053     outer_ref(outer_field_arg), in_sum_func(0),
00054     found_in_select_list(0)
00055   {
00056     ref= &outer_ref;
00057     set_properties();
00058     fixed= 0;
00059   }
00060   Item_outer_ref(Name_resolution_context *context_arg, Item **item,
00061                  const char *table_name_arg, const char *field_name_arg,
00062                  bool alias_name_used_arg)
00063     :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
00064                      alias_name_used_arg),
00065     outer_ref(0), in_sum_func(0), found_in_select_list(1)
00066   {}
00067   void save_in_result_field(bool)
00068   {
00069     outer_ref->save_org_in_field(result_field);
00070   }
00071   bool fix_fields(Session *, Item **);
00072   void fix_after_pullout(Select_Lex *new_parent, Item **ref);
00073   table_map used_tables() const
00074   {
00075     return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
00076   }
00077   virtual Ref_Type ref_type() { return OUTER_REF; }
00078 };
00079 
00080 } /* namespace drizzled */
00081