~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_func.cc

  • Committer: Brian Aker
  • Date: 2008-07-13 22:45:08 UTC
  • Revision ID: brian@tangent.org-20080713224508-hb20z4okblotb39a
longlong replacement

Show diffs side-by-side

added added

removed removed

Lines of Context:
453
453
  switch (result_type()) {
454
454
  case INT_RESULT:
455
455
    if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
456
 
      field= new Field_longlong(max_length, maybe_null, name, unsigned_flag);
 
456
      field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
457
457
    else
458
458
      field= new Field_long(max_length, maybe_null, name, unsigned_flag);
459
459
    break;
632
632
String *Item_int_func::val_str(String *str)
633
633
{
634
634
  assert(fixed == 1);
635
 
  longlong nr=val_int();
 
635
  int64_t nr=val_int();
636
636
  if (null_value)
637
637
    return 0;
638
638
  str->set_int(nr, unsigned_flag, &my_charset_bin);
746
746
  }
747
747
  case INT_RESULT:
748
748
  {
749
 
    longlong nr= int_op();
 
749
    int64_t nr= int_op();
750
750
    if (null_value)
751
751
      return 0; /* purecov: inspected */
752
752
    str->set_int(nr, unsigned_flag, &my_charset_bin);
784
784
  }
785
785
  case INT_RESULT:
786
786
  {
787
 
    longlong result= int_op();
 
787
    int64_t result= int_op();
788
788
    return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
789
789
  }
790
790
  case REAL_RESULT:
804
804
}
805
805
 
806
806
 
807
 
longlong Item_func_numhybrid::val_int()
 
807
int64_t Item_func_numhybrid::val_int()
808
808
{
809
809
  assert(fixed == 1);
810
810
  switch (hybrid_type) {
813
813
    my_decimal decimal_value, *val;
814
814
    if (!(val= decimal_op(&decimal_value)))
815
815
      return 0;                                 // null is set
816
 
    longlong result;
 
816
    int64_t result;
817
817
    my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
818
818
    return result;
819
819
  }
820
820
  case INT_RESULT:
821
821
    return int_op();
822
822
  case REAL_RESULT:
823
 
    return (longlong) rint(real_op());
 
823
    return (int64_t) rint(real_op());
824
824
  case STRING_RESULT:
825
825
  {
826
826
    int err_not_used;
849
849
    break;
850
850
  case INT_RESULT:
851
851
  {
852
 
    longlong result= int_op();
 
852
    int64_t result= int_op();
853
853
    int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
854
854
    break;
855
855
  }
886
886
}
887
887
 
888
888
 
889
 
longlong Item_func_signed::val_int_from_str(int *error)
 
889
int64_t Item_func_signed::val_int_from_str(int *error)
890
890
{
891
891
  char buff[MAX_FIELD_WIDTH], *end, *start;
892
892
  uint32 length;
893
893
  String tmp(buff,sizeof(buff), &my_charset_bin), *res;
894
 
  longlong value;
 
894
  int64_t value;
895
895
 
896
896
  /*
897
897
    For a string result, we must first get the string and then convert it
898
 
    to a longlong
 
898
    to a int64_t
899
899
  */
900
900
 
901
901
  if (!(res= args[0]->val_str(&tmp)))
924
924
}
925
925
 
926
926
 
927
 
longlong Item_func_signed::val_int()
 
927
int64_t Item_func_signed::val_int()
928
928
{
929
 
  longlong value;
 
929
  int64_t value;
930
930
  int error;
931
931
 
932
932
  if (args[0]->cast_to_int_type() != STRING_RESULT ||
933
 
      args[0]->result_as_longlong())
 
933
      args[0]->result_as_int64_t())
934
934
  {
935
935
    value= args[0]->val_int();
936
936
    null_value= args[0]->null_value; 
957
957
}
958
958
 
959
959
 
960
 
longlong Item_func_unsigned::val_int()
 
960
int64_t Item_func_unsigned::val_int()
961
961
{
962
 
  longlong value;
 
962
  int64_t value;
963
963
  int error;
964
964
 
965
965
  if (args[0]->cast_to_int_type() == DECIMAL_RESULT)
972
972
    return value;
973
973
  }
974
974
  else if (args[0]->cast_to_int_type() != STRING_RESULT ||
975
 
           args[0]->result_as_longlong())
 
975
           args[0]->result_as_int64_t())
976
976
  {
977
977
    value= args[0]->val_int();
978
978
    null_value= args[0]->null_value; 
1009
1009
}
1010
1010
 
1011
1011
 
1012
 
