~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_create.cc

  • Committer: Jay Pipes
  • Date: 2008-07-17 17:54:00 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080717175400-xm2aazihjra8mdzq
Removal of DBUG from libdrizzle/ - Round 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
  Functions to create an item. Used by sql_yac.yy
21
21
*/
22
22
 
23
 
#include <drizzled/server_includes.h>
 
23
#include "mysql_priv.h"
 
24
#include "item_create.h"
24
25
 
25
26
/*
26
27
=============================================================================
404
405
  virtual ~Create_func_cot() {}
405
406
};
406
407
 
 
408
 
 
409
class Create_func_crc32 : public Create_func_arg1
 
410
{
 
411
public:
 
412
  virtual Item *create(THD *thd, Item *arg1);
 
413
 
 
414
  static Create_func_crc32 s_singleton;
 
415
 
 
416
protected:
 
417
  Create_func_crc32() {}
 
418
  virtual ~Create_func_crc32() {}
 
419
};
 
420
 
 
421
 
407
422
class Create_func_date_format : public Create_func_arg2
408
423
{
409
424
public:
521
536
};
522
537
 
523
538
 
 
539
class Create_func_encode : public Create_func_arg2
 
540
{
 
541
public:
 
542
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
543
 
 
544
  static Create_func_encode s_singleton;
 
545
 
 
546
protected:
 
547
  Create_func_encode() {}
 
548
  virtual ~Create_func_encode() {}
 
549
};
 
550
 
 
551
 
 
552
class Create_func_encrypt : public Create_native_func
 
553
{
 
554
public:
 
555
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
556
 
 
557
  static Create_func_encrypt s_singleton;
 
558
 
 
559
protected:
 
560
  Create_func_encrypt() {}
 
561
  virtual ~Create_func_encrypt() {}
 
562
};
 
563
 
 
564
 
524
565
class Create_func_exp : public Create_func_arg1
525
566
{
526
567
public:
923
964
  virtual ~Create_func_master_pos_wait() {}
924
965
};
925
966
 
 
967
 
 
968
class Create_func_md5 : public Create_func_arg1
 
969
{
 
970
public:
 
971
  virtual Item *create(THD *thd, Item *arg1);
 
972
 
 
973
  static Create_func_md5 s_singleton;
 
974
 
 
975
protected:
 
976
  Create_func_md5() {}
 
977
  virtual ~Create_func_md5() {}
 
978
};
 
979
 
 
980
 
926
981
class Create_func_monthname : public Create_func_arg1
927
982
{
928
983
public:
1447
1502
}
1448
1503
 
1449
1504
 
 
1505
#ifdef HAVE_DLOPEN
1450
1506
Create_udf_func Create_udf_func::s_singleton;
1451
1507
 
1452
1508
Item*
1461
1517
Item*
1462
1518
Create_udf_func::create(THD *thd, udf_func *udf, List<Item> *item_list)
1463
1519
{
1464
 
  Item_func *func= NULL;
 
1520
  Item *func= NULL;
1465
1521
  int arg_count= 0;
1466
1522
 
1467
1523
  if (item_list != NULL)
1469
1525
 
1470
1526
  thd->lex->set_stmt_unsafe();
1471
1527
 
1472
 
  func= udf->create_func(thd->mem_root);
1473
 
 
1474
 
  func->set_arguments(*item_list);
1475
 
 
 
1528
  assert(   (udf->type == UDFTYPE_FUNCTION)
 
1529
              || (udf->type == UDFTYPE_AGGREGATE));
 
1530
 
 
1531
  switch(udf->returns) {
 
1532
  case STRING_RESULT:
 
1533
  {
 
1534
    if (udf->type == UDFTYPE_FUNCTION)
 
1535
    {
 
1536
      if (arg_count)
 
1537
        func= new (thd->mem_root) Item_func_udf_str(udf, *item_list);
 
1538
      else
 
1539
        func= new (thd->mem_root) Item_func_udf_str(udf);
 
1540
    }
 
1541
    else
 
1542
    {
 
1543
      if (arg_count)
 
1544
        func= new (thd->mem_root) Item_sum_udf_str(udf, *item_list);
 
1545
      else
 
1546
        func= new (thd->mem_root) Item_sum_udf_str(udf);
 
1547
    }
 
1548
    break;
 
1549
  }
 
1550
  case REAL_RESULT:
 
1551
  {
 
1552
    if (udf->type == UDFTYPE_FUNCTION)
 
1553
    {
 
1554
      if (arg_count)
 
1555
        func= new (thd->mem_root) Item_func_udf_float(udf, *item_list);
 
1556
      else
 
1557
        func= new (thd->mem_root) Item_func_udf_float(udf);
 
1558
    }
 
1559
    else
 
1560
    {
 
1561
      if (arg_count)
 
1562
        func= new (thd->mem_root) Item_sum_udf_float(udf, *item_list);
 
1563
      else
 
1564
        func= new (thd->mem_root) Item_sum_udf_float(udf);
 
1565
    }
 
1566
    break;
 
1567
  }
 
1568
  case INT_RESULT:
 
1569
  {
 
1570
    if (udf->type == UDFTYPE_FUNCTION)
 
1571
    {
 
1572
      if (arg_count)
 
1573
        func= new (thd->mem_root) Item_func_udf_int(udf, *item_list);
 
1574
      else
 
1575
        func= new (thd->mem_root) Item_func_udf_int(udf);
 
1576
    }
 
1577
    else
 
1578
    {
 
1579
      if (arg_count)
 
1580
        func= new (thd->mem_root) Item_sum_udf_int(udf, *item_list);
 
1581
      else
 
1582
        func= new (thd->mem_root) Item_sum_udf_int(udf);
 
1583
    }
 
1584
    break;
 
1585
  }
 
1586
  case DECIMAL_RESULT:
 
1587
  {
 
1588
    if (udf->type == UDFTYPE_FUNCTION)
 
1589
    {
 
1590
      if (arg_count)
 
1591
        func= new (thd->mem_root) Item_func_udf_decimal(udf, *item_list);
 
1592
      else
 
1593
        func= new (thd->mem_root) Item_func_udf_decimal(udf);
 
1594
    }
 
1595
    else
 
1596
    {
 
1597
      if (arg_count)
 
1598
        func= new (thd->mem_root) Item_sum_udf_decimal(udf, *item_list);
 
1599
      else
 
1600
        func= new (thd->mem_root) Item_sum_udf_decimal(udf);
 
1601
    }
 
1602
    break;
 
1603
  }
 
1604
  default:
 
1605
  {
 
1606
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "UDF return type");
 
1607
  }
 
1608
  }
1476
1609
  return func;
1477
1610
}
 
1611
#endif
1478
1612
 
1479
1613
 
1480
1614
Item*
1679
1813
Item*
1680
1814
Create_func_bin::create(THD *thd, Item *arg1)
1681
1815
{
1682
 
  Item *i10= new (thd->mem_root) Item_int((int32_t) 10,2);
1683
 
  Item *i2= new (thd->mem_root) Item_int((int32_t) 2,1);
 
1816
  Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
 
1817
  Item *i2= new (thd->mem_root) Item_int((int32) 2,1);
1684
1818
  return new (thd->mem_root) Item_func_conv(arg1, i10, i2);
1685
1819
}
1686
1820
 
1810
1944
  return new (thd->mem_root) Item_func_div(i1, i2);
1811
1945
}
1812
1946
 
 
1947
 
 
1948
Create_func_crc32 Create_func_crc32::s_singleton;
 
1949
 
 
1950
Item*
 
1951
Create_func_crc32::create(THD *thd, Item *arg1)
 
1952
{
 
1953
  return new (thd->mem_root) Item_func_crc32(arg1);
 
1954
}
 
1955
 
 
1956
 
1813
1957
Create_func_date_format Create_func_date_format::s_singleton;
1814
1958
 
1815
1959
Item*
1867
2011
}
1868
2012
 
1869
2013
 
 
2014
Create_func_decode Create_func_decode::s_singleton;
 
2015
 
 
2016
Item*
 
2017
Create_func_decode::create(THD *thd, Item *arg1, Item *arg2)
 
2018
{
 
2019
  return new (thd->mem_root) Item_func_decode(arg1, arg2);
 
2020
}
 
2021
 
 
2022
 
1870
2023
Create_func_degrees Create_func_degrees::s_singleton;
1871
2024
 
1872
2025
Item*
1898
2051
}
1899
2052
 
1900
2053
 
 
2054
Create_func_encode Create_func_encode::s_singleton;
 
2055
 
 
2056
Item*
 
2057
Create_func_encode::create(THD *thd, Item *arg1, Item *arg2)
 
2058
{
 
2059
  return new (thd->mem_root) Item_func_encode(arg1, arg2);
 
2060
}
 
2061
 
 
2062
 
 
2063
Create_func_encrypt Create_func_encrypt::s_singleton;
 
2064
 
 
2065
Item*
 
2066
Create_func_encrypt::create_native(THD *thd, LEX_STRING name,
 
2067
                                   List<Item> *item_list)
 
2068
{
 
2069
  Item *func= NULL;
 
2070
  int arg_count= 0;
 
2071
 
 
2072
  if (item_list != NULL)
 
2073
    arg_count= item_list->elements;
 
2074
 
 
2075
  switch (arg_count) {
 
2076
  case 1:
 
2077
  {
 
2078
    Item *param_1= item_list->pop();
 
2079
    func= new (thd->mem_root) Item_func_encrypt(param_1);
 
2080
    break;
 
2081
  }
 
2082
  case 2:
 
2083
  {
 
2084
    Item *param_1= item_list->pop();
 
2085
    Item *param_2= item_list->pop();
 
2086
    func= new (thd->mem_root) Item_func_encrypt(param_1, param_2);
 
2087
    break;
 
2088
  }
 
2089
  default:
 
2090
  {
 
2091
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2092
    break;
 
2093
  }
 
2094
  }
 
2095
 
 
2096
  return func;
 
2097
}
 
2098
 
 
2099
 
1901
2100
Create_func_exp Create_func_exp::s_singleton;
1902
2101
 
1903
2102
Item*
2417
2616
}
2418
2617
 
2419
2618
 
 
2619
Create_func_md5 Create_func_md5::s_singleton;
 
2620
 
 
2621
Item*
 
2622
Create_func_md5::create(THD *thd, Item *arg1)
 
2623
{
 
2624
  return new (thd->mem_root) Item_func_md5(arg1);
 
2625
}
 
2626
 
 
2627
 
2420
2628
Create_func_monthname Create_func_monthname::s_singleton;
2421
2629
 
2422
2630
Item*
2440
2648
Item*
2441
2649
Create_func_oct::create(THD *thd, Item *arg1)
2442
2650
{
2443
 
  Item *i10= new (thd->mem_root) Item_int((int32_t) 10,2);
2444
 
  Item *i8= new (thd->mem_root) Item_int((int32_t) 8,1);
 
2651
  Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
 
2652
  Item *i8= new (thd->mem_root) Item_int((int32) 8,1);
2445
2653
  return new (thd->mem_root) Item_func_conv(arg1, i10, i8);
2446
2654
}
2447
2655
 
2648
2856
    The parsed item tree should not depend on
2649
2857
    <code>thd->variables.collation_connection</code>.
2650
2858
  */
