~maria-captains/maria/mysql-6.0-backup

« back to all changes in this revision

Viewing changes to sql/item_strfunc.cc

  • Committer: Thava Alagu
  • Date: 2010-03-11 19:18:17 UTC
  • mfrom: (3719.14.62 mysql-6.0-codebase)
  • Revision ID: thavamuni.alagu@sun.com-20100311191817-5nigmq884xo9fuut
Merge from mysql-6.0-codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
String my_empty_string("",default_charset_info);
45
45
 
 
46
/*
 
47
  For the Items which have only val_str_ascii() method
 
48
  and don't have their own "native" val_str(),
 
49
  we provide a "wrapper" method to convert from ASCII
 
50
  to Item character set when it's necessary.
 
51
  Conversion happens only in case of "tricky" Item character set (e.g. UCS2).
 
52
  Normally conversion does not happen, and val_str_ascii() is immediately
 
53
  returned instead.
 
54
*/
 
55
String *Item_str_ascii_func::val_str(String *str)
 
56
{
 
57
  DBUG_ASSERT(fixed == 1);
 
58
 
 
59
  if (!(collation.collation->state & MY_CS_NONASCII))
 
60
    return val_str_ascii(str);
 
61
  
 
62
  DBUG_ASSERT(str != &ascii_buf);
 
63
  
 
64
  uint errors;
 
65
  String *res= val_str_ascii(&ascii_buf);
 
66
  if (!res)
 
67
    return 0;
 
68
  
 
69
  if ((null_value= str->copy(res->ptr(), res->length(),
 
70
                             &my_charset_latin1, collation.collation,
 
71
                             &errors)))
 
72
    return 0;
 
73
  
 
74
  return str;
 
75
}
 
76
 
 
77
 
46
78
 
47
79
/*
48
80
  Convert an array of bytes to a hexadecimal representation.
114
146
}
115
147
 
116
148
 
117
 
String *Item_func_md5::val_str(String *str)
 
149
String *Item_func_md5::val_str_ascii(String *str)
118
150
{
119
151
  DBUG_ASSERT(fixed == 1);
120
152
  String * sptr= args[0]->val_str(str);
141
173
 
142
174
void Item_func_md5::fix_length_and_dec()
143
175
{
144
 
  max_length=32;
145
176
  /*
146
177
    The MD5() function treats its parameter as being a case sensitive. Thus
147
178
    we set binary collation on it so different instances of MD5() will be
150
181
  args[0]->collation.set(
151
182
      get_charset_by_csname(args[0]->collation.collation->csname,
152
183
                            MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE);
 
184
  fix_length_and_charset(32, default_charset());
153
185
}
154
186
 
155
187
 
156
 
String *Item_func_sha::val_str(String *str)
 
188
String *Item_func_sha::val_str_ascii(String *str)
157
189
{
158
190
  DBUG_ASSERT(fixed == 1);
159
191
  String * sptr= args[0]->val_str(str);
183
215
 
184
216
void Item_func_sha::fix_length_and_dec()
185
217
{
186
 
  max_length=SHA1_HASH_SIZE*2; // size of hex representation of hash
187
218
  /*
188
219
    The SHA() function treats its parameter as being a case sensitive. Thus
189
220
    we set binary collation on it so different instances of MD5() will be
192
223
  args[0]->collation.set(
193
224
      get_charset_by_csname(args[0]->collation.collation->csname,
194
225
                            MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE);
 
226
  // size of hex representation of hash
 
227
  fix_length_and_charset(SHA1_HASH_SIZE * 2, default_charset());
195
228
}
196
229
 
197
230
String *Item_func_sha2::val_str(String *str)
554
587
{
555
588
  ulonglong max_result_length= 0;
556
589
 
557
 
  if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
 
590
  if (agg_arg_charsets_for_string_result(collation, args, arg_count))
558
591
    return;
559
592
 
560
593
  for (uint i=0 ; i < arg_count ; i++)
911
944
{
912
945
  ulonglong max_result_length;
913
946
 
914
 
  if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
 
947
  if (agg_arg_charsets_for_string_result(collation, args, arg_count))
915
948
    return;
916
949
 
917
950
  /*
982
1015
 
983
1016
void Item_func_reverse::fix_length_and_dec()
984
1017
{
985
 
  collation.set(args[0]->collation);
986
 
  max_length = args[0]->max_length;
 
1018
  agg_arg_charsets_for_string_result(collation, args, 1);
 
1019
  fix_char_length(args[0]->max_char_length());
987
1020
}
988
1021
 
989
1022
/**
1126
1159
  }
1127
1160
  max_length= (ulong) max_result_length;
1128
1161
  
1129
 
  if (agg_arg_charsets(collation, args, 3, MY_COLL_CMP_CONV, 1))
 
1162
  if (agg_arg_charsets_for_comparison(collation, args, 3))
1130
1163
    return;
1131
1164
}
1132
1165
 
1185
1218
  ulonglong max_result_length;
1186
1219
 
1187
1220
  // Handle character set for args[0] and args[3].
1188
 
  if (agg_arg_charsets(collation, &args[0], 2, MY_COLL_ALLOW_CONV, 3))
 
1221
  if (agg_arg_charsets_for_string_result(collation, args, 2, 3))
1189
1222
    return;
1190
1223
  max_result_length= ((ulonglong) args[0]->max_length+
1191
1224
                      (ulonglong) args[3]->max_length);
1233
1266
 
1234
1267
void Item_func_lcase::fix_length_and_dec()
1235
1268
{
1236
 
  collation.set(args[0]->collation);
 
1269
  agg_arg_charsets_for_string_result(collation, args, 1);
1237
1270
  multiply= collation.collation->casedn_multiply;
1238
1271
  converter= collation.collation->cset->casedn;
1239
1272
  max_length= args[0]->max_length * multiply;
1241
1274
 
1242
1275
void Item_func_ucase::fix_length_and_dec()
1243
1276
{
1244
 
  collation.set(args[0]->collation);
 
1277
  agg_arg_charsets_for_string_result(collation, args, 1);
1245
1278
  multiply= collation.collation->caseup_multiply;
1246
1279
  converter= collation.collation->cset->caseup;
1247
1280
  max_length= args[0]->max_length * multiply;
1289
1322
 
1290
1323
void Item_func_left::fix_length_and_dec()
1291
1324
{
1292
 
  collation.set(args[0]->collation);
 
1325
  agg_arg_charsets_for_string_result(collation, args, 1);
1293
1326
  left_right_max_length();
1294
1327
}
1295
1328
 
1322
1355
 
1323
1356
void Item_func_right::fix_length_and_dec()
1324
1357
{
1325
 
  collation.set(args[0]->collation);
 
1358
  agg_arg_charsets_for_string_result(collation, args, 1);
1326
1359
  left_right_max_length();
1327
1360
}
1328
1361
 
1378
1411
{
1379
1412
  max_length=args[0]->max_length;
1380
1413
 
1381
 
  collation.set(args[0]->collation);
 
1414
  agg_arg_charsets_for_string_result(collation, args, 1);
1382
1415
  if (args[1]->const_item())
1383
1416
  {
1384
1417
    int32 start= (int32) args[1]->val_int();
1403
1436
1404
1437
  max_length= args[0]->max_length;
1405
1438
 
1406
 
  if (agg_arg_charsets(collation, args, 2, MY_COLL_CMP_CONV, 1))
 
1439
  if (agg_arg_charsets_for_comparison(collation, args, 2))
1407
1440
    return;
1408
1441
}
1409
1442
 
1733
1766
  max_length= args[0]->max_length;
1734
1767
  if (arg_count == 1)
1735
1768
  {
1736
 
    collation.set(args[0]->collation);
 
1769
    agg_arg_charsets_for_string_result(collation, args, 1);
1737
1770
    remove.set_charset(collation.collation);
1738
1771
    remove.set_ascii(" ",1);
1739
1772
  }
1741
1774
  {
1742
1775
    // Handle character set for args[1] and args[0].
1743
1776
    // Note that we pass args[1] as the first item, and args[0] as the second.
1744
 
    if (agg_arg_charsets(collation, &args[1], 2, MY_COLL_CMP_CONV, -1))
 
1777
    if (agg_arg_charsets_for_comparison(collation, &args[1], 2, -1))
1745
1778
      return;
1746
1779
  }
1747
1780
}
1766
1799
 
1767
1800
/* Item_func_password */
1768
1801
 
1769
 
String *Item_func_password::val_str(String *str)
 
1802
String *Item_func_password::val_str_ascii(String *str)
1770
1803
{
1771
1804
  DBUG_ASSERT(fixed == 1);
1772
1805
  String *res= args[0]->val_str(str); 
1775
1808
  if (res->length() == 0)
1776
1809
    return &my_empty_string;
1777
1810
  my_make_scrambled_password(tmp_value, res->ptr(), res->length());
1778
 
  str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, res->charset());
 
1811
  str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, &my_charset_latin1);
1779
1812
  return str;
1780
1813
}
1781
1814
 
1790
1823
 
1791
1824
/* Item_func_old_password */
1792
1825
 
1793
 
String *Item_func_old_password::val_str(String *str)
 
1826
String *Item_func_old_password::val_str_ascii(String *str)
1794
1827
{
1795
1828
  DBUG_ASSERT(fixed == 1);
1796
1829
  String *res= args[0]->val_str(str);
1799
1832
  if (res->length() == 0)
1800
1833
    return &my_empty_string;
1801
1834
  my_make_scrambled_password_323(tmp_value, res->ptr(), res->length());
1802
 
  str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, res->charset());
 
1835
  str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, &my_charset_latin1);
1803
1836
  return str;
1804
1837
}
1805
1838
 
2019
2052
 
