~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_func.cc

Removed/replaced DBUG symbols and fixed TRUE/FALSEs

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
bool
141
141
Item_func::fix_fields(THD *thd, Item **ref __attribute__((__unused__)))
142
142
{
143
 
  DBUG_ASSERT(fixed == 0);
 
143
  assert(fixed == 0);
144
144
  Item **arg,**arg_end;
145
145
  void *save_thd_marker= thd->thd_marker;
146
146
  uchar buff[STACK_BUFF_ALLOC];                 // Max argument in function
171
171
      else
172
172
      {
173
173
        /*  we have to fetch allowed_arg_cols from first argument */
174
 
        DBUG_ASSERT(arg == args); // it is first argument
 
174
        assert(arg == args); // it is first argument
175
175
        allowed_arg_cols= item->cols();
176
 
        DBUG_ASSERT(allowed_arg_cols); // Can't be 0 any more
 
176
        assert(allowed_arg_cols); // Can't be 0 any more
177
177
      }
178
178
 
179
179
      if (item->maybe_null)
472
472
  case ROW_RESULT:
473
473
  default:
474
474
    // This case should never be chosen
475
 
    DBUG_ASSERT(0);
 
475
    assert(0);
476
476
    field= 0;
477
477
    break;
478
478
  }
484
484
 
485
485
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
486
486
{
487
 
  DBUG_ASSERT(fixed);
 
487
  assert(fixed);
488
488
  int2my_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
489
489
  return decimal_value;
490
490
}
492
492
 
493
493
String *Item_real_func::val_str(String *str)
494
494
{
495
 
  DBUG_ASSERT(fixed == 1);
 
495
  assert(fixed == 1);
496
496
  double nr= val_real();
497
497
  if (null_value)
498
498
    return 0; /* purecov: inspected */
503
503
 
504
504
my_decimal *Item_real_func::val_decimal(my_decimal *decimal_value)
505
505
{
506
 
  DBUG_ASSERT(fixed);
 
506
  assert(fixed);
507
507
  double nr= val_real();
508
508
  if (null_value)
509
509
    return 0; /* purecov: inspected */
623
623
 
624
624
double Item_int_func::val_real()
625
625
{
626
 
  DBUG_ASSERT(fixed == 1);
 
626
  assert(fixed == 1);
627
627
 
628
628
  return unsigned_flag ? (double) ((ulonglong) val_int()) : (double) val_int();
629
629
}
631
631
 
632
632
String *Item_int_func::val_str(String *str)
633
633
{
634
 
  DBUG_ASSERT(fixed == 1);
 
634
  assert(fixed == 1);
635
635
  longlong nr=val_int();
636
636
  if (null_value)
637
637
    return 0;
664
664
 
665
665
void Item_num_op::find_num_type(void)
666
666
{
667
 
  DBUG_ENTER("Item_num_op::find_num_type");
668
 
  DBUG_PRINT("info", ("name %s", func_name()));
669
 
  DBUG_ASSERT(arg_count == 2);
 
667
  assert(arg_count == 2);
670
668
  Item_result r0= args[0]->result_type();
671
669
  Item_result r1= args[1]->result_type();
672
670
 
684
682
  }
685
683
  else
686
684
  {
687
 
    DBUG_ASSERT(r0 == INT_RESULT && r1 == INT_RESULT);
 
685
    assert(r0 == INT_RESULT && r1 == INT_RESULT);
688
686
    decimals= 0;
689
687
    hybrid_type=INT_RESULT;
690
688
    result_precision();
691
689
  }
692
 
  DBUG_PRINT("info", ("Type: %s",
693
 
             (hybrid_type == REAL_RESULT ? "REAL_RESULT" :
694
 
              hybrid_type == DECIMAL_RESULT ? "DECIMAL_RESULT" :
695
 
              hybrid_type == INT_RESULT ? "INT_RESULT" :
696
 
              "--ILLEGAL!!!--")));
697
 
  DBUG_VOID_RETURN;
 
690
  return;
698
691
}
699
692
 
700
693
 
706
699
 
707
700
void Item_func_num1::find_num_type()
708
701
{
709
 
  DBUG_ENTER("Item_func_num1::find_num_type");
710
 
  DBUG_PRINT("info", ("name %s", func_name()));
711
702
  switch (hybrid_type= args[0]->result_type()) {
712
703
  case INT_RESULT:
713
704
    unsigned_flag= args[0]->unsigned_flag;
720
711
  case DECIMAL_RESULT:
721
712
    break;
722
713
  default:
723
 
    DBUG_ASSERT(0);
 
714
    assert(0);
724
715
  }
725
 
  DBUG_PRINT("info", ("Type: %s",
726
 
                      (hybrid_type == REAL_RESULT ? "REAL_RESULT" :
727
 
                       hybrid_type == DECIMAL_RESULT ? "DECIMAL_RESULT" :
728
 
                       hybrid_type == INT_RESULT ? "INT_RESULT" :
729
 
                       "--ILLEGAL!!!--")));
730
 
  DBUG_VOID_RETURN;
 
716
  return;
731
717
}
732
718
 
733
719
 
747
733
 
748
734
String *Item_func_numhybrid::val_str(String *str)
749
735
{
750
 
  DBUG_ASSERT(fixed == 1);
 
736
  assert(fixed == 1);
751
737
  switch (hybrid_type) {
752
738
  case DECIMAL_RESULT:
753
739
  {
777
763
  case STRING_RESULT:
778
764
    return str_op(&str_value);
779
765
  default:
780
 
    DBUG_ASSERT(0);
 
766
    assert(0);
781
767
  }
782
768
  return str;
783
769
}
785
771
 
786
772
double Item_func_numhybrid::val_real()
787
773
{
788
 
  DBUG_ASSERT(fixed == 1);
 
774
  assert(fixed == 1);
789
775
  switch (hybrid_type) {
790
776
  case DECIMAL_RESULT:
791
777
  {
812
798
                             &end_not_used, &err_not_used) : 0.0);
813
799
  }
814
800
  default:
815
 
    DBUG_ASSERT(0);
 
801
    assert(0);
816
802
  }
817
803
  return 0.0;
818
804
}
820
806
 
821
807
longlong Item_func_numhybrid::val_int()
822
808
{
823
 
  DBUG_ASSERT(fixed == 1);
 
809
  assert(fixed == 1);
824
810
  switch (hybrid_type) {
825
811
  case DECIMAL_RESULT:
826
812
  {
847
833
    return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
848
834
  }
849
835
  default:
850
 
    DBUG_ASSERT(0);
 
836
    assert(0);
851
837
  }
852
838
  return 0;
853
839
}
856
842
my_decimal *Item_func_numhybrid::val_decimal(my_decimal *decimal_value)
857
843
{
858
844
  my_decimal *val= decimal_value;
859
 
  DBUG_ASSERT(fixed == 1);
 
845
  assert(fixed == 1);
860
846
  switch (hybrid_type) {
861
847
  case DECIMAL_RESULT:
862
848
    val= decimal_op(decimal_value);
885
871
  }  
886
872
  case ROW_RESULT:
887
873
  default:
888
 
    DBUG_ASSERT(0);
 
874
    assert(0);
889
875
  }
890
876
  return val;
891
877
}
1214
1200
 
