~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include <boost/dynamic_bitset.hpp>
36
36
 
37
 
namespace drizzled
38
 
{
 
37
namespace drizzled {
39
38
 
40
39
/**
41
40
  Store the pointer to this item field into a list if not already there.
59
58
{
60
59
  List<Item_field> *item_list= (List<Item_field>*) arg;
61
60
  List<Item_field>::iterator item_list_it(item_list->begin());
62
 
  Item_field *curr_item;
63
 
  while ((curr_item= item_list_it++))
 
61
  while (Item_field* curr_item= item_list_it++)
64
62
  {
65
63
    if (curr_item->eq(this, 1))
66
 
      return(false); /* Already in the set. */
 
64
      return false; /* Already in the set. */
67
65
  }
68
66
  item_list->push_back(this);
69
 
  return(false);
 
67
  return false;
70
68
}
71
69
 
72
70
 
90
88
{
91
89
  KeyPartInfo *first_non_group_part= *((KeyPartInfo **) arg);
92
90
  KeyPartInfo *last_part= *(((KeyPartInfo **) arg) + 1);
93
 
  KeyPartInfo *cur_part;
94
91
 
95
 
  for (cur_part= first_non_group_part; cur_part != last_part; cur_part++)
 
92
  for (KeyPartInfo* cur_part= first_non_group_part; cur_part != last_part; cur_part++)
96
93
  {
97
94
    if (field->eq(cur_part->field))
98
95
      return true;
216
213
{
217
214
  set_field(f);
218
215
  /* 'name' is pointing at field->field_name of old field */
219
 
  name= (char*) f->field_name;
 
216
  name= f->field_name;
220
217
}
221
218
 
222
219
/* ARGSUSED */
325
322
    return false;
326
323
  }
327
324
 
328
 
  switch (result_field->result_type()) {
 
325
  switch (result_field->result_type()) 
 
326
  {
329
327
  case INT_RESULT:
330
328
    return result_field->val_int() != 0;
331
329
 
343
341
    return result_field->val_real() != 0.0;
344
342
 
345
343
  case ROW_RESULT:
346
 
    assert(0);
347
 
    return 0;                                   // Shut up compiler
 
344
    assert(false);
 
345
    return 0;
348
346
  }
349
347
 
350
 
  assert(0);
351
 
  return 0;                                   // Shut up compiler
 
348
  assert(false);
 
349
  return 0;
352
350
}
353
351
 
354
352
 
371
369
    (In cases where we would choose wrong we would have to generate a
372
370
    ER_NON_UNIQ_ERROR).
373
371
  */
374
 
  return (not my_strcasecmp(system_charset_info, item_field->name, field_name) &&
 
372
  return (not system_charset_info->strcasecmp(item_field->name, field_name) &&
375
373
          (not item_field->table_name || not table_name ||
376
 
           (not my_strcasecmp(table_alias_charset, item_field->table_name, table_name) &&
 
374
           (not table_alias_charset->strcasecmp(item_field->table_name, table_name) &&
377
375
            (not item_field->db_name || not db_name ||
378
 
             (item_field->db_name && not my_strcasecmp(system_charset_info, item_field->db_name, db_name))))));
 
376
             (item_field->db_name && not system_charset_info->strcasecmp(item_field->db_name, db_name))))));
379
377
}
380
378
 
381
379
 
386
384
    return 0;                                   // const item
387
385
  }
388
386
 
389
 
  return (depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map);
 
387
  return depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map;
390
388
}
391
389
 
392
390
enum Item_result Item_field::result_type () const
429
427
Item *Item_field::get_tmp_table_item(Session *session)
430
428
{
431
429
  Item_field *new_item= new Item_field(session, this);
432
 
  if (new_item)
433
 
    new_item->field= new_item->result_field;
 
430
  new_item->field= new_item->result_field;
434
431
  return new_item;
435
432
}
436
433
 
549
546
              select->group_list.elements &&
550
547
              (place == SELECT_LIST || place == IN_HAVING))
551
548
          {
552
 
            Item_outer_ref *rf;
553
549
            /*
554
550
              If an outer field is resolved in a grouping select then it
555
551
              is replaced for an Item_outer_ref object. Otherwise an
559
555
              after the original field has been fixed and this is done in the
560
556
              fix_inner_refs() function.
561
557
            */
562
 
            ;
563
 
            if (!(rf= new Item_outer_ref(context, this)))
564
 
              return -1;
 
558
            Item_outer_ref* rf= new Item_outer_ref(context, this);
565
559
            *reference= rf;
566
560
            select->inner_refs_list.push_back(rf);
567
561
            rf->in_sum_func= session->lex().in_sum_func;
590
584
        else
591
585
        {
592
586
          Item::Type ref_type= (*reference)->type();
593
 
          prev_subselect_item->used_tables_cache|=
594
 
            (*reference)->used_tables();
595
 
          prev_subselect_item->const_item_cache&=
596
 
            (*reference)->const_item();
 
587
          prev_subselect_item->used_tables_cache|= (*reference)->used_tables();
 
588
          prev_subselect_item->const_item_cache&= (*reference)->const_item();
597
589
          mark_as_dependent(session, last_checked_context->select_lex,
598
 
                            context->select_lex, this,
599
 
                            ((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
600
 
                             (Item_ident*) (*reference) :
601
 
                             0));
 
590
            context->select_lex, this, ((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ? (Item_ident*) (*reference) : 0));
602
591
          /*
603
592
            A reference to a view field had been found and we
604
593
            substituted it instead of this Item (find_field_in_tables
656
645
  }
657
646
  else if (ref != not_found_item)
658
647
  {
659
 
    Item *save;
660
 
    Item_ref *rf;
661
 
 
662
648
    /* Should have been checked in resolve_ref_in_select_and_group(). */
663
649
    assert(*ref && (*ref)->fixed);
664
650
    /*
667
653
      constructor, so no initialization is performed, and call
668
654
      fix_fields() below.
669
655
    */
670
 
    save= *ref;
 
656
    Item* save= *ref;
671
657
    *ref= NULL;                             // Don't call set_properties()
672
 
    rf= (place == IN_HAVING ?
673
 
         new Item_ref(context, ref, (char*) table_name,
674
 
                      (char*) field_name, alias_name_used) :
 
658
    Item_ref* rf= (place == IN_HAVING ?
 
659
         new Item_ref(context, ref, table_name, field_name, alias_name_used) :
675
660
         (!select->group_list.elements ?
676
 
         new Item_direct_ref(context, ref, (char*) table_name,
677
 
                             (char*) field_name, alias_name_used) :
678
 
         new Item_outer_ref(context, ref, (char*) table_name,
679
 
                            (char*) field_name, alias_name_used)));
 
661
         new Item_direct_ref(context, ref, table_name, field_name, alias_name_used) :
 
662
         new Item_outer_ref(context, ref, table_name, field_name, alias_name_used)));
680
663
    *ref= save;
681
664
    if (!rf)
682
665
      return -1;
695
678
    if (rf->fix_fields(session, reference) || rf->check_cols(1))
696
679
      return -1;
697
680
 
698
 
    mark_as_dependent(session, last_checked_context->select_lex,
699
 
                      context->select_lex, this,
700
 
                      rf);
 
681
    mark_as_dependent(session, last_checked_context->select_lex, context->select_lex, this, rf);
701
682
    return 0;
702
683
  }
703
684
  else
704
685
  {
705
 
    mark_as_dependent(session, last_checked_context->select_lex,
706
 
                      context->select_lex,
707
 
                      this, (Item_ident*)*reference);
 
686
    mark_as_dependent(session, last_checked_context->select_lex, context->select_lex, this, (Item_ident*)*reference);
708
687
    if (last_checked_context->select_lex->having_fix_field)
709
688
    {
710
 
      Item_ref *rf;
711
 
      rf= new Item_ref(context,
712
 
                       (cached_table->getSchemaName()[0] ? cached_table->getSchemaName() : 0),
713
 
                       (char*) cached_table->alias, (char*) field_name);
714
 
      if (!rf)
715
 
        return -1;
 
689
      Item_ref* rf= new Item_ref(context, (cached_table->getSchemaName()[0] ? cached_table->getSchemaName() : 0), cached_table->alias, field_name);
716
690
      *reference= rf;
717
691
      /*
718
692
        rf is Item_ref => never substitute other items (in this case)
827
801
              /* The column to which we link isn't valid. */
828
802
              my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->name,
829
803
                       session->where());
830
 
              return(1);
 
804
              return 1;
831
805
            }
832
806
 
833
807
            set_field(new_field);
841
815
              Item_field created by the parser with the new Item_ref.
842
816
            */
843
817
            Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
844
 
            if (!rf)
845
 
              return 1;
846
818
            *reference= rf;
847
819
            /*
848
820
              Because Item_ref never substitutes itself with other items
854
826
        }
855
827
      }
856
828
      if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
857
 
        goto error;
 
829
        return true;
858
830
      outer_fixed= true;
859
831
      if (!ret)
860
832
        goto mark_non_agg_field;
861
833
    }
862
834
    else if (!from_field)
863
 
      goto error;
 
835
      return true;
864
836
 
865
837
    if (!outer_fixed && cached_table && cached_table->select_lex &&
866
838
        context->select_lex &&
868
840
    {
869
841
      int ret;
870
842
      if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
871
 
        goto error;
 
843
        return true;
872
844
      outer_fixed= 1;
873
845
      if (!ret)
874
846
        goto mark_non_agg_field;
926
898
  fixed= 1;
927
899
mark_non_agg_field:
928
900
  return false;
929
 
 
930
 
error:
931
 
  context->process_error(session);
932
 
  return true;
933
901
}
934
902
 
935
 
Item *Item_field::safe_charset_converter(const CHARSET_INFO * const tocs)
 
903
Item *Item_field::safe_charset_converter(const charset_info_st * const tocs)
936
904
{
937
905
  no_const_subst= 1;
938
906
  return Item::safe_charset_converter(tocs);
949
917
   */
950
918
  field= result_field= 0;
951
919
  null_value= false;
952
 
  return;
953
920
}
954
921
 