2651
 
  const CHARSET_INFO * const cs= thd->variables.collation_connection;
 
2859
  CHARSET_INFO *cs= thd->variables.collation_connection;
2652
2860
  Item *sp;
2653
2861
 
2654
2862
  if (cs->mbminlen > 1)
2655
2863
  {
2656
 
    uint32_t dummy_errors;
 
2864
    uint dummy_errors;
2657
2865
    sp= new (thd->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
2658
 
    sp->str_value.copy(" ", 1, &my_charset_utf8_general_ci, cs, &dummy_errors);
 
2866
    sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
2659
2867
  }
2660
2868
  else
2661
2869
  {
2927
3135
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
2928
3136
  { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
2929
3137
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
 
3138
  { { C_STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)},
2930
3139
  { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
2931
3140
  { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
2932
3141
  { { C_STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
2933
3142
  { { C_STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
2934
3143
  { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
2935
3144
  { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
 
3145
  { { C_STRING_WITH_LEN("DECODE") }, BUILDER(Create_func_decode)},
2936
3146
  { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
2937
3147
  { { C_STRING_WITH_LEN("ELT") }, BUILDER(Create_func_elt)},
 
3148
  { { C_STRING_WITH_LEN("ENCODE") }, BUILDER(Create_func_encode)},
 
3149
  { { C_STRING_WITH_LEN("ENCRYPT") }, BUILDER(Create_func_encrypt)},
2938
3150
  { { C_STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
2939
3151
  { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
2940
3152
  { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
2967
3179
  { { C_STRING_WITH_LEN("MAKETIME") }, BUILDER(Create_func_maketime)},
2968
3180
  { { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
2969
3181
  { { C_STRING_WITH_LEN("MASTER_POS_WAIT") }, BUILDER(Create_func_master_pos_wait)},
 
3182
  { { C_STRING_WITH_LEN("MD5") }, BUILDER(Create_func_md5)},
2970
3183
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
2971
3184
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
2972
3185
  { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
3013
3226
 
3014
3227
static HASH native_functions_hash;
3015
3228
 
3016
 
extern "C" unsigned char*
3017
 
get_native_fct_hash_key(const unsigned char *buff, size_t *length,
3018
 
                        bool /* unused */)
 
3229
extern "C" uchar*
 
3230
get_native_fct_hash_key(const uchar *buff, size_t *length,
 
3231
                        my_bool /* unused */)
3019
3232
{
3020
3233
  Native_func_registry *func= (Native_func_registry*) buff;
3021
3234
  *length= func->name.length;
3022
 
  return (unsigned char*) func->name.str;
 
3235
  return (uchar*) func->name.str;
3023
3236
}
3024
3237
 
3025
3238
/*
3044
3257
 
3045
3258
  for (func= func_array; func->builder != NULL; func++)
3046
3259
  {
3047
 
    if (my_hash_insert(& native_functions_hash, (unsigned char*) func))
 
3260
    if (my_hash_insert(& native_functions_hash, (uchar*) func))
3048
3261
      return(1);
3049
3262
  }
3050
3263
 
3064
3277
}
3065
3278
 
3066
3279
Create_func *
3067
 
find_native_function_builder(THD *thd __attribute__((unused)),
 
3280
find_native_function_builder(THD *thd __attribute__((__unused__)),
3068
3281
                             LEX_STRING name)
3069
3282
{
3070
3283
  Native_func_registry *func;
3072
3285
 
3073
3286
  /* Thread safe */
3074
3287
  func= (Native_func_registry*) hash_search(& native_functions_hash,
3075
 
                                            (unsigned char*) name.str,
 
3288
                                            (uchar*) name.str,
3076
3289
                                             name.length);
3077
3290
 
3078
3291
  if (func)
3085
3298
 
3086
3299
 
3087
3300
Item*
3088
 
create_func_char_cast(THD *thd, Item *a, int len, const CHARSET_INFO * const cs)
 
3301
create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs)
3089
3302
{
3090
 
  const CHARSET_INFO * const real_cs= (cs ? cs : thd->variables.collation_connection);
 
3303
  CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
3091
3304
  return new (thd->mem_root) Item_char_typecast(a, len, real_cs);
3092
3305
}
3093
3306
 
3095
3308
Item *
3096
3309
create_func_cast(THD *thd, Item *a, Cast_target cast_type,
3097
3310
                 const char *c_len, const char *c_dec,
3098
 
                 const CHARSET_INFO * const cs)
 
3311
                 CHARSET_INFO *cs)
3099
3312
{
3100
3313
  Item *res;
3101
 
  uint32_t len;
3102
 
  uint32_t dec;
 
3314
  ulong len;
 
3315
  uint dec;
3103
3316
 
3104
3317
  switch (cast_type) {
3105
3318
  case ITEM_CAST_BINARY: