~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

  • Committer: Mark Atwood
  • Date: 2011-12-20 02:32:53 UTC
  • mfrom: (2469.1.1 drizzle-build)
  • Revision ID: me@mark.atwood.name-20111220023253-bvu0kr14kwsdvz7g
mergeĀ lp:~brianaker/drizzle/deprecate-pbms

Show diffs side-by-side

added added

removed removed

Lines of Context:
399
399
  return false;
400
400
}
401
401
 
402
 
void Item::set_name(const char *str, uint32_t length, const charset_info_st * const cs)
 
402
void Item::set_name(const char *str, uint32_t length, const charset_info_st* cs)
403
403
{
404
 
  if (!length)
 
404
  if (not length)
405
405
  {
 
406
    if (0) // str && *str)
 
407
      std::cerr << "non-empty empty name: " << str << std::endl;
406
408
    /* Empty string, used by AS or internal function like last_insert_id() */
407
 
    name= str;
 
409
    name= str; // should be NULL (or "");
408
410
    name_length= 0;
409
411
    return;
410
412
  }
411
413
  if (cs->ctype)
412
414
  {
413
415
    uint32_t orig_len= length;
414
 
    while (length && ! my_isgraph(cs, *str))
 
416
    while (length && not cs->isgraph(*str))
415
417
    {
416
418
      /* Fix problem with yacc */
417
419
      length--;
418
420
      str++;
419
421
    }
420
 
    if (orig_len != length && ! is_autogenerated_name)
 
422
    if (orig_len != length && not is_autogenerated_name)
421
423
    {
422
424
      if (length == 0)
423
425
        push_warning_printf(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY), str + length - orig_len);
438
440
  return type() == item->type() && 
439
441
         name && 
440
442
         item->name &&
441
 
         ! my_strcasecmp(system_charset_info, name, item->name);
 
443
         not system_charset_info->strcasecmp(name, item->name);
442
444
}
443
445
 
444
 
Item *Item::safe_charset_converter(const charset_info_st * const tocs)
 
446
Item *Item::safe_charset_converter(const charset_info_st* tocs)
445
447
{
446
448
  Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1);
447
 
  return conv->safe ? conv : NULL;
 
449
  return conv->safe ? conv : NULL; // memory leak? (conv if not conv->safe)
448
450
}
449
451
 
450
452
bool Item::get_date(type::Time &ltime,uint32_t fuzzydate)
458
460
    else if (result_type() == STRING_RESULT)