longlong Item_decimal_typecast::val_int()
 
1012
int64_t Item_decimal_typecast::val_int()
1013
1013
{
1014
1014
  my_decimal tmp_buf, *tmp= val_decimal(&tmp_buf);
1015
 
  longlong res;
 
1015
  int64_t res;
1016
1016
  if (null_value)
1017
1017
    return 0;
1018
1018
  my_decimal2int(E_DEC_FATAL_ERROR, tmp, unsigned_flag, &res);
1090
1090
}
1091
1091
 
1092
1092
 
1093
 
longlong Item_func_plus::int_op()
 
1093
int64_t Item_func_plus::int_op()
1094
1094
{
1095
 
  longlong value=args[0]->val_int()+args[1]->val_int();
 
1095
  int64_t value=args[0]->val_int()+args[1]->val_int();
1096
1096
  if ((null_value=args[0]->null_value || args[1]->null_value))
1097
1097
    return 0;
1098
1098
  return value;
1168
1168
}
1169
1169
 
1170
1170
 
1171
 
longlong Item_func_minus::int_op()
 
1171
int64_t Item_func_minus::int_op()
1172
1172
{
1173
 
  longlong value=args[0]->val_int() - args[1]->val_int();
 
1173
  int64_t value=args[0]->val_int() - args[1]->val_int();
1174
1174
  if ((null_value=args[0]->null_value || args[1]->null_value))
1175
1175
    return 0;
1176
1176
  return value;
1208
1208
}
1209
1209
 
1210
1210
 
1211
 
longlong Item_func_mul::int_op()
 
1211
int64_t Item_func_mul::int_op()
1212
1212
{
1213
1213
  assert(fixed == 1);
1214
 
  longlong value=args[0]->val_int()*args[1]->val_int();
 
1214
  int64_t value=args[0]->val_int()*args[1]->val_int();
1215
1215
  if ((null_value=args[0]->null_value || args[1]->null_value))
1216
1216
    return 0;
1217
1217
  return value;
1335
1335
 
1336
1336
 
1337
1337
/* Integer division */
1338
 
longlong Item_func_int_div::val_int()
 
1338
int64_t Item_func_int_div::val_int()
1339
1339
{
1340
1340
  assert(fixed == 1);
1341
 
  longlong value=args[0]->val_int();
1342
 
  longlong val2=args[1]->val_int();
 
1341
  int64_t value=args[0]->val_int();
 
1342
  int64_t val2=args[1]->val_int();
1343
1343
  if ((null_value= (args[0]->null_value || args[1]->null_value)))
1344
1344
    return 0;
1345
1345
  if (val2 == 0)
1365
1365
}
1366
1366
 
1367
1367
 
1368
 
longlong Item_func_mod::int_op()
 
1368
int64_t Item_func_mod::int_op()
1369
1369
{
1370
1370
  assert(fixed == 1);
1371
 
  longlong value=  args[0]->val_int();
1372
 
  longlong val2= args[1]->val_int();
1373
 
  longlong result;
 
1371
  int64_t value=  args[0]->val_int();
 
1372
  int64_t val2= args[1]->val_int();
 
1373
  int64_t result;
1374
1374
 
1375
1375
  if ((null_value= args[0]->null_value || args[1]->null_value))
1376
1376
    return 0; /* purecov: inspected */
1454
1454
}
1455
1455
 
1456
1456
 
1457
 
longlong Item_func_neg::int_op()
 
1457
int64_t Item_func_neg::int_op()
1458
1458
{
1459
 
  longlong value= args[0]->val_int();
 
1459
  int64_t value= args[0]->val_int();
1460
1460
  null_value= args[0]->null_value;
1461
1461
  return -value;
1462
1462
}
1495
1495
  */
1496
1496
  if (hybrid_type == INT_RESULT && args[0]->const_item())
1497
1497
  {
1498
 
    longlong val= args[0]->val_int();
 
1498
    int64_t val= args[0]->val_int();
1499
1499
    if ((uint64_t) val >= (uint64_t) LONGLONG_MIN &&
1500
1500
        ((uint64_t) val != (uint64_t) LONGLONG_MIN ||
1501
1501
          args[0]->type() != INT_ITEM))        
1502
1502
    {
1503
1503
      /*
1504
 
        Ensure that result is converted to DECIMAL, as longlong can't hold
 
1504
        Ensure that result is converted to DECIMAL, as int64_t can't hold
1505
1505
        the negated number
1506
1506
      */
1507
1507
      hybrid_type= DECIMAL_RESULT;
1520
1520
}
1521
1521
 
1522
1522
 
1523
 
longlong Item_func_abs::int_op()
 
1523
int64_t Item_func_abs::int_op()
1524
1524
{
1525
 
  longlong value= args[0]->val_int();
 
1525
  int64_t value= args[0]->val_int();
1526
1526
  if ((null_value= args[0]->null_value))
1527
1527
    return 0;
1528
1528
  return (value >= 0) || unsigned_flag ? value : -value;
1723
1723
// Shift-functions, same as << and >> in C/C++
1724
1724
 
1725
1725
 
1726
 
longlong Item_func_shift_left::val_int()
 
1726
int64_t Item_func_shift_left::val_int()
1727
1727
{
1728
1728
  assert(fixed == 1);
1729
1729
  uint shift;
1735
1735
    return 0;
1736
1736
  }
1737
1737
  null_value=0;
1738
 
  return (shift < sizeof(longlong)*8 ? (longlong) res : 0LL);
 
1738
  return (shift < sizeof(int64_t)*8 ? (int64_t) res : 0LL);
1739
1739
}
1740
1740
 
1741
 
longlong Item_func_shift_right::val_int()
 
1741
int64_t Item_func_shift_right::val_int()
1742
1742
{
1743
1743
  assert(fixed == 1);
1744
1744
  uint shift;
1750
1750
    return 0;
1751
1751
  }
1752
1752
  null_value=0;
1753
 
  return (shift < sizeof(longlong)*8 ? (longlong) res : 0LL);
 
1753
  return (shift < sizeof(int64_t)*8 ? (int64_t) res : 0LL);
1754
1754
}
1755
1755
 
1756
1756
 
1757
 
longlong Item_func_bit_neg::val_int()
 
1757
int64_t Item_func_bit_neg::val_int()
1758
1758
{
1759
1759
  assert(fixed == 1);
1760
1760
  uint64_t res= (uint64_t) args[0]->val_int();
1797
1797
  case INT_RESULT:
1798
1798
  case DECIMAL_RESULT:
1799
1799
    /*
1800
 
      -2 because in most high position can't be used any digit for longlong
 
1800
      -2 because in most high position can't be used any digit for int64_t
1801
1801
      and one position for increasing value during operation
1802
1802
    */
1803
1803
    if ((args[0]->max_length - args[0]->decimals) >=
1818
1818
}
1819
1819
 
1820
1820
 
1821
 
longlong Item_func_ceiling::int_op()
 
1821
int64_t Item_func_ceiling::int_op()
1822
1822
{
1823
 
  longlong result;
 
1823
  int64_t result;
1824
1824
  switch (args[0]->result_type()) {
1825
1825
  case INT_RESULT:
1826
1826
    result= args[0]->val_int();
1836
1836
    break;
1837
1837
  }
1838
1838
  default:
1839
 
    result= (longlong)Item_func_ceiling::real_op();
 
1839
    result= (int64_t)Item_func_ceiling::real_op();
1840
1840
  };
1841
1841
  return result;
1842
1842
}
1865
1865
}
1866
1866
 
1867
1867
 
1868
 
longlong Item_func_floor::int_op()
 
1868
int64_t Item_func_floor::int_op()
1869
1869
{
1870
 
  longlong result;
 
1870
  int64_t result;
1871
1871
  switch (args[0]->result_type()) {
1872
1872
  case INT_RESULT:
1873
1873
    result= args[0]->val_int();
1883
1883
    break;
1884
1884
  }
1885
1885
  default:
1886
 
    result= (longlong)Item_func_floor::real_op();
 
1886
    result= (int64_t)Item_func_floor::real_op();
1887
1887
  };
1888
1888
  return result;
1889
1889
}
1915
1915
void Item_func_round::fix_length_and_dec()
1916
1916
{
1917
1917
  int      decimals_to_set;
1918
 
  longlong val1;
 
1918
  int64_t val1;
1919
1919
  bool     val1_unsigned;
1920
1920
  
1921
1921
  unsigned_flag= args[0]->unsigned_flag;
1985
1985
  }
1986
1986
}
1987
1987
 
1988
 
