~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <config.h>
21
21
 
22
22
#include <drizzled/session.h>
23
23
#include <drizzled/table.h>
56
56
bool Item_field::collect_item_field_processor(unsigned char *arg)
57
57
{
58
58
  List<Item_field> *item_list= (List<Item_field>*) arg;
59
 
  List_iterator<Item_field> item_list_it(*item_list);
 
59
  List<Item_field>::iterator item_list_it(item_list->begin());
60
60
  Item_field *curr_item;
61
61
  while ((curr_item= item_list_it++))
62
62
  {
111
111
{
112
112
  Table *table= (Table *) arg;
113
113
  if (field->getTable() == table || !table)
114
 
    field->getTable()->setReadSet(field->field_index);
 
114
    field->getTable()->setReadSet(field->position());
115
115
 
116
116
  return 0;
117
117
}
165
165
   have_privileges(0),
166
166
   any_privileges(0)
167
167
{
168
 
  Select_Lex *select= current_session->lex->current_select;
 
168
  Select_Lex *select= getSession().getLex()->current_select;
169
169
  collation.set(DERIVATION_IMPLICIT);
170
170
 
171
171
  if (select && select->parsing_place != IN_HAVING)
246
246
}
247
247
 
248
248
 
249
 
my_decimal *Item_field::val_decimal(my_decimal *decimal_value)
 
249
type::Decimal *Item_field::val_decimal(type::Decimal *decimal_value)
250
250
{
251
251
  if ((null_value= field->is_null()))
252
252
    return 0;
262
262
  return result_field->val_str(str,&str_value);
263
263
}
264
264
 
265
 
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
265
bool Item_field::get_date(type::Time &ltime,uint32_t fuzzydate)
266
266
{
267
267
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
268
268
  {
269
 
    memset(ltime, 0, sizeof(*ltime));
 
269
    ltime.reset();
270
270
    return 1;
271
271
  }
272
272
  return 0;
273
273
}
274
274
 
275
 
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
 
275
bool Item_field::get_date_result(type::Time &ltime,uint32_t fuzzydate)
276
276
{
277
277
  if ((null_value=result_field->is_null()) ||
278
278
      result_field->get_date(ltime,fuzzydate))
279
279
  {
280
 
    memset(ltime, 0, sizeof(*ltime));
 
280
    ltime.reset();
281
281
    return 1;
282
282
  }
283
283
  return 0;
284
284
}
285
285
 
286
 
bool Item_field::get_time(DRIZZLE_TIME *ltime)
 
286
bool Item_field::get_time(type::Time &ltime)
287
287
{
288
288
  if ((null_value=field->is_null()) || field->get_time(ltime))
289
289
  {
290
 
    memset(ltime, 0, sizeof(*ltime));
 
290
    ltime.reset();
291
291
    return 1;
292
292
  }
293
293
  return 0;
308
308
}
309
309
 
310
310
 
311
 
my_decimal *Item_field::val_decimal_result(my_decimal *decimal_value)
 
311
type::Decimal *Item_field::val_decimal_result(type::Decimal *decimal_value)
312
312
{
313
313
  if ((null_value= result_field->is_null()))
314
314
    return 0;
319
319
bool Item_field::val_bool_result()
320
320
{
321
321
  if ((null_value= result_field->is_null()))
 
322
  {
322
323
    return false;
 
324
  }
 
325
 
323
326
  switch (result_field->result_type()) {
324
327
  case INT_RESULT:
325
328
    return result_field->val_int() != 0;
 
329
 
326
330
  case DECIMAL_RESULT:
327
 
  {
328
 
    my_decimal decimal_value;
329
 
    my_decimal *val= result_field->val_decimal(&decimal_value);
330
 
    if (val)
331
 
      return !my_decimal_is_zero(val);
332
 
    return 0;
333
 
  }
 
331
    {
 
332
      type::Decimal decimal_value;
 
333
      type::Decimal *val= result_field->val_decimal(&decimal_value);
 
334
      if (val)
 
335
        return not val->isZero();
 
336
      return 0;
 
337
    }
 
338
 
334
339
  case REAL_RESULT:
335
340
  case STRING_RESULT:
336
341
    return result_field->val_real() != 0.0;
 
342
 
337
343
  case ROW_RESULT:
338
 
  default:
339
344
    assert(0);
340
345
    return 0;                                   // Shut up compiler
341
346
  }
 
347
 
 
348
  assert(0);
 
349
  return 0;                                   // Shut up compiler
342
350
}
343
351
 
344
352
 
361
369
    (In cases where we would choose wrong we would have to generate a
362
370
    ER_NON_UNIQ_ERROR).
363
371
  */
364
 
  return (!my_strcasecmp(system_charset_info, item_field->name,
365
 
                         field_name) &&
366
 
          (!item_field->table_name || !table_name ||
367
 
           (!my_strcasecmp(table_alias_charset, item_field->table_name,
368
 
                           table_name) &&
369
 
            (!item_field->db_name || !db_name ||
370
 
             (item_field->db_name && !strcasecmp(item_field->db_name,
371
 
                                             db_name))))));
 
372
  return (not my_strcasecmp(system_charset_info, item_field->name, field_name) &&
 
373
          (not item_field->table_name || not table_name ||
 
374
           (not my_strcasecmp(table_alias_charset, item_field->table_name, table_name) &&
 
375
            (not item_field->db_name || not db_name ||
 
376
             (item_field->db_name && not my_strcasecmp(system_charset_info, item_field->db_name, db_name))))));
372
377
}
373
378
 
374
379
 
375
380
table_map Item_field::used_tables() const
376
381
{
377
382
  if (field->getTable()->const_table)
 
383
  {
378
384
    return 0;                                   // const item
 
385
  }
 
386
 
379
387
  return (depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map);
380
388
}
381
389
 
488
496
  */
489
497
  Name_resolution_context *last_checked_context= context;
490
498
  Item **ref= (Item **) not_found_item;
491
 
  Select_Lex *current_sel= (Select_Lex *) session->lex->current_select;
 
499
  Select_Lex *current_sel= (Select_Lex *) session->getLex()->current_select;
492
500
  Name_resolution_context *outer_context= 0;
493
501
  Select_Lex *select= 0;
494
502
  /* Currently derived tables cannot be correlated */
533
541
        if (*from_field != view_ref_found)
534
542
        {
535
543
          prev_subselect_item->used_tables_cache|= (*from_field)->getTable()->map;
536
 
          prev_subselect_item->const_item_cache= 0;
 
544
          prev_subselect_item->const_item_cache= false;
537
545
          set_field(*from_field);
538
546
          if (!last_checked_context->select_lex->having_fix_field &&
539
547
              select->group_list.elements &&
554
562
              return -1;
555
563
            session->change_item_tree(reference, rf);
556
564
            select->inner_refs_list.push_back(rf);
557
 
            rf->in_sum_func= session->lex->in_sum_func;
 
565
            rf->in_sum_func= session->getLex()->in_sum_func;
558
566
          }
559
567
          /*
560
568
            A reference is resolved to a nest level that's outer or the same as
561
569
            the nest level of the enclosing set function : adjust the value of
562
570
            max_arg_level for the function if it's needed.
563
571
          */
564
 
          if (session->lex->in_sum_func &&
565
 
              session->lex->in_sum_func->nest_level >= select->nest_level)
 
572
          if (session->getLex()->in_sum_func &&
 
573
              session->getLex()->in_sum_func->nest_level >= select->nest_level)
566
574
          {
567
575
            Item::Type ref_type= (*reference)->type();
568
 
            set_if_bigger(session->lex->in_sum_func->max_arg_level,
 
576
            set_if_bigger(session->getLex()->in_sum_func->max_arg_level,
569
577
                          select->nest_level);
570
578
            set_field(*from_field);
571
579
            fixed= 1;
621
629
      case it does not matter which used tables bits we set)
622
630
    */
623
631
    prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
624
 
    prev_subselect_item->const_item_cache= 0;
 
632
    prev_subselect_item->const_item_cache= false;
625
633
  }
626
634
 
627
635
  assert(ref != 0);
632
640
    if (upward_lookup)
633
641
    {
634
642
      // We can't say exactly what absent table or field
635
 
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where);
 
643
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where());
636
644
    }
637
645
    else
638
646
    {
674
682
    if (place != IN_HAVING && select->group_list.elements)
675
683
    {
676
684
      outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
677
 
      ((Item_outer_ref*)rf)->in_sum_func= session->lex->in_sum_func;
 
685
      ((Item_outer_ref*)rf)->in_sum_func= session->getLex()->in_sum_func;
678
686
    }
679
687
    session->change_item_tree(reference, rf);
680
688
    /*
780
788
                                          context->first_name_resolution_table,
781
789
                                          context->last_name_resolution_table,
782
790
                                          reference,
783
 
                                          session->lex->use_only_table_context ?
 
791
                                          session->getLex()->use_only_table_context ?
784
792
                                            REPORT_ALL_ERRORS :
785
793
                                            IGNORE_EXCEPT_NON_UNIQUE, true)) ==
786
794
        not_found_field)
787
795
    {
788
796
      int ret;
789
797
      /* Look up in current select's item_list to find aliased fields */
790
 
      if (session->lex->current_select->is_item_list_lookup)
 
798
      if (session->getLex()->current_select->is_item_list_lookup)
791
799
      {
792
800
        uint32_t counter;
793
801
        enum_resolution_type resolution;
794
802
        Item** res= find_item_in_list(session,
795
 
                                      this, session->lex->current_select->item_list,
 
803
                                      this, session->getLex()->current_select->item_list,
796
804
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
797
805
                                      &resolution);
798
806
        if (!res)
816
824
            {
817
825
              /* The column to which we link isn't valid. */
818
826
              my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->name,
819
 
                       current_session->where);
 
827
                       session->where());
820
828
              return(1);
821
829
            }
822
830
 
880
888
      return false;
881
889
 
882
890
    set_field(from_field);
883
 
    if (session->lex->in_sum_func &&
884
 
        session->lex->in_sum_func->nest_level ==
885
 
        session->lex->current_select->nest_level)
 
891
    if (session->getLex()->in_sum_func &&
 
892
        session->getLex()->in_sum_func->nest_level ==
 
893
        session->getLex()->current_select->nest_level)
886
894
    {
887
 
      set_if_bigger(session->lex->in_sum_func->max_arg_level,
888
 
                    session->lex->current_select->nest_level);
 
895
      set_if_bigger(session->getLex()->in_sum_func->max_arg_level,
 
896
                    session->getLex()->current_select->nest_level);
889
897
    }
890
898
  }
891
899
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
902
910
      current_bitmap= table->write_set;
903
911
      other_bitmap=   table->read_set;
904
912
    }
905
 
    //if (! current_bitmap->testAndSet(field->field_index))
906
 
    if (! current_bitmap->test(field->field_index))
 
913
    //if (! current_bitmap->testAndSet(field->position()))
 
914
    if (! current_bitmap->test(field->position()))
907
915
    {
908
 
      if (! other_bitmap->test(field->field_index))
 
916
      if (! other_bitmap->test(field->position()))
909
917
      {
910
918
        /* First usage of column */
911
919
        table->used_fields++;                     // Used to optimize loops
972
980
  Item_equal *item= 0;
973
981
  while (cond_equal)
974
982
  {
975
 
    List_iterator_fast<Item_equal> li(cond_equal->current_level);
 
983
    List<Item_equal>::iterator li(cond_equal->current_level.begin());
976
984
    while ((item= li++))
977
985
    {
978
986
      if (item->contains(field))