~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_strfunc.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
{
108
108
  assert(fixed == 1);
109
109
  String *res,*res2,*use_as_buff;
110
 
  uint i;
 
110
  uint32_t i;
111
111
  bool is_const= 0;
112
112
 
113
113
  null_value=0;
194
194
          more than 25% of memory will be overcommitted on average.
195
195
        */
196
196
 
197
 
        uint concat_len= res->length() + res2->length();
 
197
        uint32_t concat_len= res->length() + res2->length();
198
198
 
199
199
        if (tmp_value.alloced_length() < concat_len)
200
200
        {
205
205
          }
206
206
          else
207
207
          {
208
 
            uint new_len = cmax(tmp_value.alloced_length() * 2, concat_len);
 
208
            uint32_t new_len = cmax(tmp_value.alloced_length() * 2, concat_len);
209
209
 
210
210
            if (tmp_value.realloc(new_len))
211
211
              goto null;
237
237
  if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
238
238
    return;
239
239
 
240
 
  for (uint i=0 ; i < arg_count ; i++)
 
240
  for (uint32_t i=0 ; i < arg_count ; i++)
241
241
  {
242
242
    if (args[i]->collation.collation->mbmaxlen != collation.collation->mbmaxlen)
243
243
      max_result_length+= (args[i]->max_length /
267
267
  char tmp_str_buff[10];
268
268
  String tmp_sep_str(tmp_str_buff, sizeof(tmp_str_buff),default_charset_info),
269
269
         *sep_str, *res, *res2,*use_as_buff;
270
 
  uint i;
 
270
  uint32_t i;
271
271
 
272
272
  null_value=0;
273
273
  if (!(sep_str= args[0]->val_str(&tmp_sep_str)))
364
364
        25% of memory will be overcommitted on average.
365
365
      */
366
366
 
367
 
      uint concat_len= res->length() + sep_str->length() + res2->length();
 
367
      uint32_t concat_len= res->length() + sep_str->length() + res2->length();
368
368
 
369
369
      if (tmp_value.alloced_length() < concat_len)
370
370
      {
375
375
        }
376
376
        else
377
377
        {
378
 
          uint new_len = cmax(tmp_value.alloced_length() * 2, concat_len);
 
378
          uint32_t new_len = cmax(tmp_value.alloced_length() * 2, concat_len);
379
379
 
380
380
          if (tmp_value.realloc(new_len))
381
381
            goto null;
412
412
     so, (arg_count - 2) is safe here.
413
413
  */
414
414
  max_result_length= (uint64_t) args[0]->max_length * (arg_count - 2);
415
 
  for (uint i=1 ; i < arg_count ; i++)
 
415
  for (uint32_t i=1 ; i < arg_count ; i++)
416
416
    max_result_length+=args[i]->max_length;
417
417
 
418
418
  if (max_result_length >= MAX_BLOB_WIDTH)
492
492
  assert(fixed == 1);
493
493
  String *res,*res2,*res3;
494
494
  int offset;
495
 
  uint from_length,to_length;
 
495
  uint32_t from_length,to_length;
496
496
  bool alloced=0;
497
497
#ifdef USE_MB
498
498
  const char *ptr,*end,*strend,*search,*search_end;
702
702
  null_value=0;
703
703
  if (multiply == 1)
704
704
  {
705
 
    uint len;
 
705
    uint32_t len;
706
706
    res= copy_if_not_alloced(str,res,res->length());
707
707
    len= converter(collation.collation, (char*) res->ptr(), res->length(),
708
708
                                        (char*) res->ptr(), res->length());
711
711
  }
712
712
  else
713
713
  {
714
 
    uint len= res->length() * multiply;
 
714
    uint32_t len= res->length() * multiply;
715
715
    tmp_value.alloc(len);
716
716
    tmp_value.set_charset(collation.collation);
717
717
    len= converter(collation.collation, (char*) res->ptr(), res->length(),
747
747
 
748
748
  /* must be int64_t to avoid truncation */
749
749
  int64_t length= args[1]->val_int();
750
 
  uint char_pos;
 
750
  uint32_t char_pos;
751
751
 
752
752
  if ((null_value=(args[0]->null_value || args[1]->null_value)))
753
753
    return 0;
803
803
  if (res->length() <= (uint64_t) length)
804
804
    return res; /* purecov: inspected */
805
805
 
806
 
  uint start=res->numchars();
 
806
  uint32_t start=res->numchars();
807
807
  if (start <= (uint) length)
808
808
    return res;
809
809
  start=res->charpos(start - (uint) length);
906
906
  String *res= args[0]->val_str(str);
907
907
  String *delimiter= args[1]->val_str(&tmp_value);
908
908
  int32_t count= (int32_t) args[2]->val_int();
909
 
  uint offset;
 
909
  uint32_t offset;
910
910
 
911
911
  if (args[0]->null_value || args[1]->null_value || args[2]->null_value)
912
912
  {                                     // string and/or delim are null
914
914
    return 0;
915
915
  }
916
916
  null_value=0;
917
 
  uint delimiter_length= delimiter->length();
 
917
  uint32_t delimiter_length= delimiter->length();
918
918
  if (!res->length() || !delimiter_length || !count)
919
919
    return &my_empty_string;            // Wrong parameters
920
920
 
1036
1036
  char buff[MAX_FIELD_WIDTH], *ptr, *end;
1037
1037
  String tmp(buff,sizeof(buff),system_charset_info);
1038
1038
  String *res, *remove_str;
1039
 
  uint remove_length;
 
1039
  uint32_t remove_length;
1040
1040
 
1041
1041
  res= args[0]->val_str(str);
1042
1042
  if ((null_value=args[0]->null_value))
1082
1082
  char buff[MAX_FIELD_WIDTH], *ptr, *end;
1083
1083
  String tmp(buff, sizeof(buff), system_charset_info);
1084
1084
  String *res, *remove_str;
1085
 
  uint remove_length;
 
1085
  uint32_t remove_length;
1086
1086
 
1087
1087
  res= args[0]->val_str(str);
1088
1088
  if ((null_value=args[0]->null_value))
1163
1163
  const char *r_ptr;
1164
1164
  String tmp(buff, sizeof(buff), system_charset_info);
1165
1165
  String *res, *remove_str;
1166
 
  uint remove_length;
 
1166
  uint32_t remove_length;
1167
1167
 
1168
1168
  res= args[0]->val_str(str);
1169
1169
  if ((null_value=args[0]->null_value))
1256
1256
Item *Item_func_sysconst::safe_charset_converter(const CHARSET_INFO * const tocs)
1257
1257
{
1258
1258
  Item_string *conv;
1259
 
  uint conv_errors;
 
1259
  uint32_t conv_errors;
1260
1260
  String tmp, cstr, *ostr= val_str(&tmp);
1261
1261
  cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
1262
1262
  if (conv_errors ||
1300
1300
  if (user)
1301
1301
  {
1302
1302
    const CHARSET_INFO * const cs= str_value.charset();
1303
 
    uint res_length= (strlen(user)+strlen(host)+2) * cs->mbmaxlen;
 
1303
    uint32_t res_length= (strlen(user)+strlen(host)+2) * cs->mbmaxlen;
1304
1304
 
1305
1305
    if (str_value.alloc(res_length))
1306
1306
    {
1352
1352
void Item_func_format::fix_length_and_dec()
1353
1353
{
1354
1354
  collation.set(default_charset());
1355
 
  uint char_length= args[0]->max_length/args[0]->collation.collation->mbmaxlen;
 
1355
  uint32_t char_length= args[0]->max_length/args[0]->collation.collation->mbmaxlen;
1356
1356
  max_length= ((char_length + (char_length-args[0]->decimals)/3) *
1357
1357
               collation.collation->mbmaxlen);
1358
1358
}
1457
1457
  if (agg_arg_charsets(collation, args+1, arg_count-1, MY_COLL_ALLOW_CONV, 1))
1458
1458
    return;
1459
1459
 
1460
 
  for (uint i= 1 ; i < arg_count ; i++)
 
1460
  for (uint32_t i= 1 ; i < arg_count ; i++)
1461
1461
  {
1462
1462
    set_if_bigger(max_length,args[i]->max_length);
1463
1463
    set_if_bigger(decimals,args[i]->decimals);
1469
1469
double Item_func_elt::val_real()
1470
1470
{
1471
1471
  assert(fixed == 1);
1472
 
  uint tmp;
 
1472
  uint32_t tmp;
1473
1473
  null_value=1;
1474
1474
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
1475
1475
    return 0.0;
1482
1482
int64_t Item_func_elt::val_int()
1483
1483
{
1484
1484
  assert(fixed == 1);
1485
 
  uint tmp;
 
1485
  uint32_t tmp;
1486
1486
  null_value=1;
1487
1487
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
1488
1488
    return 0;
1496
1496
String *Item_func_elt::val_str(String *str)
1497
1497
{
1498
1498
  assert(fixed == 1);
1499
 
  uint tmp;
 
1499
  uint32_t tmp;
1500
1500
  null_value=1;
1501
1501
  if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
1502
1502
    return NULL;
1524
1524
  if (agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1))
1525
1525
    return;
1526
1526
  
1527
 
  for (uint i=0 ; i < arg_count ; i++)
 
1527
  for (uint32_t i=0 ; i < arg_count ; i++)
1528
1528
    max_length+=args[i]->max_length;
1529
1529
 
1530
1530
  used_tables_cache|=     item->used_tables();
1632
1632
  assert(fixed == 1);
1633
1633
  str->length(0);
1634
1634
  str->set_charset(collation.collation);
1635
 
  for (uint i=0 ; i < arg_count ; i++)
 
1635
  for (uint32_t i=0 ; i < arg_count ; i++)
1636
1636
  {
1637
1637
    int32_t num=(int32_t) args[i]->val_int();
1638
1638
    if (!args[i]->null_value)
1713
1713
String *Item_func_repeat::val_str(String *str)
1714
1714
{
1715
1715
  assert(fixed == 1);
1716
 
  uint length,tot_length;
 
1716
  uint32_t length,tot_length;
1717
1717
  char *to;
1718
1718
  /* must be int64_t to avoid truncation */
1719
1719
  int64_t count= args[1]->val_int();
2003
2003
  if (use_cached_value)
2004
2004
    return null_value ? 0 : &str_value;
2005
2005
  String *arg= args[0]->val_str(str);
2006
 
  uint dummy_errors;
 
2006
  uint32_t dummy_errors;
2007
2007
  if (!arg)
2008
2008
  {
2009
2009
    null_value=1;
2084
2084
  Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
2085
2085
  if (collation.collation != item_func_sc->collation.collation)
2086
2086
    return 0;
2087
 
  for (uint i=0; i < arg_count ; i++)
 
2087
  for (uint32_t i=0; i < arg_count ; i++)
2088
2088
    if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
2089
2089
      return 0;
2090
2090
  return 1;
2105
2105
String *Item_func_charset::val_str(String *str)
2106
2106
{
2107
2107
  assert(fixed == 1);
2108
 
  uint dummy_errors;
 
2108
  uint32_t dummy_errors;
2109
2109
 
2110
2110
  const CHARSET_INFO * const cs= args[0]->collation.collation; 
2111
2111
  null_value= 0;
2117
2117
String *Item_func_collation::val_str(String *str)
2118
2118
{
2119
2119
  assert(fixed == 1);
2120
 
  uint dummy_errors;
 
2120
  uint32_t dummy_errors;
2121
2121
  const CHARSET_INFO * const cs= args[0]->collation.collation; 
2122
2122
 
2123
2123
  null_value= 0;
2142
2142
{
2143
2143
  String *res;
2144
2144
  const CHARSET_INFO * const cs= args[0]->collation.collation;
2145
 
  uint tmp_length, frm_length;
 
2145
  uint32_t tmp_length, frm_length;
2146
2146
  assert(fixed == 1);
2147
2147
 
2148
2148
  if (args[0]->result_type() != STRING_RESULT ||
2221
2221
  const char *from, *end;
2222
2222
  char *to;
2223
2223
  String *res;
2224
 
  uint length;
 
2224
  uint32_t length;
2225
2225
  assert(fixed == 1);
2226
2226
 
2227
2227
  res= args[0]->val_str(str);
2329
2329
  no = args[2]->val_str(&no_buf);
2330
2330
  String *sep = NULL, sep_buf ;
2331
2331
 
2332
 
  uint num_set_values = 64;
 
2332
  uint32_t num_set_values = 64;
2333
2333
  uint64_t mask = 0x1;
2334
2334
  str->length(0);
2335
2335
  str->set_charset(collation.collation);
2365
2365
  case 3:
2366
2366
    {
2367
2367
      /* errors is not checked - assume "," can always be converted */
2368
 
      uint errors;
 
2368
      uint32_t errors;
2369
2369
      sep_buf.copy(STRING_WITH_LEN(","), &my_charset_bin, collation.collation, &errors);
2370
2370
      sep = &sep_buf;
2371
2371
    }
2375
2375
  }
2376
2376
  null_value=0;
2377
2377
 
2378
 
  for (uint i = 0; i < num_set_values; i++, mask = (mask << 1))
 
2378
  for (uint32_t i = 0; i < num_set_values; i++, mask = (mask << 1))
2379
2379
  {
2380
2380
    if (the_set & mask)
2381
2381
      str->append(*yes);
2389
2389
 
2390
2390
void Item_func_export_set::fix_length_and_dec()
2391
2391
{
2392
 
  uint length=cmax(args[1]->max_length,args[2]->max_length);
2393
 
  uint sep_length=(arg_count > 3 ? args[3]->max_length : 1);
 
2392
  uint32_t length=cmax(args[1]->max_length,args[2]->max_length);
 
2393
  uint32_t sep_length=(arg_count > 3 ? args[3]->max_length : 1);
2394
2394
  max_length=length*64+sep_length*63;
2395
2395
 
2396
2396
  if (agg_arg_charsets(collation, args+1, cmin((uint)4,arg_count)-1,
2438
2438
 
2439
2439
  char *from, *to, *end, *start;
2440
2440
  String *arg= args[0]->val_str(str);
2441
 
  uint arg_length, new_length;
 
2441
  uint32_t arg_length, new_length;
2442
2442
  if (!arg)                                     // Null argument
2443
2443
  {
2444
2444
    /* Return the string 'NULL' */
2506
2506
*/
2507
2507
 
2508
2508
static struct rand_struct uuid_rand;
2509
 
static uint nanoseq;
 
2509
static uint32_t nanoseq;
2510
2510
static uint64_t uuid_time=0;
2511
2511
static char clock_seq_and_node_str[]="-0000-000000000000";
2512
2512
 
2519
2519
#define UUID_VERSION      0x1000
2520
2520
#define UUID_VARIANT      0x8000
2521
2521
 
2522
 
static void tohex(char *to, uint from, uint len)
 
2522
static void tohex(char *to, uint32_t from, uint32_t len)
2523
2523
{
2524
2524
  to+= len;
2525
2525
  while (len--)