double my_double_round(double value, longlong dec, bool dec_unsigned,
 
1988
double my_double_round(double value, int64_t dec, bool dec_unsigned,
1989
1989
                       bool truncate)
1990
1990
{
1991
1991
  double tmp;
2040
2040
}
2041
2041
 
2042
2042
 
2043
 
longlong Item_func_round::int_op()
 
2043
int64_t Item_func_round::int_op()
2044
2044
{
2045
 
  longlong value= args[0]->val_int();
2046
 
  longlong dec= args[1]->val_int();
 
2045
  int64_t value= args[0]->val_int();
 
2046
  int64_t dec= args[1]->val_int();
2047
2047
  decimals= 0;
2048
2048
  uint64_t abs_dec;
2049
2049
  if ((null_value= args[0]->null_value || args[1]->null_value))
2052
2052
    return value; // integer have not digits after point
2053
2053
 
2054
2054
  abs_dec= -dec;
2055
 
  longlong tmp;
 
2055
  int64_t tmp;
2056
2056
  
2057
2057
  if(abs_dec >= array_elements(log_10_int))
2058
2058
    return 0;
2065
2065
  else
2066
2066
    value= (unsigned_flag || value >= 0) ?
2067
2067
      my_unsigned_round((uint64_t) value, tmp) :
2068
 
      -(longlong) my_unsigned_round((uint64_t) -value, tmp);
 
2068
      -(int64_t) my_unsigned_round((uint64_t) -value, tmp);
2069
2069
  return value;
2070
2070
}
2071
2071
 
2073
2073
my_decimal *Item_func_round::decimal_op(my_decimal *decimal_value)
2074
2074
{
2075
2075
  my_decimal val, *value= args[0]->val_decimal(&val);
2076
 
  longlong dec= args[1]->val_int();
 
2076
  int64_t dec= args[1]->val_int();
2077
2077
  if (dec >= 0 || args[1]->unsigned_flag)
2078
2078
    dec= min((uint64_t) dec, decimals);
2079
2079
  else if (dec < INT_MIN)
2157
2157
  return my_rnd(rand);
2158
2158
}
2159
2159
 
2160
 
longlong Item_func_sign::val_int()
 
2160
int64_t Item_func_sign::val_int()
2161
2161
{
2162
2162
  assert(fixed == 1);
2163
2163
  double value= args[0]->val_real();
2278
2278
  switch (cmp_type) {
2279
2279
  case INT_RESULT:
2280
2280
  {
2281
 
    longlong nr=val_int();
 
2281
    int64_t nr=val_int();
2282
2282
    if (null_value)
2283
2283
      return 0;
2284
2284
    str->set_int(nr, unsigned_flag, &my_charset_bin);
2362
2362
}
2363
2363
 
2364
2364
 
2365
 
longlong Item_func_min_max::val_int()
 
2365
int64_t Item_func_min_max::val_int()
2366
2366
{
2367
2367
  assert(fixed == 1);
2368
 
  longlong value=0;
 
2368
  int64_t value=0;
2369
2369
  if (compare_as_dates)
2370
2370
  {
2371
2371
    uint64_t result= 0;
2372
2372
    (void)cmp_datetimes(&result);
2373
 
    return (longlong)result;
 
2373
    return (int64_t)result;
2374
2374
  }
2375
2375
  for (uint i=0; i < arg_count ; i++)
2376
2376
  {
2378
2378
      value=args[i]->val_int();
2379
2379
    else
2380
2380
    {
2381
 
      longlong tmp=args[i]->val_int();
 
2381
      int64_t tmp=args[i]->val_int();
2382
2382
      if (!args[i]->null_value && (tmp < value ? cmp_sign : -cmp_sign) > 0)
2383
2383
        value=tmp;
2384
2384
    }
2430
2430
}
2431
2431
 
2432
2432
 
2433
 
longlong Item_func_length::val_int()
2434
 
{
2435
 
  assert(fixed == 1);
2436
 
  String *res=args[0]->val_str(&value);
2437
 
  if (!res)
2438
 
  {
2439
 
    null_value=1;
2440
 
    return 0; /* purecov: inspected */
2441
 
  }
2442
 
  null_value=0;
2443
 
  return (longlong) res->length();
2444
 
}
2445
 
 
2446
 
 
2447
 
longlong Item_func_char_length::val_int()
2448
 
{
2449
 
  assert(fixed == 1);
2450
 
  String *res=args[0]->val_str(&value);
2451
 
  if (!res)
2452
 
  {
2453
 
    null_value=1;
2454
 
    return 0; /* purecov: inspected */
2455
 
  }
2456
 
  null_value=0;
2457
 
  return (longlong) res->numchars();
2458
 
}
2459
 
 
2460
 
 
2461
 
longlong Item_func_coercibility::val_int()
 
2433
int64_t Item_func_length::val_int()
 
2434
{
 
2435
  assert(fixed == 1);
 
2436
  String *res=args[0]->val_str(&value);
 
2437
  if (!res)
 
2438
  {
 
2439
    null_value=1;
 
2440
    return 0; /* purecov: inspected */
 
2441
  }
 
2442
  null_value=0;
 
2443
  return (int64_t) res->length();
 
2444
}
 
2445
 
 
2446
 
 
2447
int64_t Item_func_char_length::val_int()
 
2448
{
 
2449
  assert(fixed == 1);
 
2450
  String *res=args[0]->val_str(&value);
 
2451
  if (!res)
 
2452
  {
 
2453
    null_value=1;
 
2454
    return 0; /* purecov: inspected */
 
2455
  }
 
2456
  null_value=0;
 
2457
  return (int64_t) res->numchars();
 
2458
}
 
2459
 
 
2460
 
 
2461
int64_t Item_func_coercibility::val_int()
2462
2462
{
2463
2463
  assert(fixed == 1);
2464
2464
  null_value= 0;
2465
 
  return (longlong) args[0]->collation.derivation;
 
2465
  return (int64_t) args[0]->collation.derivation;
2466
2466
}
2467
2467
 
2468
2468
 
2473
2473
}
2474
2474
 
2475
2475
 
2476
 
longlong Item_func_locate::val_int()
 
2476
int64_t Item_func_locate::val_int()
2477
2477
{
2478
2478
  assert(fixed == 1);
2479
2479
  String *a=args[0]->val_str(&value1);
2484
2484
    return 0; /* purecov: inspected */
2485
2485
  }
2486
2486
  null_value=0;
2487
 
  /* must be longlong to avoid truncation */
2488
 
  longlong start=  0; 
2489
 
  longlong start0= 0;
 
2487
  /* must be int64_t to avoid truncation */
 
2488
  int64_t start=  0; 
 
2489
  int64_t start0= 0;
2490
2490
  my_match_t match;
2491
2491
 
2492
2492
  if (arg_count == 3)
2512
2512
                                            b->ptr(), b->length(),
2513
2513
                                            &match, 1))
2514
2514
    return 0;
2515
 
  return (longlong) match.mb_len + start0 + 1;
 
2515
  return (int64_t) match.mb_len + start0 + 1;
2516
2516
}
2517
2517
 
2518
2518
 
2531
2531
}
2532
2532
 
2533
2533
 
2534
 
longlong Item_func_field::val_int()
 
2534
int64_t Item_func_field::val_int()
2535
2535
{
2536
2536
  assert(fixed == 1);
2537
2537
 
2544
2544
    {
2545
2545
      String *tmp_value=args[i]->val_str(&tmp);
2546
2546
      if (tmp_value && !sortcmp(field,tmp_value,cmp_collation.collation))
2547
 
        return (longlong) (i);
 
2547
        return (int64_t) (i);
2548
2548
    }
2549
2549
  }
2550
2550
  else if (cmp_type == INT_RESULT)
2551
2551
  {
2552
 
    longlong val= args[0]->val_int();
 
2552
    int64_t val= args[0]->val_int();
2553
2553
    if (args[0]->null_value)
2554
2554
      return 0;
2555
2555
    for (uint i=1; i < arg_count ; i++)
2556
2556
    {
2557
2557
      if (val == args[i]->val_int() && !args[i]->null_value)
2558
 
        return (longlong) (i);
 
2558
        return (int64_t) (i);
2559
2559
    }
2560
2560
  }
2561
2561
  else if (cmp_type == DECIMAL_RESULT)
2568
2568
    {
2569
2569
      dec_arg= args[i]->val_decimal(&dec_arg_buf);
2570
2570
      if (!args[i]->null_value && !my_decimal_cmp(dec_arg, dec))
2571
 
        return (longlong) (i);
 
2571
        return (int64_t) (i);
2572
2572
    }
2573
2573
  }
2574
2574
  else
2579
2579
    for (uint i=1; i < arg_count ; i++)
2580
2580
    {
2581
2581
      if (val == args[i]->val_real() && !args[i]->null_value)
2582
 
        return (longlong) (i);
 
2582
        return (int64_t) (i);
2583
2583
    }
2584
2584
  }
2585
2585
  return 0;
2597
2597
}
2598
2598
 
2599
2599
 
2600
 
longlong Item_func_ascii::val_int()
 
2600
int64_t Item_func_ascii::val_int()
2601
2601
{
2602
2602
  assert(fixed == 1);
2603
2603
  String *res=args[0]->val_str(&value);
2607
2607
    return 0;
2608
2608
  }
2609
2609
  null_value=0;
2610
 
  return (longlong) (res->length() ? (uchar) (*res)[0] : (uchar) 0);
 