1215
1201
double Item_func_mul::real_op()
1216
1202
{
1217
 
  DBUG_ASSERT(fixed == 1);
 
1203
  assert(fixed == 1);
1218
1204
  double value= args[0]->val_real() * args[1]->val_real();
1219
1205
  if ((null_value=args[0]->null_value || args[1]->null_value))
1220
1206
    return 0.0;
1224
1210
 
1225
1211
longlong Item_func_mul::int_op()
1226
1212
{
1227
 
  DBUG_ASSERT(fixed == 1);
 
1213
  assert(fixed == 1);
1228
1214
  longlong value=args[0]->val_int()*args[1]->val_int();
1229
1215
  if ((null_value=args[0]->null_value || args[1]->null_value))
1230
1216
    return 0;
1266
1252
 
1267
1253
double Item_func_div::real_op()
1268
1254
{
1269
 
  DBUG_ASSERT(fixed == 1);
 
1255
  assert(fixed == 1);
1270
1256
  double value= args[0]->val_real();
1271
1257
  double val2= args[1]->val_real();
1272
1258
  if ((null_value= args[0]->null_value || args[1]->null_value))
1321
1307
 
1322
1308
void Item_func_div::fix_length_and_dec()
1323
1309
{
1324
 
  DBUG_ENTER("Item_func_div::fix_length_and_dec");
1325
1310
  prec_increment= current_thd->variables.div_precincrement;
1326
1311
  Item_num_op::fix_length_and_dec();
1327
1312
  switch(hybrid_type) {
1336
1321
  }
1337
1322
  case INT_RESULT:
1338
1323
    hybrid_type= DECIMAL_RESULT;
1339
 
    DBUG_PRINT("info", ("Type changed: DECIMAL_RESULT"));
1340
1324
    result_precision();
1341
1325
    break;
1342
1326
  case DECIMAL_RESULT:
1343
1327
    result_precision();
1344
1328
    break;
1345
1329
  default:
1346
 
    DBUG_ASSERT(0);
 
1330
    assert(0);
1347
1331
  }
1348
1332
  maybe_null= 1; // devision by zero
1349
 
  DBUG_VOID_RETURN;
 
1333
  return;
1350
1334
}
1351
1335
 
1352
1336
 
1353
1337
/* Integer division */
1354
1338
longlong Item_func_int_div::val_int()
1355
1339
{
1356
 
  DBUG_ASSERT(fixed == 1);
 
1340
  assert(fixed == 1);
1357
1341
  longlong value=args[0]->val_int();
1358
1342
  longlong val2=args[1]->val_int();
1359
1343
  if ((null_value= (args[0]->null_value || args[1]->null_value)))
1383
1367
 
1384
1368
longlong Item_func_mod::int_op()
1385
1369
{
1386
 
  DBUG_ASSERT(fixed == 1);
 
1370
  assert(fixed == 1);
1387
1371
  longlong value=  args[0]->val_int();
1388
1372
  longlong val2= args[1]->val_int();
1389
1373
  longlong result;
1408
1392
 
1409
1393
double Item_func_mod::real_op()
1410
1394
{
1411
 
  DBUG_ASSERT(fixed == 1);
 
1395
  assert(fixed == 1);
1412
1396
  double value= args[0]->val_real();
1413
1397
  double val2=  args[1]->val_real();
1414
1398
  if ((null_value= args[0]->null_value || args[1]->null_value))
1501
1485
 
1502
1486
void Item_func_neg::fix_length_and_dec()
1503
1487
{
1504
 
  DBUG_ENTER("Item_func_neg::fix_length_and_dec");
1505
1488
  Item_func_num1::fix_length_and_dec();
1506
1489
 
1507
1490
  /*
1522
1505
        the negated number
1523
1506
      */
1524
1507
      hybrid_type= DECIMAL_RESULT;
1525
 
      DBUG_PRINT("info", ("Type changed: DECIMAL_RESULT"));
1526
1508
    }
1527
1509
  }
1528
1510
  unsigned_flag= 0;
1529
 
  DBUG_VOID_RETURN;
 
1511
  return;
1530
1512
}
1531
1513
 
1532
1514
 
1571
1553
/** Gateway to natural LOG function. */
1572
1554
double Item_func_ln::val_real()
1573
1555
{
1574
 
  DBUG_ASSERT(fixed == 1);
 
1556
  assert(fixed == 1);
1575
1557
  double value= args[0]->val_real();
1576
1558
  if ((null_value= args[0]->null_value))
1577
1559
    return 0.0;
1591
1573
*/ 
1592
1574
double Item_func_log::val_real()
1593
1575
{
1594
 
  DBUG_ASSERT(fixed == 1);
 
1576
  assert(fixed == 1);
1595
1577
  double value= args[0]->val_real();
1596
1578
  if ((null_value= args[0]->null_value))
1597
1579
    return 0.0;
1617
1599
 
1618
1600
double Item_func_log2::val_real()
1619
1601
{
1620
 
  DBUG_ASSERT(fixed == 1);
 
1602
  assert(fixed == 1);
1621
1603
  double value= args[0]->val_real();
1622
1604
 
1623
1605
  if ((null_value=args[0]->null_value))
1632
1614
 
1633
1615
double Item_func_log10::val_real()
1634
1616
{
1635
 
  DBUG_ASSERT(fixed == 1);
 
1617
  assert(fixed == 1);
1636
1618
  double value= args[0]->val_real();
1637
1619
  if ((null_value= args[0]->null_value))
1638
1620
    return 0.0;
1646
1628
 
1647
1629
double Item_func_exp::val_real()
1648
1630
{
1649
 
  DBUG_ASSERT(fixed == 1);
 
1631
  assert(fixed == 1);
1650
1632
  double value= args[0]->val_real();
1651
1633
  if ((null_value=args[0]->null_value))
1652
1634
    return 0.0; /* purecov: inspected */
1655
1637
 
1656
1638
double Item_func_sqrt::val_real()
1657
1639
{
1658
 
  DBUG_ASSERT(fixed == 1);
 
1640
  assert(fixed == 1);
1659
1641
  double value= args[0]->val_real();
1660
1642
  if ((null_value=(args[0]->null_value || value < 0)))
1661
1643
    return 0.0; /* purecov: inspected */
1664
1646
 
1665
1647
double Item_func_pow::val_real()
1666
1648
{
1667
 
  DBUG_ASSERT(fixed == 1);
 
1649
  assert(fixed == 1);
1668
1650
  double value= args[0]->val_real();
1669
1651
  double val2= args[1]->val_real();
1670
1652
  if ((null_value=(args[0]->null_value || args[1]->null_value)))
1676
1658
 
1677
1659
double Item_func_acos::val_real()
1678
1660
{
1679
 
  DBUG_ASSERT(fixed == 1);
 
1661
  assert(fixed == 1);
1680
1662
  // the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug)
1681
1663
  volatile double value= args[0]->val_real();
1682
1664
  if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0))))
1686
1668
 
1687
1669
double Item_func_asin::val_real()
1688
1670
{
1689
 
  DBUG_ASSERT(fixed == 1);
 
1671
  assert(fixed == 1);
1690
1672
  // the volatile's for BUG #2338 to calm optimizer down (because of gcc's bug)
1691
1673
  volatile double value= args[0]->val_real();
1692
1674
  if ((null_value=(args[0]->null_value || (value < -1.0 || value > 1.0))))
1696
1678
 
1697
1679
double Item_func_atan::val_real()
1698
1680
{
1699
 
  DBUG_ASSERT(fixed == 1);
 
1681
  assert(fixed == 1);
1700
1682
  double value= args[0]->val_real();
1701
1683
  if ((null_value=args[0]->null_value))
1702
1684
    return 0.0;
1712
1694
 
1713
1695
double Item_func_cos::val_real()
1714
1696
{
1715
 
  DBUG_ASSERT(fixed == 1);
 
1697
  assert(fixed == 1);
1716
1698
  double value= args[0]->val_real();
1717
1699
  if ((null_value=args[0]->null_value))
1718
1700
    return 0.0;
1721
1703
 
1722
1704
double Item_func_sin::val_real()
1723
1705
{
1724
 
  DBUG_ASSERT(fixed == 1);
 
1706
  assert(fixed == 1);
1725
1707
  double value= args[0]->val_real();
1726
1708
  if ((null_value=args[0]->null_value))
1727
1709
    return 0.0;
1730
1712
 
1731
1713
double Item_func_tan::val_real()
1732
1714
{
1733
 
  DBUG_ASSERT(fixed == 1);
 
1715
  assert(fixed == 1);
1734
1716
  double value= args[0]->val_real();
1735
1717
  if ((null_value=args[0]->null_value))
1736
1718
    return 0.0;
1743
1725
 
1744
1726
longlong Item_func_shift_left::val_int()
1745
1727
{
1746
 
  DBUG_ASSERT(fixed == 1);
 
1728
  assert(fixed == 1);
1747
1729
  uint shift;
1748
1730
  ulonglong res= ((ulonglong) args[0]->val_int() <<
1749
1731
                  (shift=(uint) args[1]->val_int()));
1758
1740
 
1759
1741
longlong Item_func_shift_right::val_int()
1760
1742
{
1761
 
  DBUG_ASSERT(fixed == 1);
 
1743
  assert(fixed == 1);
1762
1744
  uint shift;
1763
1745
  ulonglong res= (ulonglong) args[0]->val_int() >>
1764
1746
    (shift=(uint) args[1]->val_int());
1774
1756
 
1775
1757
longlong Item_func_bit_neg::val_int()
1776
1758
{
1777
 
  DBUG_ASSERT(fixed == 1);
 
1759
  assert(fixed == 1);
1778
1760
  ulonglong res= (ulonglong) args[0]->val_int();
1779
1761
  if ((null_value=args[0]->null_value))
1780
1762
    return 0;
1805
1787
 
1806
1788
void Item_func_int_val::find_num_type()
1807
1789
{
1808
 
  DBUG_ENTER("Item_func_int_val::find_num_type");
1809
 
  DBUG_PRINT("info", ("name %s", func_name()));
1810
1790
  switch(hybrid_type= args[0]->result_type())
1811
1791
  {
1812
1792
  case STRING_RESULT:
1832
1812
    }
1833
1813
    break;
1834
1814
  default:
1835
 
    DBUG_ASSERT(0);
 
1815
    assert(0);
1836
1816
  }
1837
 
  DBUG_PRINT("info", ("Type: %s",
1838
 
                      (hybrid_type == REAL_RESULT ? "REAL_RESULT" :
1839
 
                       hybrid_type == DECIMAL_RESULT ? "DECIMAL_RESULT" :
1840
 
                       hybrid_type == INT_RESULT ? "INT_RESULT" :
1841
 
                       "--ILLEGAL!!!--")));
1842
 
 
1843
 
  DBUG_VOID_RETURN;
 
1817
  return;
1844
1818
}
1845
1819
 
1846
1820
 
2007
1981
    break;
2008
1982
  }
2009
1983
  default:
2010
 
    DBUG_ASSERT(0); /* This result type isn't handled */
 
1984
    assert(0); /* This result type isn't handled */
2011
1985
  }
2012
1986
}
2013
1987
 
2177
2151
 
2178
2152
double Item_func_rand::val_real()
2179
2153
{
2180
 
  DBUG_ASSERT(fixed == 1);
 
2154
  assert(fixed == 1);
2181
2155
  if (arg_count && !args[0]->const_item())
2182
2156
    seed_random (args[0]);
2183
2157
  return my_rnd(rand);
2185
2159
 
2186
2160
longlong Item_func_sign::val_int()
2187
2161
{
2188
 
  DBUG_ASSERT(fixed == 1);
 
2162
  assert(fixed == 1);
2189
2163
  double value= args[0]->val_real();
2190
2164
  null_value=args[0]->null_value;
2191
2165
  return value < 0.0 ? -1 : (value > 0 ? 1 : 0);
2194
2168
 
2195
2169
double Item_func_units::val_real()
2196
2170
{
2197
 
  DBUG_ASSERT(fixed == 1);
 
2171
  assert(fixed == 1);
2198
2172
  double value= args[0]->val_real();
2199
2173
  if ((null_value=args[0]->null_value))
2200
2174
    return 0;
2290
2264
 
2291
2265
String *Item_func_min_max::val_str(String *str)
2292
2266
{
2293
 
  DBUG_ASSERT(fixed == 1);
 
2267
  assert(fixed == 1);
2294
2268
  if (compare_as_dates)
2295
2269
  {
2296
2270
    String *str_res;
2354
2328
  case ROW_RESULT:
2355
2329
  default:
2356
2330
    // This case should never be chosen
2357
 
    DBUG_ASSERT(0);
 
2331
    assert(0);
2358
2332
    return 0;
2359
2333
  }
2360
2334
  return 0;                                     // Keep compiler happy
2363
2337
 
2364
2338
double Item_func_min_max::val_real()
2365
2339
{
2366
 
  DBUG_ASSERT(fixed == 1);
 
2340
  assert(fixed == 1);
2367
2341
  double value=0.0;
2368
2342
  if (compare_as_dates)
2369
2343
  {
2390
2364
 
2391
2365
longlong Item_func_min_max::val_int()
2392
2366
{
2393
 
  DBUG_ASSERT(fixed == 1);
 
2367
  assert(fixed == 1);
2394
2368
  longlong value=0;
2395
2369
  if (compare_as_dates)
2396
2370
  {
2417
2391
 
2418
2392
my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
2419
2393
{
2420
 
  DBUG_ASSERT(fixed == 1);
 
2394
  assert(fixed == 1);
2421
2395
  my_decimal tmp_buf, *tmp, *res= NULL;
2422
2396
 
2423
2397
  if (compare_as_dates)
2458
2432
 
2459
2433
longlong Item_func_length::val_int()
2460
2434
{
2461
 
  DBUG_ASSERT(fixed == 1);
 
2435
  assert(fixed == 1);
2462
2436
  String *res=args[0]->val_str(&value);
2463
2437
  if (!res)
2464
2438
  {
2472
2446
 
2473
2447
longlong Item_func_char_length::val_int()
2474
2448
{
2475
 
  DBUG_ASSERT(fixed == 1);
 
2449
  assert(fixed == 1);
2476
2450
  String *res=args[0]->val_str(&value);
2477
2451
  if (!res)
2478
2452
  {
2486
2460
 
2487
2461
longlong Item_func_coercibility::val_int()
2488
2462
{
2489
 
  DBUG_ASSERT(fixed == 1);
 
2463
  assert(fixed == 1);
2490
2464
  null_value= 0;
2491
2465
  return (longlong) args[0]->collation.derivation;
2492
2466
}
2501
2475
 
2502
2476
longlong Item_func_locate::val_int()
2503
2477
{
2504
 
  DBUG_ASSERT(fixed == 1);
 
2478
  assert(fixed == 1);
2505
2479
  String *a=args[0]->val_str(&value1);
2506
2480
  String *b=args[1]->val_str(&value2);
2507
2481
  if (!a || !b)
2559
2533
 
2560
2534
longlong Item_func_field::val_int()
2561
2535
{
2562
 
  DBUG_ASSERT(fixed == 1);
 
2536
  assert(fixed == 1);
2563
2537
 
2564
2538
  if (cmp_type == STRING_RESULT)
2565
2539
  {
2625
2599
 
2626
2600
longlong Item_func_ascii::val_int()
2627
2601
{
2628
 
  DBUG_ASSERT(fixed == 1);
 
2602
  assert(fixed == 1);
2629
2603
  String *res=args[0]->val_str(&value);
2630
2604
  if (!res)
2631
2605
  {
2638
2612
 
2639
2613
longlong Item_func_ord::val_int()
2640
2614
{
2641
 
  DBUG_ASSERT(fixed == 1);
 
2615
  assert(fixed == 1);
2642
2616
  String *res=args[0]->val_str(&value);
2643
2617
  if (!res)
2644
2618
  {
2693
2667
 
2694
2668
longlong Item_func_find_in_set::val_int()
2695
2669
{
2696
 
  DBUG_ASSERT(fixed == 1);
 
2670
  assert(fixed == 1);
2697
2671
  if (enum_value)
2698
2672
  {
2699
2673
    ulonglong tmp=(ulonglong) args[1]->val_int();
2761
2735
 
2762
2736
longlong Item_func_bit_count::val_int()
2763
2737
{
2764
 
  DBUG_ASSERT(fixed == 1);
 
2738
  assert(fixed == 1);
2765
2739
  ulonglong value= (ulonglong) args[0]->val_int();
2766
2740
  if ((null_value= args[0]->null_value))
2767
2741
    return 0; /* purecov: inspected */
2803
2777
                        uint arg_count, Item **arguments)
2804
2778
{
2805
2779
  uchar buff[STACK_BUFF_ALLOC];                 // Max argument in function
2806
 
  DBUG_ENTER("Item_udf_func::fix_fields");
2807
2780
 
2808
2781
  if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
2809
 
    DBUG_RETURN(true);                          // Fatal error flag is set!
 
2782
    return(true);                               // Fatal error flag is set!
2810
2783
 
2811
2784
  udf_func *tmp_udf=find_udf(u_d->name.str,(uint) u_d->name.length,1);
2812
2785
 
2813
2786
  if (!tmp_udf)
2814
2787
  {
2815
2788
    my_error(ER_CANT_FIND_UDF, MYF(0), u_d->name.str, errno);
2816
 
    DBUG_RETURN(true);
 
2789
    return(true);
2817
2790
  }
2818
2791
  u_d=tmp_udf;
2819
2792
  args=arguments;
2830
2803
 
2831
2804
    {
2832
2805
      free_udf(u_d);
2833
 
      DBUG_RETURN(true);
 
2806
      return(true);
2834
2807
    }
2835
2808
    uint i;
2836
2809
    Item **arg,**arg_end;
2840
2813
    {
2841
2814
      if (!(*arg)->fixed &&
2842
2815
          (*arg)->fix_fields(thd, arg))
2843
 
        DBUG_RETURN(1);
 
2816
        return(1);
2844
2817
      // we can't assign 'item' before, because fix_fields() can change arg
2845
2818
      Item *item= *arg;
2846
2819
      if (item->check_cols(1))
2847
 
        DBUG_RETURN(true);
 
2820
        return(true);
2848
2821
      /*
2849
2822
        TODO: We should think about this. It is not always
2850
2823
        right way just to set an UDF result to return my_charset_bin
2877
2850
                                                       sizeof(long))))
2878
2851
    {
2879
2852
      free_udf(u_d);
2880
 
      DBUG_RETURN(true);
 
2853
      return(true);
2881
2854
    }
2882
2855
  }
2883
2856
  func->fix_length_and_dec();
2935
2908
        case ROW_RESULT:
2936
2909
        default:
2937
2910
          // This case should never be chosen
2938
 
          DBUG_ASSERT(0);
 
2911
          assert(0);
2939
2912
          break;
2940
2913
        }
2941
2914
      }
2946
2919
      my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
2947
2920
               u_d->name.str, init_msg_buff);
2948
2921
      free_udf(u_d);
2949
 
      DBUG_RETURN(true);
 
2922
      return(true);
2950
2923
    }
2951
2924
    func->max_length=min(initid.max_length,MAX_BLOB_WIDTH);
2952
2925
    func->maybe_null=initid.maybe_null;
2964
2937
  {
2965
2938
    my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
2966
2939
             u_d->name.str, ER(ER_UNKNOWN_ERROR));
2967
 
    DBUG_RETURN(true);
 
2940
    return(true);
2968
2941
  }
2969
 
  DBUG_RETURN(false);
 
2942
  return(false);
2970
2943
}
2971
2944
 
2972
2945
 
3010
2983
    case ROW_RESULT:
3011
2984
    default:
3012
2985
      // This case should never be chosen
3013
 
      DBUG_ASSERT(0);
 
2986
      assert(0);
3014
2987
      break;
3015
2988
    }
3016
2989
  }
3025
2998
{
3026
2999
  uchar is_null_tmp=0;
3027
3000
  ulong res_length;
3028
 
  DBUG_ENTER("udf_handler::val_str");
3029
3001
 
3030
3002
  if (get_arguments())
3031
 
    DBUG_RETURN(0);
 
3003
    return(0);
3032
3004
  char * (*func)(UDF_INIT *, UDF_ARGS *, char *, ulong *, uchar *, uchar *)=
3033
3005
    (char* (*)(UDF_INIT *, UDF_ARGS *, char *, ulong *, uchar *, uchar *))
3034
3006
    u_d->func;
3038
3010
    if (str->alloc(MAX_FIELD_WIDTH))
3039
3011
    {
3040
3012
      error=1;
3041
 
      DBUG_RETURN(0);
 
3013
      return(0);
3042
3014
    }
3043
3015
  }
3044
3016
  char *res=func(&initid, &f_args, (char*) str->ptr(), &res_length,
3045
3017
                 &is_null_tmp, &error);
3046
 
  DBUG_PRINT("info", ("udf func returned, res_length: %lu", res_length));
3047
3018
  if (is_null_tmp || !res || error)             // The !res is for safety
3048
3019
  {
3049
 
    DBUG_PRINT("info", ("Null or error"));
3050
 
    DBUG_RETURN(0);
 
3020
    return(0);
3051
3021
  }
3052
3022
  if (res == str->ptr())
3053
3023
  {
3054
3024
    str->length(res_length);
3055
 
    DBUG_PRINT("exit", ("str: %s", str->ptr()));
3056
 
    DBUG_RETURN(str);
 
3025
    return(str);
3057
3026
  }
3058
3027
  save_str->set(res, res_length, str->charset());
3059
 
  DBUG_PRINT("exit", ("save_str: %s", save_str->ptr()));
3060
 
  DBUG_RETURN(save_str);
 
3028
  return(save_str);
3061
3029
}
3062
3030
 
3063
3031
 
3114
3082
 
3115
3083
double Item_func_udf_float::val_real()
3116
3084
{
3117
 
  DBUG_ASSERT(fixed == 1);
3118
 
  DBUG_ENTER("Item_func_udf_float::val");
3119
 
  DBUG_PRINT("info",("result_type: %d  arg_count: %d",
3120
 
                     args[0]->result_type(), arg_count));
3121
 
  DBUG_RETURN(udf.val(&null_value));
 
3085
  assert(fixed == 1);
 
3086
  return(udf.val(&null_value));
3122
3087
}
3123
3088
 
3124
3089
 
3125
3090
String *Item_func_udf_float::val_str(String *str)
3126
3091
{
3127
 
  DBUG_ASSERT(fixed == 1);
 
3092
  assert(fixed == 1);
3128
3093
  double nr= val_real();
3129
3094
  if (null_value)
3130
3095
    return 0;                                   /* purecov: inspected */
3135
3100
 
3136
3101
longlong Item_func_udf_int::val_int()
3137
3102
{
3138
 
  DBUG_ASSERT(fixed == 1);
3139
 
  DBUG_ENTER("Item_func_udf_int::val_int");
3140
 
  DBUG_RETURN(udf.val_int(&null_value));
 
3103
  assert(fixed == 1);
 
3104
  return(udf.val_int(&null_value));
3141
3105
}
3142
3106
 
3143
3107
 
3144
3108
String *Item_func_udf_int::val_str(String *str)
3145
3109
{
3146
 
  DBUG_ASSERT(fixed == 1);
 
3110
  assert(fixed == 1);
3147
3111
  longlong nr=val_int();
3148
3112
  if (null_value)
3149
3113
    return 0;
3176
3140
 
3177
3141
my_decimal *Item_func_udf_decimal::val_decimal(my_decimal *dec_buf)
3178
3142
{
3179
 
  DBUG_ASSERT(fixed == 1);
3180
 
  DBUG_ENTER("Item_func_udf_decimal::val_decimal");
3181
 
  DBUG_PRINT("info",("result_type: %d  arg_count: %d",
3182
 
                     args[0]->result_type(), arg_count));
3183
 
 
3184
 
  DBUG_RETURN(udf.val_decimal(&null_value, dec_buf));
 
3143
  assert(fixed == 1);
 
3144
  return(udf.val_decimal(&null_value, dec_buf));
3185
3145
}
3186
3146
 
3187
3147
 
3208
3168
 
3209
3169
void Item_func_udf_str::fix_length_and_dec()
3210
3170
{
3211
 
  DBUG_ENTER("Item_func_udf_str::fix_length_and_dec");
3212
3171
  max_length=0;
3213
3172
  for (uint i = 0; i < arg_count; i++)
3214
3173
    set_if_bigger(max_length,args[i]->max_length);
3215
 
  DBUG_VOID_RETURN;
 
3174
  return;
3216
3175
}
3217
3176
 
3218
3177
String *Item_func_udf_str::val_str(String *str)
3219
3178
{
3220
 
  DBUG_ASSERT(fixed == 1);
 
3179
  assert(fixed == 1);
3221
3180
  String *res=udf.val_str(str,&str_value);
3222
3181
  null_value = !res;
3223
3182
  return res;
3233
3192
udf_handler::~udf_handler()
3234
3193
{
3235
3194
  /* Everything should be properly cleaned up by this moment. */
3236
 
  DBUG_ASSERT(not_original || !(initialized || buffers));
 
3195
  assert(not_original || !(initialized || buffers));
3237
3196
}
3238
3197
 
3239
3198
#else
3333
3292
 
3334
3293
longlong Item_master_pos_wait::val_int()
3335
3294
{
3336
 
  DBUG_ASSERT(fixed == 1);
 
3295
  assert(fixed == 1);
3337
3296
  THD* thd = current_thd;
3338
3297
  String *log_name = args[0]->val_str(&value);
3339
3298
  int event_count= 0;
3367
3326
longlong Item_func_last_insert_id::val_int()
3368
3327
{
3369
3328
  THD *thd= current_thd;
3370
 
  DBUG_ASSERT(fixed == 1);
 
3329
  assert(fixed == 1);
3371
3330
  if (arg_count)
3372
3331
  {
3373
3332
    longlong value= args[0]->val_int();
3397
3356
 
3398
3357
longlong Item_func_benchmark::val_int()
3399
3358
{
3400
 
  DBUG_ASSERT(fixed == 1);
 
3359
  assert(fixed == 1);
3401
3360
  char buff[MAX_FIELD_WIDTH];
3402
3361
  String tmp(buff,sizeof(buff), &my_charset_bin);
3403
3362
  my_decimal tmp_decimal;
3441
3400
    case ROW_RESULT:
3442
3401
    default:
3443
3402
      // This case should never be chosen
3444
 
      DBUG_ASSERT(0);
 
3403
      assert(0);
3445
3404
      return 0;
3446
3405
    }
3447
3406
  }
3511
3470
 
3512
3471
bool Item_func_set_user_var::fix_fields(THD *thd, Item **ref)
3513
3472
{
3514
 
  DBUG_ASSERT(fixed == 0);
 
3473
  assert(fixed == 0);
3515
3474
  /* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
3516
3475
  if (Item_func::fix_fields(thd, ref) ||
3517
3476
      !(entry= get_variable(&thd->user_vars, name, 1)))
3699
3658
  case STRING_RESULT:
3700
3659
    return my_atof(value);                      // This is null terminated
3701
3660
  case ROW_RESULT:
3702
 
    DBUG_ASSERT(1);                             // Impossible
 
3661
    assert(1);                          // Impossible
3703
3662
    break;
3704
3663
  }
3705
3664
  return 0.0;                                   // Impossible
3730
3689
    return my_strtoll10(value, (char**) 0, &error);// String is null terminated
3731
3690
  }
3732
3691
  case ROW_RESULT:
3733
 
    DBUG_ASSERT(1);                             // Impossible
 
3692
    assert(1);                          // Impossible
3734
3693
    break;
3735
3694
  }
3736
3695
  return 0LL;                                   // Impossible
3762
3721
    if (str->copy(value, length, collation.collation))
3763
3722
      str= 0;                                   // EOM error
3764
3723
  case ROW_RESULT:
3765
 
    DBUG_ASSERT(1);                             // Impossible
 
3724
    assert(1);                          // Impossible
3766
3725
    break;
3767
3726
  }
3768
3727
  return(str);
3789
3748
    str2my_decimal(E_DEC_FATAL_ERROR, value, length, collation.collation, val);
3790
3749
    break;
3791
3750
  case ROW_RESULT:
3792
 
    DBUG_ASSERT(1);                             // Impossible
 
3751
    assert(1);                          // Impossible
3793
3752
    break;
3794
3753
  }
3795
3754
  return(val);
3812
3771
bool
3813
3772
Item_func_set_user_var::check(bool use_result_field)
3814
3773
{
3815
 
  DBUG_ENTER("Item_func_set_user_var::check");
3816
3774
  if (use_result_field && !result_field)
3817
3775
    use_result_field= false;
3818
3776
 
3847
3805
  case ROW_RESULT:
3848
3806
  default:
3849
3807
    // This case should never be chosen
3850
 
    DBUG_ASSERT(0);
 
3808
    assert(0);
3851
3809
    break;
3852
3810
  }
3853
 
  DBUG_RETURN(false);
 
3811
  return(false);
3854
3812
}
3855
3813
 
3856
3814
 
3873
3831
Item_func_set_user_var::update()
3874
3832
{
3875
3833
  bool res= false;
3876
 
  DBUG_ENTER("Item_func_set_user_var::update");
3877
3834
 
3878
3835
  switch (cached_result_type) {
3879
3836
  case REAL_RESULT:
3915
3872
  case ROW_RESULT:
3916
3873
  default:
3917
3874
    // This case should never be chosen
3918
 
    DBUG_ASSERT(0);
 
3875
    assert(0);
3919
3876
    break;
3920
3877
  }
3921
 
  DBUG_RETURN(res);
 
3878
  return(res);
3922
3879
}
3923
3880
 
3924
3881
 
3925
3882
double Item_func_set_user_var::val_real()
3926
3883
{
3927
 
  DBUG_ASSERT(fixed == 1);
 
3884
  assert(fixed == 1);
3928
3885
  check(0);
3929
3886
  update();                                     // Store expression
3930
3887
  return entry->val_real(&null_value);
3932
3889
 
3933
3890
longlong Item_func_set_user_var::val_int()
3934
3891
{
3935
 
  DBUG_ASSERT(fixed == 1);
 
3892
  assert(fixed == 1);
3936
3893
  check(0);
3937
3894
  update();                                     // Store expression
3938
3895
  return entry->val_int(&null_value);
3940
3897
 
3941
3898
String *Item_func_set_user_var::val_str(String *str)
3942
3899
{
3943
 
  DBUG_ASSERT(fixed == 1);
 
3900
  assert(fixed == 1);
3944
3901
  check(0);
3945
3902
  update();                                     // Store expression
3946
3903
  return entry->val_str(&null_value, str, decimals);
3949
3906
 
3950
3907
my_decimal *Item_func_set_user_var::val_decimal(my_decimal *val)
3951
3908
{
3952
 
  DBUG_ASSERT(fixed == 1);
 
3909
  assert(fixed == 1);
3953
3910
  check(0);
3954
3911
  update();                                     // Store expression
3955
3912
  return entry->val_decimal(&null_value, val);
3958
3915
 
3959
3916
double Item_func_set_user_var::val_result()
3960
3917
{
3961
 
  DBUG_ASSERT(fixed == 1);
 
3918
  assert(fixed == 1);
3962
3919
  check(true);
3963
3920
  update();                                     // Store expression
3964
3921
  return entry->val_real(&null_value);
3966
3923
 
3967
3924
longlong Item_func_set_user_var::val_int_result()
3968
3925
{
3969
 
  DBUG_ASSERT(fixed == 1);
 
3926
  assert(fixed == 1);
3970
3927
  check(true);
3971
3928
  update();                                     // Store expression
3972
3929
  return entry->val_int(&null_value);
3974
3931
 
3975
3932
String *Item_func_set_user_var::str_result(String *str)
3976
3933
{
3977
 
  DBUG_ASSERT(fixed == 1);
 
3934
  assert(fixed == 1);
3978
3935
  check(true);
3979
3936
  update();                                     // Store expression
3980
3937
  return entry->val_str(&null_value, str, decimals);
3983
3940
 
3984
3941
my_decimal *Item_func_set_user_var::val_decimal_result(my_decimal *val)
3985
3942
{
3986
 
  DBUG_ASSERT(fixed == 1);
 
3943
  assert(fixed == 1);
3987
3944
  check(true);
3988
3945
  update();                                     // Store expression
3989
3946
  return entry->val_decimal(&null_value, val);
4026
3983
  if (result_field)
4027
3984
  {
4028
3985
    result_field->make_field(tmp_field);
4029
 
    DBUG_ASSERT(tmp_field->table_name != 0);
 
3986
    assert(tmp_field->table_name != 0);
4030
3987
    if (Item::name)
4031
3988
      tmp_field->col_name=Item::name;               // Use user supplied name
4032
3989
  }
4137
4094
String *
4138
4095
Item_func_get_user_var::val_str(String *str)
4139
4096
{
4140
 
  DBUG_ASSERT(fixed == 1);
4141
 
  DBUG_ENTER("Item_func_get_user_var::val_str");
 
4097
  assert(fixed == 1);
4142
4098
  if (!var_entry)
4143
 
    DBUG_RETURN((String*) 0);                   // No such variable
4144
 
  DBUG_RETURN(var_entry->val_str(&null_value, str, decimals));
 
4099
    return((String*) 0);                        // No such variable
 
4100
  return(var_entry->val_str(&null_value, str, decimals));
4145
4101
}
4146
4102
 
4147
4103
 
4148
4104
double Item_func_get_user_var::val_real()
4149
4105
{
4150
 
  DBUG_ASSERT(fixed == 1);
 
4106
  assert(fixed == 1);
4151
4107
  if (!var_entry)
4152
4108
    return 0.0;                                 // No such variable
4153
4109
  return (var_entry->val_real(&null_value));
4156
4112
 
4157
4113
my_decimal *Item_func_get_user_var::val_decimal(my_decimal *dec)
4158
4114
{
4159
 
  DBUG_ASSERT(fixed == 1);
 
4115
  assert(fixed == 1);
4160
4116
  if (!var_entry)
4161
4117
    return 0;
4162
4118
  return var_entry->val_decimal(&null_value, dec);
4165
4121
 
4166
4122
longlong Item_func_get_user_var::val_int()
4167
4123
{
4168
 
  DBUG_ASSERT(fixed == 1);
 
4124
  assert(fixed == 1);
4169
4125
  if (!var_entry)
4170
4126
    return 0LL;                         // No such variable
4171
4127
  return (var_entry->val_int(&null_value));
4347
4303
      break;
4348
4304
    case ROW_RESULT:                            // Keep compiler happy
4349
4305
    default:
4350
 
      DBUG_ASSERT(0);
 
4306
      assert(0);
4351
4307
      break;
4352
4308
    }
4353
4309
  }
4400
4356
 
4401
4357
bool Item_user_var_as_out_param::fix_fields(THD *thd, Item **ref)
4402
4358
{
4403
 
  DBUG_ASSERT(fixed == 0);
 
4359
  assert(fixed == 0);
4404
4360
  if (Item::fix_fields(thd, ref) ||
4405
4361
      !(entry= get_variable(&thd->user_vars, name, 1)))
4406
4362
    return true;
4433
4389
 
4434
4390
double Item_user_var_as_out_param::val_real()
4435
4391
{
4436
 
  DBUG_ASSERT(0);
 
4392
  assert(0);
4437
4393
  return 0.0;
4438
4394
}
4439
4395
 
4440
4396
 
4441
4397
longlong Item_user_var_as_out_param::val_int()
4442
4398
{
4443
 
  DBUG_ASSERT(0);
 
4399
  assert(0);
4444
4400
  return 0;
4445
4401
}
4446
4402
 
4447
4403
 
4448
4404
String* Item_user_var_as_out_param::val_str(String *str __attribute__((__unused__)))
4449
4405
{
4450
 
  DBUG_ASSERT(0);
 
4406
  assert(0);
4451
4407
  return 0;
4452
4408
}
4453
4409
 
4454
4410
 
4455
4411
my_decimal* Item_user_var_as_out_param::val_decimal(my_decimal *decimal_buffer __attribute__((__unused__)))
4456
4412
{
4457
 
  DBUG_ASSERT(0);
 
4413
  assert(0);
4458
4414
  return 0;
4459
4415
}
4460
4416
 
4482
4438
Item_func_get_system_var::fix_fields(THD *thd, Item **ref)
4483
4439
{
4484
4440
  Item *item;
4485
 
  DBUG_ENTER("Item_func_get_system_var::fix_fields");
4486
4441
 
4487
4442
  /*
4488
4443
    Evaluate the system variable and substitute the result (a basic constant)
4490
4445
    the error is reported in sys_var::item().
4491
4446
  */
4492
4447
  if (!(item= var->item(thd, var_type, &component)))
4493
 
    DBUG_RETURN(1);                             // Impossible
 
4448
    return(1);                             // Impossible
4494
4449
  item->set_name(name, 0, system_charset_info); // don't allocate a new name
4495
4450
  thd->change_item_tree(ref, item);
4496
4451
 
4497
 
  DBUG_RETURN(0);
 
4452
  return(0);
4498
4453
}
4499
4454
 
4500
4455
 
4505
4460
 
4506
4461
longlong Item_func_bit_xor::val_int()
4507
4462
{
4508
 
  DBUG_ASSERT(fixed == 1);
 
4463
  assert(fixed == 1);
4509
4464
  ulonglong arg1= (ulonglong) args[0]->val_int();
4510
4465
  ulonglong arg2= (ulonglong) args[1]->val_int();
4511
4466
  if ((null_value= (args[0]->null_value || args[1]->null_value)))
4583
4538
 
4584
4539
longlong Item_func_is_free_lock::val_int()
4585
4540
{
4586
 
  DBUG_ASSERT(fixed == 1);
 
4541
  assert(fixed == 1);
4587
4542
  String *res=args[0]->val_str(&value);
4588
4543
  User_level_lock *ull;
4589
4544
 
4605
4560
 
4606
4561
longlong Item_func_is_used_lock::val_int()
4607
4562
{
4608
 
  DBUG_ASSERT(fixed == 1);
 
4563
  assert(fixed == 1);
4609
4564
  String *res=args[0]->val_str(&value);
4610
4565
  User_level_lock *ull;
4611
4566
 
4627
4582
 
4628
4583
longlong Item_func_row_count::val_int()
4629
4584
{
4630
 
  DBUG_ASSERT(fixed == 1);
 
4585
  assert(fixed == 1);
4631
4586
  THD *thd= current_thd;
4632
4587
 
4633
4588
  return thd->row_count_func;
4635
4590
 
4636
4591
longlong Item_func_found_rows::val_int()
4637
4592
{
4638
 
  DBUG_ASSERT(fixed == 1);
 
4593
  assert(fixed == 1);
4639
4594
  THD *thd= current_thd;
4640
4595
 
4641
4596
  return thd->found_rows();