~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_strfunc.cc

  • Committer: Brian Aker
  • Date: 2008-07-10 19:37:55 UTC
  • mfrom: (51.1.67 remove-dbug)
  • Revision ID: brian@tangent.org-20080710193755-f5g761uieqa3wxmt
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
my_decimal *Item_str_func::val_decimal(my_decimal *decimal_value)
63
63
{
64
 
  DBUG_ASSERT(fixed == 1);
 
64
  assert(fixed == 1);
65
65
  char buff[64];
66
66
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
67
67
  res= val_str(&tmp);
75
75
 
76
76
double Item_str_func::val_real()
77
77
{
78
 
  DBUG_ASSERT(fixed == 1);
 
78
  assert(fixed == 1);
79
79
  int err_not_used;
80
80
  char *end_not_used, buff[64];
81
81
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
87
87
 
88
88
longlong Item_str_func::val_int()
89
89
{
90
 
  DBUG_ASSERT(fixed == 1);
 
90
  assert(fixed == 1);
91
91
  int err;
92
92
  char buff[22];
93
93
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
101
101
 
102
102
String *Item_func_md5::val_str(String *str)
103
103
{
104
 
  DBUG_ASSERT(fixed == 1);
 
104
  assert(fixed == 1);
105
105
  String * sptr= args[0]->val_str(str);
106
106
  str->set_charset(&my_charset_bin);
107
107
  if (sptr)
153
153
 
154
154
String *Item_func_concat::val_str(String *str)
155
155
{
156
 
  DBUG_ASSERT(fixed == 1);
 
156
  assert(fixed == 1);
157
157
  String *res,*res2,*use_as_buff;
158
158
  uint i;
159
159
  bool is_const= 0;
311
311
 
312
312
String *Item_func_concat_ws::val_str(String *str)
313
313
{
314
 
  DBUG_ASSERT(fixed == 1);
 
314
  assert(fixed == 1);
315
315
  char tmp_str_buff[10];
316
316
  String tmp_sep_str(tmp_str_buff, sizeof(tmp_str_buff),default_charset_info),
317
317
         *sep_str, *res, *res2,*use_as_buff;
474
474
 
475
475
String *Item_func_reverse::val_str(String *str)
476
476
{
477
 
  DBUG_ASSERT(fixed == 1);
 
477
  assert(fixed == 1);
478
478
  String *res = args[0]->val_str(str);
479
479
  char *ptr, *end, *tmp;
480
480
 
537
537
 
538
538
String *Item_func_replace::val_str(String *str)
539
539
{
540
 
  DBUG_ASSERT(fixed == 1);
 
540
  assert(fixed == 1);
541
541
  String *res,*res2,*res3;
542
542
  int offset;
543
543
  uint from_length,to_length;
673
673
 
674
674
String *Item_func_insert::val_str(String *str)
675
675
{
676
 
  DBUG_ASSERT(fixed == 1);
 
676
  assert(fixed == 1);
677
677
  String *res,*res2;
678
678
  longlong start, length;  /* must be longlong to avoid truncation */
679
679
 
740
740
 
741
741
String *Item_str_conv::val_str(String *str)
742
742
{
743
 
  DBUG_ASSERT(fixed == 1);
 
743
  assert(fixed == 1);
744
744
  String *res;
745
745
  if (!(res=args[0]->val_str(str)))
746
746
  {
754
754
    res= copy_if_not_alloced(str,res,res->length());
755
755
    len= converter(collation.collation, (char*) res->ptr(), res->length(),
756
756
                                        (char*) res->ptr(), res->length());
757
 
    DBUG_ASSERT(len <= res->length());
 
757
    assert(len <= res->length());
758
758
    res->length(len);
759
759
  }
760
760
  else
790
790
 
791
791
String *Item_func_left::val_str(String *str)
792
792
{
793
 
  DBUG_ASSERT(fixed == 1);
 
793
  assert(fixed == 1);
794
794
  String *res= args[0]->val_str(str);
795
795
 
796
796
  /* must be longlong to avoid truncation */
836
836
 
837
837
String *Item_func_right::val_str(String *str)
838
838
{
839
 
  DBUG_ASSERT(fixed == 1);
 
839
  assert(fixed == 1);
840
840
  String *res= args[0]->val_str(str);
841
841
  /* must be longlong to avoid truncation */
842
842
  longlong length= args[1]->val_int();
869
869
 
870
870
String *Item_func_substr::val_str(String *str)
871
871
{
872
 
  DBUG_ASSERT(fixed == 1);
 
872
  assert(fixed == 1);
873
873
  String *res  = args[0]->val_str(str);
874
874
  /* must be longlong to avoid truncation */
875
875
  longlong start= args[1]->val_int();
950
950
 
951
951
String *Item_func_substr_index::val_str(String *str)
952
952
{
953
 
  DBUG_ASSERT(fixed == 1);
 
953
  assert(fixed == 1);
954
954
  String *res= args[0]->val_str(str);
955
955
  String *delimiter= args[1]->val_str(&tmp_value);
956
956
  int32 count= (int32) args[2]->val_int();
1080
1080
 
1081
1081
String *Item_func_ltrim::val_str(String *str)
1082
1082
{
1083
 
  DBUG_ASSERT(fixed == 1);
 
1083
  assert(fixed == 1);
1084
1084
  char buff[MAX_FIELD_WIDTH], *ptr, *end;
1085
1085
  String tmp(buff,sizeof(buff),system_charset_info);
1086
1086
  String *res, *remove_str;
1126
1126
 
1127
1127
String *Item_func_rtrim::val_str(String *str)
1128
1128
{
1129
 
  DBUG_ASSERT(fixed == 1);
 
1129
  assert(fixed == 1);
1130
1130
  char buff[MAX_FIELD_WIDTH], *ptr, *end;
1131
1131
  String tmp(buff, sizeof(buff), system_charset_info);
1132
1132
  String *res, *remove_str;
1206
1206
 
1207
1207
String *Item_func_trim::val_str(String *str)
1208
1208
{
1209
 
  DBUG_ASSERT(fixed == 1);
 
1209
  assert(fixed == 1);
1210
1210
  char buff[MAX_FIELD_WIDTH], *ptr, *end;
1211
1211
  const char *r_ptr;
1212
1212
  String tmp(buff, sizeof(buff), system_charset_info);
1305
1305
 
1306
1306
String *Item_func_password::val_str(String *str)
1307
1307
{
1308
 
  DBUG_ASSERT(fixed == 1);
 
1308
  assert(fixed == 1);
1309
1309
  String *res= args[0]->val_str(str); 
1310
1310
  if ((null_value=args[0]->null_value))
1311
1311
    return 0;
1328
1328
 
1329
1329
String *Item_func_encrypt::val_str(String *str)
1330
1330
{
1331
 
  DBUG_ASSERT(fixed == 1);
 
1331
  assert(fixed == 1);
1332
1332
  String *res  =args[0]->val_str(str);
1333
1333
 
1334
1334
#ifdef HAVE_CRYPT
1384
1384
  char pw_buff[80];
1385
1385
  String tmp_pw_value(pw_buff, sizeof(pw_buff), system_charset_info);
1386
1386
  String *password;
1387
 
  DBUG_ASSERT(fixed == 1);
 
1387
  assert(fixed == 1);
1388
1388
 
1389
1389
  if (!(res=args[0]->val_str(str)))
1390
1390
  {
1413
1413
  char pw_buff[80];
1414
1414
  String tmp_pw_value(pw_buff, sizeof(pw_buff), system_charset_info);
1415
1415
  String *password;
1416
 
  DBUG_ASSERT(fixed == 1);
 
1416
  assert(fixed == 1);
1417
1417
 
1418
1418
  if (!(res=args[0]->val_str(str)))
1419
1419
  {
1458
1458
 
1459
1459
String *Item_func_database::val_str(String *str)
1460
1460
{
1461
 
  DBUG_ASSERT(fixed == 1);
 
1461
  assert(fixed == 1);
1462
1462
  THD *thd= current_thd;
1463
1463
  if (thd->db == NULL)
1464
1464
  {
1477
1477
*/
1478
1478
bool Item_func_user::init(const char *user, const char *host)
1479
1479
{
1480
 
  DBUG_ASSERT(fixed == 1);
 
1480
  assert(fixed == 1);
1481
1481
 
1482
1482
  // For system threads (e.g. replication SQL thread) user may be empty
1483
1483
  if (user)
1488
1488
    if (str_value.alloc(res_length))
1489
1489
    {
1490
1490
      null_value=1;
1491
 
      return TRUE;
 
1491
      return true;
1492
1492
    }
1493
1493
 
1494
1494
    res_length=cs->cset->snprintf(cs, (char*)str_value.ptr(), res_length,
1496
1496
    str_value.length(res_length);
1497
1497
    str_value.mark_as_const();
1498
1498
  }
1499
 
  return FALSE;
 
1499
  return false;
1500
1500
}
1501
1501
 
1502
1502
 
1511
1511
bool Item_func_current_user::fix_fields(THD *thd, Item **ref)
1512
1512
{
1513
1513
  if (Item_func_sysconst::fix_fields(thd, ref))
1514
 
    return TRUE;
 
1514
    return true;
1515
1515
 
1516
1516
  Security_context *ctx=
1517
1517
                         thd->security_ctx;
1556
1556
  /* Number of characters used to represent the decimals, including '.' */
1557
1557
  uint32 dec_length;
1558
1558
  int diff;
1559
 
  DBUG_ASSERT(fixed == 1);
 
1559
  assert(fixed == 1);
1560
1560
 
1561
1561
  dec= (int) args[1]->val_int();
1562
1562
  if (args[1]->null_value)
1587
1587
    double nr= args[0]->val_real();
1588
1588
    if ((null_value=args[0]->null_value))
1589
1589
      return 0; /* purecov: inspected */
1590
 
    nr= my_double_round(nr, (longlong) dec, FALSE, FALSE);
 
1590
    nr= my_double_round(nr, (longlong) dec, false, false);
1591
1591
    /* Here default_charset() is right as this is not an automatic conversion */
1592
1592
    str->set_real(nr, dec, default_charset());
1593
1593
    if (isnan(nr))
1651
1651
 
1652
1652
double Item_func_elt::val_real()
1653
1653
{
1654
 
  DBUG_ASSERT(fixed == 1);
 
1654
  assert(fixed == 1);
1655
1655
  uint tmp;
1656
1656
  null_value=1;
1657
1657
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
1664
1664
 
1665
1665
longlong Item_func_elt::val_int()
1666
1666
{
1667
 
  DBUG_ASSERT(fixed == 1);
 
1667
  assert(fixed == 1);
1668
1668
  uint tmp;
1669
1669
  null_value=1;
1670
1670
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
1678
1678
 
1679
1679
String *Item_func_elt::val_str(String *str)
1680
1680
{
1681
 
  DBUG_ASSERT(fixed == 1);
 
1681
  assert(fixed == 1);
1682
1682
  uint tmp;
1683
1683
  null_value=1;
1684
1684
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
1695
1695
void Item_func_make_set::split_sum_func(THD *thd, Item **ref_pointer_array,
1696
1696
                                        List<Item> &fields)
1697
1697
{
1698
 
  item->split_sum_func2(thd, ref_pointer_array, fields, &item, TRUE);
 
1698
  item->split_sum_func2(thd, ref_pointer_array, fields, &item, true);
1699
1699
  Item_str_func::split_sum_func(thd, ref_pointer_array, fields);
1700
1700
}
1701
1701
 
1728
1728
 
1729
1729
String *Item_func_make_set::val_str(String *str)
1730
1730
{
1731
 
  DBUG_ASSERT(fixed == 1);
 
1731
  assert(fixed == 1);
1732
1732
  ulonglong bits;
1733
1733
  bool first_found=0;
1734
1734
  Item **ptr=args;
1812
1812
 
1813
1813
String *Item_func_char::val_str(String *str)
1814
1814
{
1815
 
  DBUG_ASSERT(fixed == 1);
 
1815
  assert(fixed == 1);
1816
1816
  str->length(0);
1817
1817
  str->set_charset(collation.collation);
1818
1818
  for (uint i=0 ; i < arg_count ; i++)
1895
1895
 
1896
1896
String *Item_func_repeat::val_str(String *str)
1897
1897
{
1898
 
  DBUG_ASSERT(fixed == 1);
 
1898
  assert(fixed == 1);
1899
1899
  uint length,tot_length;
1900
1900
  char *to;
1901
1901
  /* must be longlong to avoid truncation */
1981
1981
 
1982
1982
String *Item_func_rpad::val_str(String *str)
1983
1983
{
1984
 
  DBUG_ASSERT(fixed == 1);
 
1984
  assert(fixed == 1);
1985
1985
  uint32 res_byte_length,res_char_length,pad_char_length,pad_byte_length;
1986
1986
  char *to;
1987
1987
  const char *ptr_pad;
2084
2084
 
2085
2085
String *Item_func_lpad::val_str(String *str)
2086
2086
{
2087
 
  DBUG_ASSERT(fixed == 1);
 
2087
  assert(fixed == 1);
2088
2088
  uint32 res_char_length,pad_char_length;
2089
2089
  /* must be longlong to avoid truncation */
2090
2090
  longlong count= args[1]->val_int();
2148
2148
 
2149
2149
String *Item_func_conv::val_str(String *str)
2150
2150
{
2151
 
  DBUG_ASSERT(fixed == 1);
 
2151
  assert(fixed == 1);
2152
2152
  String *res= args[0]->val_str(str);
2153
2153
  char *endptr,ans[65],*ptr;
2154
2154
  longlong dec;
2182
2182
 
2183
2183
String *Item_func_conv_charset::val_str(String *str)
2184
2184
{
2185
 
  DBUG_ASSERT(fixed == 1);
 
2185
  assert(fixed == 1);
2186
2186
  if (use_cached_value)
2187
2187
    return null_value ? 0 : &str_value;
2188
2188
  String *arg= args[0]->val_str(str);
2214
2214
 
2215
2215
String *Item_func_set_collation::val_str(String *str)
2216
2216
{
2217
 
  DBUG_ASSERT(fixed == 1);
 
2217
  assert(fixed == 1);
2218
2218
  str=args[0]->val_str(str);
2219
2219
  if ((null_value=args[0]->null_value))
2220
2220
    return 0;
2279
2279
  str->append('(');
2280
2280
  args[0]->print(str, query_type);
2281
2281
  str->append(STRING_WITH_LEN(" collate "));
2282
 
  DBUG_ASSERT(args[1]->basic_const_item() &&
 
2282
  assert(args[1]->basic_const_item() &&
2283
2283
              args[1]->type() == Item::STRING_ITEM);
2284
2284
  args[1]->str_value.print(str);
2285
2285
  str->append(')');
2287
2287
 
2288
2288
String *Item_func_charset::val_str(String *str)
2289
2289
{
2290
 
  DBUG_ASSERT(fixed == 1);
 
2290
  assert(fixed == 1);
2291
2291
  uint dummy_errors;
2292
2292
 
2293
2293
  CHARSET_INFO *cs= args[0]->collation.collation; 
2299
2299
 
2300
2300
String *Item_func_collation::val_str(String *str)
2301
2301
{
2302
 
  DBUG_ASSERT(fixed == 1);
 
2302
  assert(fixed == 1);
2303
2303
  uint dummy_errors;
2304
2304
  CHARSET_INFO *cs= args[0]->collation.collation; 
2305
2305
 
2326
2326
  String *res;
2327
2327
  CHARSET_INFO *cs= args[0]->collation.collation;
2328
2328
  uint tmp_length, frm_length;
2329
 
  DBUG_ASSERT(fixed == 1);
 
2329
  assert(fixed == 1);
2330
2330
 
2331
2331
  if (args[0]->result_type() != STRING_RESULT ||
2332
2332
      !(res= args[0]->val_str(str)))
2356
2356
String *Item_func_hex::val_str(String *str)
2357
2357
{
2358
2358
  String *res;
2359
 
  DBUG_ASSERT(fixed == 1);
 
2359
  assert(fixed == 1);
2360
2360
  if (args[0]->result_type() != STRING_RESULT)
2361
2361
  {
2362
2362
    ulonglong dec;
2405
2405
  char *to;
2406
2406
  String *res;
2407
2407
  uint length;
2408
 
  DBUG_ASSERT(fixed == 1);
 
2408
  assert(fixed == 1);
2409
2409
 
2410
2410
  res= args[0]->val_str(str);
2411
2411
  if (!res || tmp_value.alloc(length= (1+res->length())/2))
2451
2451
 
2452
2452
String *Item_load_file::val_str(String *str)
2453
2453
{
2454
 
  DBUG_ASSERT(fixed == 1);
 
2454
  assert(fixed == 1);
2455
2455
  String *file_name;
2456
2456
  File file;
2457
2457
  struct stat stat_info;
2458
2458
  char path[FN_REFLEN];
2459
 
  DBUG_ENTER("load_file");
2460
2459
 
2461
2460
  if (!(file_name= args[0]->val_str(str)))
2462
2461
    goto err;
2497
2496
  tmp_value.length(stat_info.st_size);
2498
2497
  my_close(file, MYF(0));
2499
2498
  null_value = 0;
2500
 
  DBUG_RETURN(&tmp_value);
 
2499
  return(&tmp_value);
2501
2500
 
2502
2501
err:
2503
2502
  null_value = 1;
2504
 
  DBUG_RETURN(0);
 
2503
  return(0);
2505
2504
}
2506
2505
 
2507
2506
 
2508
2507
String* Item_func_export_set::val_str(String* str)
2509
2508
{
2510
 
  DBUG_ASSERT(fixed == 1);
 
2509
  assert(fixed == 1);
2511
2510
  ulonglong the_set = (ulonglong) args[0]->val_int();
2512
2511
  String yes_buf, *yes;
2513
2512
  yes = args[1]->val_str(&yes_buf);
2557
2556
    }
2558
2557
    break;
2559
2558
  default:
2560
 
    DBUG_ASSERT(0); // cannot happen
 
2559
    assert(0); // cannot happen
2561
2560
  }
2562
2561
  null_value=0;
2563
2562
 
2608
2607
 
2609
2608
String *Item_func_quote::val_str(String *str)
2610
2609
{
2611
 
  DBUG_ASSERT(fixed == 1);
 
2610
  assert(fixed == 1);
2612
2611
  /*
2613
2612
    Bit mask that has 1 for set for the position of the following characters:
2614
2613
    0, \, ' and ^Z
2685
2684
 
2686
2685
longlong Item_func_uncompressed_length::val_int()
2687
2686
{
2688
 
  DBUG_ASSERT(fixed == 1);
 
2687
  assert(fixed == 1);
2689
2688
  String *res= args[0]->val_str(&value);
2690
2689
  if (!res)
2691
2690
  {
2707
2706
 
2708
2707
longlong Item_func_crc32::val_int()
2709
2708
{
2710
 
  DBUG_ASSERT(fixed == 1);
 
2709
  assert(fixed == 1);
2711
2710
  String *res=args[0]->val_str(&value);
2712
2711
  if (!res)
2713
2712
  {
2728
2727
  String *res;
2729
2728
  Byte *body;
2730
2729
  char *tmp, *last_char;
2731
 
  DBUG_ASSERT(fixed == 1);
 
2730
  assert(fixed == 1);
2732
2731
 
2733
2732
  if (!(res= args[0]->val_str(str)))
2734
2733
  {
2787
2786
 
2788
2787
String *Item_func_uncompress::val_str(String *str)
2789
2788
{
2790
 
  DBUG_ASSERT(fixed == 1);
 
2789
  assert(fixed == 1);
2791
2790
  String *res= args[0]->val_str(str);
2792
2791
  ulong new_size;
2793
2792
  int err;
2879
2878
 
2880
2879
String *Item_func_uuid::val_str(String *str)
2881
2880
{
2882
 
  DBUG_ASSERT(fixed == 1);
 
2881
  assert(fixed == 1);
2883
2882
  char *s;
2884
2883
  THD *thd= current_thd;
2885
2884
 
2930
2929
      tv-=nanoseq;
2931
2930
      nanoseq=0;
2932
2931
    }
2933
 
    DBUG_ASSERT(tv > uuid_time);
 
2932
    assert(tv > uuid_time);
2934
2933
  }
2935
2934
  uuid_time=tv;
2936
2935
  pthread_mutex_unlock(&LOCK_uuid_generator);