2610
  return (int64_t) (res->length() ? (uchar) (*res)[0] : (uchar) 0);
2611
2611
}
2612
2612
 
2613
 
longlong Item_func_ord::val_int()
 
2613
int64_t Item_func_ord::val_int()
2614
2614
{
2615
2615
  assert(fixed == 1);
2616
2616
  String *res=args[0]->val_str(&value);
2627
2627
    register const char *str=res->ptr();
2628
2628
    register uint32 n=0, l=my_ismbchar(res->charset(),str,str+res->length());
2629
2629
    if (!l)
2630
 
      return (longlong)((uchar) *str);
 
2630
      return (int64_t)((uchar) *str);
2631
2631
    while (l--)
2632
2632
      n=(n<<8)|(uint32)((uchar) *str++);
2633
 
    return (longlong) n;
 
2633
    return (int64_t) n;
2634
2634
  }
2635
2635
#endif
2636
 
  return (longlong) ((uchar) (*res)[0]);
 
2636
  return (int64_t) ((uchar) (*res)[0]);
2637
2637
}
2638
2638
 
2639
2639
        /* Search after a string in a string of strings separated by ',' */
2665
2665
 
2666
2666
static const char separator=',';
2667
2667
 
2668
 
longlong Item_func_find_in_set::val_int()
 
2668
int64_t Item_func_find_in_set::val_int()
2669
2669
{
2670
2670
  assert(fixed == 1);
2671
2671
  if (enum_value)
2716
2716
          if (!my_strnncoll(cs, (const uchar *) str_begin,
2717
2717
                            str_end - str_begin,
2718
2718
                            find_str, find_str_len))
2719
 
            return (longlong) position;
 
2719
            return (int64_t) position;
2720
2720
          else
2721
2721
            str_begin= substr_end;
2722
2722
        }
2725
2725
      else if (str_end - str_begin == 0 &&
2726
2726
               find_str_len == 0 &&
2727
2727
               wc == (my_wc_t) separator)
2728
 
        return (longlong) ++position;
 
2728
        return (int64_t) ++position;
2729
2729
      else
2730
2730
        return 0LL;
2731
2731
    }
2733
2733
  return 0;
2734
2734
}
2735
2735
 
2736
 
longlong Item_func_bit_count::val_int()
 
2736
int64_t Item_func_bit_count::val_int()
2737
2737
{
2738
2738
  assert(fixed == 1);
2739
2739
  uint64_t value= (uint64_t) args[0]->val_int();
2740
2740
  if ((null_value= args[0]->null_value))
2741
2741
    return 0; /* purecov: inspected */
2742
 
  return (longlong) my_count_bits(value);
 
2742
  return (int64_t) my_count_bits(value);
2743
2743
}
2744
2744
 
2745
2745
 
2888
2888
          break;
2889
2889
        }
2890
2890
        case INT_RESULT:
2891
 
          *((longlong*) to)= arguments[i]->val_int();
 
2891
          *((int64_t*) to)= arguments[i]->val_int();
2892
2892
          if (arguments[i]->null_value)
2893
2893
            continue;
2894
2894
          f_args.args[i]= to;
2895
 
          to+= ALIGN_SIZE(sizeof(longlong));
 
2895
          to+= ALIGN_SIZE(sizeof(int64_t));
2896
2896
          break;
2897
2897
        case REAL_RESULT:
2898
2898
          *((double*) to)= arguments[i]->val_real();
2960
2960
        }
2961
2961
      }
2962
2962
    case INT_RESULT:
2963
 
      *((longlong*) to) = args[i]->val_int();
 
2963
      *((int64_t*) to) = args[i]->val_int();
2964
2964
      if (!args[i]->null_value)
2965
2965
      {
2966
2966
        f_args.args[i]=to;
2967
 
        to+= ALIGN_SIZE(sizeof(longlong));
 
2967
        to+= ALIGN_SIZE(sizeof(int64_t));
2968
2968
      }
2969
2969
      break;
2970
2970
    case REAL_RESULT:
3093
3093
}
3094
3094
 
3095
3095
 
3096
 
longlong Item_func_udf_int::val_int()
 