955
922
 
979
946
 
980
947
Item_equal *Item_field::find_item_equal(COND_EQUAL *cond_equal)
981
948
{
982
 
  Item_equal *item= 0;
983
949
  while (cond_equal)
984
950
  {
985
951
    List<Item_equal>::iterator li(cond_equal->current_level.begin());
986
 
    while ((item= li++))
 
952
    while (Item_equal* item= li++)
987
953
    {
988
954
      if (item->contains(field))
989
955
        return item;
1197
1163
    res= field_conv(to,result_field);
1198
1164
    null_value=0;
1199
1165
  }
1200
 
  return(res);
 
1166
  return res;
1201
1167
}
1202
1168
 
1203
1169
 
1204
 
bool Item_field::send(plugin::Client *client, String *)
 
1170
void Item_field::send(plugin::Client *client, String *)
1205
1171
{
1206
 
  return client->store(result_field);
 
1172
  client->store(result_field);
1207
1173
}
1208
1174
 
1209
1175
 
1214
1180
    popping up.
1215
1181
  */
1216
1182
  Session *session= field->getTable()->in_use;
1217
 
  int no_errors;
1218
 
 
1219
 
  no_errors= session->no_errors;
 
1183
  int no_errors= session->no_errors;
1220
1184
  session->no_errors= 1;
1221
1185
  Item::update_null_value();
1222
1186
  session->no_errors= no_errors;
1255
1219
    List<Item> *all_fields= &select->join->all_fields;
1256
1220
    Item **ref_pointer_array= select->ref_pointer_array;
1257
1221
    int el= all_fields->size();
1258
 
    Item_ref *ref;
1259
 
 
1260
1222
    ref_pointer_array[el]= (Item*)this;
1261
1223
    all_fields->push_front((Item*)this);
1262
 
    ref= new Item_ref(&select->context, ref_pointer_array + el,
1263
 
                      table_name, field_name);
 
1224
    Item_ref* ref= new Item_ref(&select->context, ref_pointer_array + el, table_name, field_name);
1264
1225
    return ref;
1265
1226
  }
1266
1227
  return this;
1275
1236
    String tmp(buff,sizeof(buff),str->charset());
1276
1237
    field->val_str_internal(&tmp);
1277
1238
    if (field->is_null())  {
1278
 
      str->append("NULL");
 
1239
      str->append(STRING_WITH_LEN("NULL"));
1279
1240
    }
1280
1241
    else {
1281
1242
      str->append('\'');