2020
2053
void Item_func_soundex::fix_length_and_dec()
2021
2054
{
2022
 
  collation.set(args[0]->collation);
 
2055
  agg_arg_charsets_for_string_result(collation, args, 1);
2023
2056
  max_length=args[0]->max_length;
2024
2057
  set_if_bigger(max_length, 4 * collation.collation->mbminlen);
2025
2058
  tmp_value.set_charset(collation.collation);
2325
2358
  max_length=0;
2326
2359
  decimals=0;
2327
2360
 
2328
 
  if (agg_arg_charsets(collation, args+1, arg_count-1, MY_COLL_ALLOW_CONV, 1))
 
2361
  if (agg_arg_charsets_for_string_result(collation, args + 1, arg_count - 1))
2329
2362
    return;
2330
2363
 
2331
2364
  for (uint i= 1 ; i < arg_count ; i++)
2392
2425
{
2393
2426
  max_length=arg_count-1;
2394
2427
 
2395
 
  if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
 
2428
  if (agg_arg_charsets_for_string_result(collation, args, arg_count))
2396
2429
    return;
2397
2430
  
2398
2431
  for (uint i=0 ; i < arg_count ; i++)
2562
2595
 
2563
2596
void Item_func_repeat::fix_length_and_dec()
2564
2597
{
2565
 
  collation.set(args[0]->collation);
 
2598
  agg_arg_charsets_for_string_result(collation, args, 1);
2566
2599
  if (args[1]->const_item())
2567
2600
  {
2568
2601
    /* must be longlong to avoid truncation */
2646
2679
void Item_func_rpad::fix_length_and_dec()
2647
2680
{
2648
2681
  // Handle character set for args[0] and args[2].
2649
 
  if (agg_arg_charsets(collation, &args[0], 2, MY_COLL_ALLOW_CONV, 2))
 
2682
  if (agg_arg_charsets_for_string_result(collation, &args[0], 2, 2))
2650
2683
    return;
2651
2684
  if (args[1]->const_item())
2652
2685
  {
2748
2781
void Item_func_lpad::fix_length_and_dec()
2749
2782
{
2750
2783
  // Handle character set for args[0] and args[2].
2751
 
  if (agg_arg_charsets(collation, &args[0], 2, MY_COLL_ALLOW_CONV, 2))
 
2784
  if (agg_arg_charsets_for_string_result(collation, &args[0], 2, 2))
2752
2785
    return;
2753
2786
  
2754
2787
  if (args[1]->const_item())
2918
2951
void Item_func_conv_charset::fix_length_and_dec()
2919
2952
{
2920
2953
  collation.set(conv_charset, DERIVATION_IMPLICIT);
2921
 
  max_length = args[0]->max_length*conv_charset->mbmaxlen;
 
2954
  fix_char_length(args[0]->max_char_length());
2922
2955
}
2923
2956
 
2924
2957
void Item_func_conv_charset::print(String *str, enum_query_type query_type)
3008
3041
  DBUG_ASSERT(fixed == 1);
3009
3042
  uint dummy_errors;
3010
3043
 
3011
 
  CHARSET_INFO *cs= args[0]->collation.collation; 
 
3044
  CHARSET_INFO *cs= args[0]->charset_for_protocol(); 
3012
3045
  null_value= 0;
3013
3046
  str->copy(cs->csname, strlen(cs->csname),
3014
3047
            &my_charset_latin1, collation.collation, &dummy_errors);
3019
3052
{
3020
3053
  DBUG_ASSERT(fixed == 1);
3021
3054
  uint dummy_errors;
3022
 
  CHARSET_INFO *cs= args[0]->collation.collation; 
 
3055
  CHARSET_INFO *cs= args[0]->charset_for_protocol(); 
3023
3056
 
3024
3057
  null_value= 0;
3025
3058
  str->copy(cs->name, strlen(cs->name),
3108
3141
    if ((null_value= args[0]->null_value))
3109
3142
      return 0;
3110
3143
    ptr= longlong2str(dec,ans,16);
3111
 
    if (str->copy(ans,(uint32) (ptr-ans),default_charset()))
 
3144
    if (str->copy(ans,(uint32) (ptr-ans), &my_charset_numeric))
3112
3145
      return &my_empty_string;                  // End of memory
3113
3146
    return str;
3114
3147
  }
3313
3346
{
3314
3347
  uint length=max(args[1]->max_length,args[2]->max_length);
3315
3348
  uint sep_length=(arg_count > 3 ? args[3]->max_length : 1);
3316
 
  max_length=length*64+sep_length*63;
3317
3349
 
3318
 
  if (agg_arg_charsets(collation, args+1, min(4,arg_count)-1,
3319
 
                       MY_COLL_ALLOW_CONV, 1))
 
3350
  if (agg_arg_charsets_for_string_result(collation,
 
3351
                                         args + 1, min(4, arg_count) - 1))
3320
3352
    return;
 
3353
  fix_char_length(length * 64 + sep_length * 63);
3321
3354
}
3322
3355
 
3323
3356
String* Item_func_inet_ntoa::val_str(String* str)
3336
3369
  if ((null_value= (args[0]->null_value || n > 4294967295ULL)))
3337
3370
    return 0;                                   // Null value
3338
3371
 
 
3372
  str->set_charset(collation.collation);
3339
3373
  str->length(0);
3340
3374
  int4store(buf,n);
3341
3375
 
3353
3387
    num[0]=(char) n1+'0';
3354
3388
    num[1]=(char) n2+'0';
3355
3389
    num[2]=(char) c+'0';
3356
 
    uint length=(n1 ? 4 : n2 ? 3 : 2);          // Remove pre-zero
3357
 
 
3358
 
    (void) str->append(num+4-length,length);
 
3390
    uint length= (n1 ? 4 : n2 ? 3 : 2);         // Remove pre-zero
 
3391
    uint dot_length= (p <= buf) ? 1 : 0;
 
3392
    (void) str->append(num + 4 - length, length - dot_length,
 
3393
                       &my_charset_latin1);
3359
3394
  }
3360
 
  str->length(str->length()-1);                 // Remove last '.';
3361
3395
  return str;
3362
3396
}
3363
3397