~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <drizzled/item/field.h>
30
30
#include <drizzled/item/outer_ref.h>
31
31
#include <drizzled/plugin/client.h>
 
32
#include <drizzled/item/subselect.h>
 
33
#include <drizzled/sql_lex.h>
32
34
 
33
35
#include <boost/dynamic_bitset.hpp>
34
36
 
165
167
   have_privileges(0),
166
168
   any_privileges(0)
167
169
{
168
 
  Select_Lex *select= getSession().getLex()->current_select;
 
170
  Select_Lex *select= getSession().lex().current_select;
169
171
  collation.set(DERIVATION_IMPLICIT);
170
172
 
171
173
  if (select && select->parsing_place != IN_HAVING)
496
498
  */
497
499
  Name_resolution_context *last_checked_context= context;
498
500
  Item **ref= (Item **) not_found_item;
499
 
  Select_Lex *current_sel= (Select_Lex *) session->getLex()->current_select;
 
501
  Select_Lex *current_sel= (Select_Lex *) session->lex().current_select;
500
502
  Name_resolution_context *outer_context= 0;
501
503
  Select_Lex *select= 0;
502
504
  /* Currently derived tables cannot be correlated */
560
562
            ;
561
563
            if (!(rf= new Item_outer_ref(context, this)))
562
564
              return -1;
563
 
            session->change_item_tree(reference, rf);
 
565
            *reference= rf;
564
566
            select->inner_refs_list.push_back(rf);
565
 
            rf->in_sum_func= session->getLex()->in_sum_func;
 
567
            rf->in_sum_func= session->lex().in_sum_func;
566
568
          }
567
569
          /*
568
570
            A reference is resolved to a nest level that's outer or the same as
569
571
            the nest level of the enclosing set function : adjust the value of
570
572
            max_arg_level for the function if it's needed.
571
573
          */
572
 
          if (session->getLex()->in_sum_func &&
573
 
              session->getLex()->in_sum_func->nest_level >= select->nest_level)
 
574
          if (session->lex().in_sum_func &&
 
575
              session->lex().in_sum_func->nest_level >= select->nest_level)
574
576
          {
575
577
            Item::Type ref_type= (*reference)->type();
576
 
            set_if_bigger(session->getLex()->in_sum_func->max_arg_level,
 
578
            set_if_bigger(session->lex().in_sum_func->max_arg_level,
577
579
                          select->nest_level);
578
580
            set_field(*from_field);
579
581
            fixed= 1;
682
684
    if (place != IN_HAVING && select->group_list.elements)
683
685
    {
684
686
      outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
685
 
      ((Item_outer_ref*)rf)->in_sum_func= session->getLex()->in_sum_func;
 
687
      ((Item_outer_ref*)rf)->in_sum_func= session->lex().in_sum_func;
686
688
    }
687
 
    session->change_item_tree(reference, rf);
 
689
    *reference= rf;
688
690
    /*
689
691
      rf is Item_ref => never substitute other items (in this case)
690
692
      during fix_fields() => we can use rf after fix_fields()
711
713
                       (char*) cached_table->alias, (char*) field_name);
712
714
      if (!rf)
713
715
        return -1;
714
 
      session->change_item_tree(reference, rf);
 
716
      *reference= rf;
715
717
      /*
716
718
        rf is Item_ref => never substitute other items (in this case)
717
719
        during fix_fields() => we can use rf after fix_fields()
788
790
                                          context->first_name_resolution_table,
789
791
                                          context->last_name_resolution_table,
790
792
                                          reference,
791
 
                                          session->getLex()->use_only_table_context ?
 
793
                                          session->lex().use_only_table_context ?
792
794
                                            REPORT_ALL_ERRORS :
793
795
                                            IGNORE_EXCEPT_NON_UNIQUE, true)) ==
794
796
        not_found_field)
795
797
    {
796
798
      int ret;
797
799
      /* Look up in current select's item_list to find aliased fields */
798
 
      if (session->getLex()->current_select->is_item_list_lookup)
 
800
      if (session->lex().current_select->is_item_list_lookup)
799
801
      {
800
802
        uint32_t counter;
801
803
        enum_resolution_type resolution;
802
804
        Item** res= find_item_in_list(session,
803
 
                                      this, session->getLex()->current_select->item_list,
 
805
                                      this, session->lex().current_select->item_list,
804
806
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
805
807
                                      &resolution);
806
808
        if (!res)
841
843
            Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
842
844
            if (!rf)
843
845
              return 1;
844
 
            session->change_item_tree(reference, rf);
 
846
            *reference= rf;
845
847
            /*
846
848
              Because Item_ref never substitutes itself with other items
847
849
              in Item_ref::fix_fields(), we can safely use the original
888
890
      return false;
889
891
 
890
892
    set_field(from_field);
891
 
    if (session->getLex()->in_sum_func &&
892
 
        session->getLex()->in_sum_func->nest_level ==
893
 
        session->getLex()->current_select->nest_level)
 
893
    if (session->lex().in_sum_func &&
 
894
        session->lex().in_sum_func->nest_level ==
 
895
        session->lex().current_select->nest_level)
894
896
    {
895
 
      set_if_bigger(session->getLex()->in_sum_func->max_arg_level,
896
 
                    session->getLex()->current_select->nest_level);
 
897
      set_if_bigger(session->lex().in_sum_func->max_arg_level,
 
898
                    session->lex().current_select->nest_level);
897
899
    }
898
900
  }
899
901
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
1252
1254
  {
1253
1255
    List<Item> *all_fields= &select->join->all_fields;
1254
1256
    Item **ref_pointer_array= select->ref_pointer_array;
1255
 
    int el= all_fields->elements;
 
1257
    int el= all_fields->size();
1256
1258
    Item_ref *ref;
1257
1259
 
1258
1260
    ref_pointer_array[el]= (Item*)this;
1265
1267
}
1266
1268
 
1267
1269
 
1268
 
void Item_field::print(String *str, enum_query_type query_type)
 
1270
void Item_field::print(String *str)
1269
1271
{
1270
1272
  if (field && field->getTable()->const_table)
1271
1273
  {
1282
1284
    }
1283
1285
    return;
1284
1286
  }
1285
 
  Item_ident::print(str, query_type);
 
1287
  Item_ident::print(str);
1286
1288
}
1287
1289
 
1288
1290