3096
int64_t Item_func_udf_int::val_int()
3097
3097
{
3098
3098
  assert(fixed == 1);
3099
3099
  return(udf.val_int(&null_value));
3103
3103
String *Item_func_udf_int::val_str(String *str)
3104
3104
{
3105
3105
  assert(fixed == 1);
3106
 
  longlong nr=val_int();
 
3106
  int64_t nr=val_int();
3107
3107
  if (null_value)
3108
3108
    return 0;
3109
3109
  str->set_int(nr, unsigned_flag, &my_charset_bin);
3111
3111
}
3112
3112
 
3113
3113
 
3114
 
longlong Item_func_udf_decimal::val_int()
 
3114
int64_t Item_func_udf_decimal::val_int()
3115
3115
{
3116
3116
  my_decimal dec_buf, *dec= udf.val_decimal(&null_value, &dec_buf);
3117
 
  longlong result;
 
3117
  int64_t result;
3118
3118
  if (null_value)
3119
3119
    return 0;
3120
3120
  my_decimal2int(E_DEC_FATAL_ERROR, dec, unsigned_flag, &result);
3281
3281
  on the slave.
3282
3282
*/
3283
3283
 
3284
 
longlong Item_master_pos_wait::val_int()
 
3284
int64_t Item_master_pos_wait::val_int()
3285
3285
{
3286
3286
  assert(fixed == 1);
3287
3287
  THD* thd = current_thd;
3295
3295
    return 0;
3296
3296
  }
3297
3297
#ifdef HAVE_REPLICATION
3298
 
  longlong pos = (ulong)args[1]->val_int();
3299
 
  longlong timeout = (arg_count==3) ? args[2]->val_int() : 0 ;
 
3298
  int64_t pos = (ulong)args[1]->val_int();
 
3299
  int64_t timeout = (arg_count==3) ? args[2]->val_int() : 0 ;
3300
3300
  if ((event_count = active_mi->rli.wait_for_pos(thd, log_name, pos, timeout)) == -2)
3301
3301
  {
3302
3302
    null_value = 1;
3314
3314
#endif
3315
3315
 
3316
3316
 
3317
 
longlong Item_func_last_insert_id::val_int()
 
3317
int64_t Item_func_last_insert_id::val_int()
3318
3318
{
3319
3319
  THD *thd= current_thd;
3320
3320
  assert(fixed == 1);
3321
3321
  if (arg_count)
3322
3322
  {
3323
 
    longlong value= args[0]->val_int();
 
3323
    int64_t value= args[0]->val_int();
3324
3324
    null_value= args[0]->null_value;
3325
3325
    /*
3326
3326
      LAST_INSERT_ID(X) must affect the client's mysql_insert_id() as
3345
3345
 
3346
3346
/* This function is just used to test speed of different functions */
3347
3347
 
3348
 
longlong Item_func_benchmark::val_int()
 
3348
int64_t Item_func_benchmark::val_int()
3349
3349
{
3350
3350
  assert(fixed == 1);
3351
3351
  char buff[MAX_FIELD_WIDTH];
3357
3357
  loop_count= (uint64_t) args[0]->val_int();
3358
3358
 
3359
3359
  if (args[0]->null_value ||
3360
 
      (!args[0]->unsigned_flag && (((longlong) loop_count) < 0)))
 
3360
      (!args[0]->unsigned_flag && (((int64_t) loop_count) < 0)))
3361
3361
  {
3362
3362
    if (!args[0]->null_value)
3363
3363
    {
3364
3364
      char buff[22];
3365
 
      llstr(((longlong) loop_count), buff);
 
3365
      llstr(((int64_t) loop_count), buff);
3366
3366
      push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
3367
3367
                          ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE),
3368
3368
                          "count", buff, "benchmark");
3639
3639
  case REAL_RESULT:
3640
3640
    return *(double*) value;
3641
3641
  case INT_RESULT:
3642
 
    return (double) *(longlong*) value;
 
3642
    return (double) *(int64_t*) value;
3643
3643
  case DECIMAL_RESULT:
3644
3644
  {
3645
3645
    double result;
3658
3658
 
3659
3659
/** Get the value of a variable as an integer. */
3660
3660
 
3661
 
longlong user_var_entry::val_int(my_bool *null_value) const
 
3661
int64_t user_var_entry::val_int(my_bool *null_value) const
3662
3662
{
3663
3663
  if ((*null_value= (value == 0)))
3664
3664
    return 0LL;
3665
3665
 
3666
3666
  switch (type) {
3667
3667
  case REAL_RESULT:
3668
 
    return (longlong) *(double*) value;
 
3668
    return (int64_t) *(double*) value;
3669
3669
  case INT_RESULT:
3670
 
    return *(longlong*) value;
 
3670
    return *(int64_t*) value;
3671
3671
  case DECIMAL_RESULT:
3672
3672
  {
3673
 
    longlong result;
 
3673
    int64_t result;
3674
3674
    my_decimal2int(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, &result);
3675
3675
    return result;
3676
3676
  }
3701
3701
    break;
3702
3702
  case INT_RESULT:
3703
3703
    if (!unsigned_flag)
3704
 
      str->set(*(longlong*) value, &my_charset_bin);
 
3704
      str->set(*(int64_t*) value, &my_charset_bin);
3705
3705
    else
3706
3706
      str->set(*(uint64_t*) value, &my_charset_bin);
3707
3707
    break;
3730
3730
    double2my_decimal(E_DEC_FATAL_ERROR, *(double*) value, val);
3731
3731
    break;
3732
3732
  case INT_RESULT:
3733
 
    int2my_decimal(E_DEC_FATAL_ERROR, *(longlong*) value, 0, val);
 
3733
    int2my_decimal(E_DEC_FATAL_ERROR, *(int64_t*) value, 0, val);
3734
3734
    break;
3735
3735
  case DECIMAL_RESULT:
3736
3736
    val= (my_decimal *)value;
3878
3878
  return entry->val_real(&null_value);
3879
3879
}
3880
3880
 
3881
 
longlong Item_func_set_user_var::val_int()
 
3881
int64_t Item_func_set_user_var::val_int()
3882
3882
{
3883
3883
  assert(fixed == 1);
3884
3884
  check(0);
3912
3912
  return entry->val_real(&null_value);
3913
3913
}
3914
3914
 
3915
 
longlong Item_func_set_user_var::val_int_result()
 
3915
int64_t Item_func_set_user_var::val_int_result()
3916
3916
{
3917
3917
  assert(fixed == 1);
3918
3918
  check(true);
4072
4072
  }
4073
4073
  else
4074
4074
  {
4075
 
    longlong nr= entry->val_int(&null_value);
 
4075
    int64_t nr= entry->val_int(&null_value);
4076
4076
    if (null_value)
4077
4077
      return set_field_to_null_with_conversions(field, no_conversions);
4078
4078
    field->set_notnull();
4110
4110
}
4111
4111
 
4112
4112
 
4113
 
longlong Item_func_get_user_var::val_int()
 
4113
int64_t Item_func_get_user_var::val_int()
4114
4114
{
4115
4115
  assert(fixed == 1);
4116
4116
  if (!var_entry)
4385
4385
}
4386
4386
 
4387
4387
 
4388
 
longlong Item_user_var_as_out_param::val_int()
 
4388
int64_t Item_user_var_as_out_param::val_int()
4389
4389
{
4390
4390
  assert(0);
4391
4391
  return 0;
4449
4449
  return var->is_written_to_binlog(var_type);
4450
4450
}
4451
4451
 
4452
 
longlong Item_func_bit_xor::val_int()
 
4452
int64_t Item_func_bit_xor::val_int()
4453
4453
{
4454
4454
  assert(fixed == 1);
4455
4455
  uint64_t arg1= (uint64_t) args[0]->val_int();
4456
4456
  uint64_t arg2= (uint64_t) args[1]->val_int();
4457
4457
  if ((null_value= (args[0]->null_value || args[1]->null_value)))
4458
4458
    return 0;
4459
 
  return (longlong) (arg1 ^ arg2);
 
4459
  return (int64_t) (arg1 ^ arg2);
4460
4460
}
4461
4461
 
4462
4462
 
4527
4527
    0           Already taken, or error
4528
4528
*/
4529
4529
 
4530
 
longlong Item_func_is_free_lock::val_int()
 
4530
int64_t Item_func_is_free_lock::val_int()
4531
4531
{
4532
4532
  assert(fixed == 1);
4533
4533
  String *res=args[0]->val_str(&value);
4549
4549
  return 0;
4550
4550
}
4551
4551
 
4552
 
longlong Item_func_is_used_lock::val_int()
 
4552
int64_t Item_func_is_used_lock::val_int()
4553
4553
{
4554
4554
  assert(fixed == 1);
4555
4555
  String *res=args[0]->val_str(&value);
4571
4571
}
4572
4572
 
4573
4573
 
4574
 
longlong Item_func_row_count::val_int()
 
4574
int64_t Item_func_row_count::val_int()
4575
4575
{
4576
4576
  assert(fixed == 1);
4577
4577
  THD *thd= current_thd;
4579
4579
  return thd->row_count_func;
4580
4580
}
4581
4581
 
4582
 
longlong Item_func_found_rows::val_int()
 
4582
int64_t Item_func_found_rows::val_int()
4583
4583
{
4584
4584
  assert(fixed == 1);
4585
4585
  THD *thd= current_thd;