459
461
    {
460
462
      char buff[type::Time::MAX_STRING_LENGTH];
461
 
      String tmp(buff,sizeof(buff), &my_charset_bin),*res;
462
 
      if (!(res=val_str(&tmp)) ||
463
 
          str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
464
 
                                    &ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
 
463
      String tmp(buff,sizeof(buff), &my_charset_bin);
 
464
      String *res= val_str(&tmp);
 
465
      if (not res || str_to_datetime_with_warn(getSession(), *res, ltime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
465
466
      {
466
467
        break;
467
468
      }
475
476
 
476
477
      if (not type::is_valid(date_value))
477
478
      {
478
 
        char buff[DECIMAL_LONGLONG_DIGITS], *end;
479
 
        end= internal::int64_t10_to_str(value, buff, -10);
480
 
        make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
481
 
                                     buff, (int) (end-buff), type::DRIZZLE_TIMESTAMP_NONE, NULL);
 
479
        char buff[DECIMAL_LONGLONG_DIGITS];
 
480
        char* end= internal::int64_t10_to_str(value, buff, -10);
 
481
        make_truncated_value_warning(getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN, str_ref(buff, (int) (end-buff)), type::DRIZZLE_TIMESTAMP_NONE, NULL);
482
482
        break;
483
483
      }
484
484
    }
494
494
bool Item::get_time(type::Time &ltime)
495
495
{
496
496
  char buff[type::Time::MAX_STRING_LENGTH];
497
 
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
498
 
  if (!(res=val_str(&tmp)) or
499
 
      str_to_time_with_warn(&getSession(), res->ptr(), res->length(), &ltime))
 
497
  String tmp(buff,sizeof(buff),&my_charset_bin);
 
498
  String *res= val_str(&tmp);
 
499
  if (not res || str_to_time_with_warn(getSession(), *res, ltime))
500
500
  {
501
501
    ltime.reset();
502
 
 
503
502
    return true;
504
503
  }
505
504
 
583
582
  return (this->*processor)(arg);
584
583
}
585
584
 
586
 
Item* Item::compile(Item_analyzer analyzer, 
587
 
                    unsigned char **arg_p,
588
 
                    Item_transformer transformer, 
589
 
                    unsigned char *arg_t)
 
585
Item* Item::compile(Item_analyzer analyzer, unsigned char **arg_p, Item_transformer transformer, unsigned char *arg_t)
590
586
{
591
 
  if ((this->*analyzer) (arg_p))
592
 
    return ((this->*transformer) (arg_t));
593
 
  return NULL;
 
587
  return (this->*analyzer)(arg_p)
 
588
    ? (this->*transformer)(arg_t)
 
589
    : NULL;
594
590
}
595
591
 
596
592
void Item::traverse_cond(Cond_traverser traverser, void *arg, traverse_order)
876
872
  {
877
873
    /* Convert database to lower case for comparison */
878
874
    strncpy(name_buff, db_name, sizeof(name_buff)-1);
879
 
    my_casedn_str(files_charset_info, name_buff);
 
875
    files_charset_info->casedn_str(name_buff);
880
876
    db_name= name_buff;
881
877
  }
882
878
 
891
887
 
892
888
      assert(cur_field->field_name != 0);
893
889
 
894
 
      if (! my_strcasecmp(system_charset_info, cur_field->field_name, field_name))
895
 
        ++cur_match_degree;
896
 
      else
 
890
      if (system_charset_info->strcasecmp(cur_field->field_name, field_name))
897
891
        continue;
 
892
      ++cur_match_degree;
898
893
 
899
894
      if (cur_field->table_name && table_name)
900
895
      {
901
896
        /* If field_name is qualified by a table name. */
902
 
        if (my_strcasecmp(table_alias_charset, cur_field->table_name, table_name))
 
897
        if (table_alias_charset->strcasecmp(cur_field->table_name, table_name))
903
898
          /* Same field names, different tables. */
904
899
          return NULL;
905
900
 
907
902
        if (cur_field->db_name && db_name)
908
903
        {
909
904
          /* If field_name is also qualified by a database name. */
910
 
          if (my_strcasecmp(system_charset_info, cur_field->db_name, db_name))
 
905
          if (system_charset_info->strcasecmp(cur_field->db_name, db_name))
911
906
          {
912
907
            /* Same field names, different databases. */
913
908
            return NULL;
1011
1006
  tmp_field->table_name= "";
1012
1007
  tmp_field->col_name= name;
1013
1008
  tmp_field->charsetnr= collation.collation->number;
1014
 
  tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) | (my_binary_compare(collation.collation) ? BINARY_FLAG : 0);
 
1009
  tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) | (collation.collation->binary_compare() ? BINARY_FLAG : 0);
1015
1010
  tmp_field->type= field_type_arg;
1016
1011
  tmp_field->length= max_length;
1017
1012
  tmp_field->decimals= decimals;
1058
1053
  /* Check whether we got a well-formed string */
1059
1054
  const charset_info_st * const cs= str->charset();
1060
1055
  int well_formed_error;
1061
 
  uint32_t wlen= cs->cset->well_formed_len(cs,
1062
 
                                       str->ptr(), str->ptr() + str->length(),
1063
 
                                       str->length(), &well_formed_error);
 
1056
  uint32_t wlen= cs->cset->well_formed_len(*cs, *str, str->length(), &well_formed_error);
1064
1057
  if (wlen < str->length())
1065
1058
  {
1066
1059
    char hexbuf[7];
1575
1568
    */
1576
1569
    if (item->unsigned_flag)
1577
1570
    {
1578
 
      new_field= new field::Size(item->max_length, maybe_null,
1579
 
                                  item->name, item->unsigned_flag);
 
1571
      new_field= new field::Size(item->max_length, maybe_null, item->name, item->unsigned_flag);
1580
1572
    }
1581
 
    else if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1))
 
1573
    else if (item->max_length >= MY_INT32_NUM_DECIMAL_DIGITS - 1)
1582
1574
    {
1583
 
      new_field= new field::Int64(item->max_length, maybe_null,
1584
 
                                  item->name, item->unsigned_flag);
 
1575
      new_field= new field::Int64(item->max_length, maybe_null, item->name, item->unsigned_flag);
1585
1576
    }
1586
1577
    else
1587
1578
    {
1588
 
      new_field= new field::Int32(item->max_length, maybe_null,
1589
 
                                  item->name, item->unsigned_flag);
 
1579
      new_field= new field::Int32(item->max_length, maybe_null, item->name, item->unsigned_flag);
1590
1580
    }
1591
1581
 
1592
1582
    break;