~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_create.cc

  • Committer: Brian Aker
  • Date: 2008-07-01 23:01:40 UTC
  • mfrom: (28.1.27 libtool-patch)
  • Revision ID: brian@tangent.org-20080701230140-8bs081cfx1mxugp4
More Cleanup around dead files/GNU Makefile warnings (just a merge from me)

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
=============================================================================
379
380
};
380
381
 
381
382
 
 
383
class Create_func_convert_tz : public Create_func_arg3
 
384
{
 
385
public:
 
386
  virtual Item *create(THD *thd, Item *arg1, Item *arg2, Item *arg3);
 
387
 
 
388
  static Create_func_convert_tz s_singleton;
 
389
 
 
390
protected:
 
391
  Create_func_convert_tz() {}
 
392
  virtual ~Create_func_convert_tz() {}
 
393
};
 
394
 
 
395
 
382
396
class Create_func_cos : public Create_func_arg1
383
397
{
384
398
public:
404
418
  virtual ~Create_func_cot() {}
405
419
};
406
420
 
 
421
 
 
422
class Create_func_crc32 : public Create_func_arg1
 
423
{
 
424
public:
 
425
  virtual Item *create(THD *thd, Item *arg1);
 
426
 
 
427
  static Create_func_crc32 s_singleton;
 
428
 
 
429
protected:
 
430
  Create_func_crc32() {}
 
431
  virtual ~Create_func_crc32() {}
 
432
};
 
433
 
 
434
 
407
435
class Create_func_date_format : public Create_func_arg2
408
436
{
409
437
public:
521
549
};
522
550
 
523
551
 
 
552
class Create_func_encode : public Create_func_arg2
 
553
{
 
554
public:
 
555
  virtual Item *create(THD *thd, Item *arg1, Item *arg2);
 
556
 
 
557
  static Create_func_encode s_singleton;
 
558
 
 
559
protected:
 
560
  Create_func_encode() {}
 
561
  virtual ~Create_func_encode() {}
 
562
};
 
563
 
 
564
 
 
565
class Create_func_encrypt : public Create_native_func
 
566
{
 
567
public:
 
568
  virtual Item *create_native(THD *thd, LEX_STRING name, List<Item> *item_list);
 
569
 
 
570
  static Create_func_encrypt s_singleton;
 
571
 
 
572
protected:
 
573
  Create_func_encrypt() {}
 
574
  virtual ~Create_func_encrypt() {}
 
575
};
 
576
 
 
577
 
524
578
class Create_func_exp : public Create_func_arg1
525
579
{
526
580
public:
923
977
  virtual ~Create_func_master_pos_wait() {}
924
978
};
925
979
 
 
980
 
 
981
class Create_func_md5 : public Create_func_arg1
 
982
{
 
983
public:
 
984
  virtual Item *create(THD *thd, Item *arg1);
 
985
 
 
986
  static Create_func_md5 s_singleton;
 
987
 
 
988
protected:
 
989
  Create_func_md5() {}
 
990
  virtual ~Create_func_md5() {}
 
991
};
 
992
 
 
993
 
926
994
class Create_func_monthname : public Create_func_arg1
927
995
{
928
996
public:
1365
1433
};
1366
1434
 
1367
1435
 
 
1436
class Create_func_uuid_short : public Create_func_arg0
 
1437
{
 
1438
public:
 
1439
  virtual Item *create(THD *thd);
 
1440
 
 
1441
  static Create_func_uuid_short s_singleton;
 
1442
 
 
1443
protected:
 
1444
  Create_func_uuid_short() {}
 
1445
  virtual ~Create_func_uuid_short() {}
 
1446
};
 
1447
 
 
1448
 
1368
1449
class Create_func_version : public Create_func_arg0
1369
1450
{
1370
1451
public:
1447
1528
}
1448
1529
 
1449
1530
 
 
1531
#ifdef HAVE_DLOPEN
1450
1532
Create_udf_func Create_udf_func::s_singleton;
1451
1533
 
1452
1534
Item*
1453
1535
Create_udf_func::create(THD *thd, LEX_STRING name, List<Item> *item_list)
1454
1536
{
1455
1537
  udf_func *udf= find_udf(name.str, name.length);
1456
 
  assert(udf);
 
1538
  DBUG_ASSERT(udf);
1457
1539
  return create(thd, udf, item_list);
1458
1540
}
1459
1541
 
1461
1543
Item*
1462
1544
Create_udf_func::create(THD *thd, udf_func *udf, List<Item> *item_list)
1463
1545
{
1464
 
  Item_func *func= NULL;
 
1546
  Item *func= NULL;
1465
1547
  int arg_count= 0;
1466
1548
 
1467
1549
  if (item_list != NULL)
1469
1551
 
1470
1552
  thd->lex->set_stmt_unsafe();
1471
1553
 
1472
 
  func= udf->create_func(thd->mem_root);
1473
 
 
1474
 
  func->set_arguments(*item_list);
1475
 
 
 
1554
  DBUG_ASSERT(   (udf->type == UDFTYPE_FUNCTION)
 
1555
              || (udf->type == UDFTYPE_AGGREGATE));
 
1556
 
 
1557
  switch(udf->returns) {
 
1558
  case STRING_RESULT:
 
1559
  {
 
1560
    if (udf->type == UDFTYPE_FUNCTION)
 
1561
    {
 
1562
      if (arg_count)
 
1563
        func= new (thd->mem_root) Item_func_udf_str(udf, *item_list);
 
1564
      else
 
1565
        func= new (thd->mem_root) Item_func_udf_str(udf);
 
1566
    }
 
1567
    else
 
1568
    {
 
1569
      if (arg_count)
 
1570
        func= new (thd->mem_root) Item_sum_udf_str(udf, *item_list);
 
1571
      else
 
1572
        func= new (thd->mem_root) Item_sum_udf_str(udf);
 
1573
    }
 
1574
    break;
 
1575
  }
 
1576
  case REAL_RESULT:
 
1577
  {
 
1578
    if (udf->type == UDFTYPE_FUNCTION)
 
1579
    {
 
1580
      if (arg_count)
 
1581
        func= new (thd->mem_root) Item_func_udf_float(udf, *item_list);
 
1582
      else
 
1583
        func= new (thd->mem_root) Item_func_udf_float(udf);
 
1584
    }
 
1585
    else
 
1586
    {
 
1587
      if (arg_count)
 
1588
        func= new (thd->mem_root) Item_sum_udf_float(udf, *item_list);
 
1589
      else
 
1590
        func= new (thd->mem_root) Item_sum_udf_float(udf);
 
1591
    }
 
1592
    break;
 
1593
  }
 
1594
  case INT_RESULT:
 
1595
  {
 
1596
    if (udf->type == UDFTYPE_FUNCTION)
 
1597
    {
 
1598
      if (arg_count)
 
1599
        func= new (thd->mem_root) Item_func_udf_int(udf, *item_list);
 
1600
      else
 
1601
        func= new (thd->mem_root) Item_func_udf_int(udf);
 
1602
    }
 
1603
    else
 
1604
    {
 
1605
      if (arg_count)
 
1606
        func= new (thd->mem_root) Item_sum_udf_int(udf, *item_list);
 
1607
      else
 
1608
        func= new (thd->mem_root) Item_sum_udf_int(udf);
 
1609
    }
 
1610
    break;
 
1611
  }
 
1612
  case DECIMAL_RESULT:
 
1613
  {
 
1614
    if (udf->type == UDFTYPE_FUNCTION)
 
1615
    {
 
1616
      if (arg_count)
 
1617
        func= new (thd->mem_root) Item_func_udf_decimal(udf, *item_list);
 
1618
      else
 
1619
        func= new (thd->mem_root) Item_func_udf_decimal(udf);
 
1620
    }
 
1621
    else
 
1622
    {
 
1623
      if (arg_count)
 
1624
        func= new (thd->mem_root) Item_sum_udf_decimal(udf, *item_list);
 
1625
      else
 
1626
        func= new (thd->mem_root) Item_sum_udf_decimal(udf);
 
1627
    }
 
1628
    break;
 
1629
  }
 
1630
  default:
 
1631
  {
 
1632
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "UDF return type");
 
1633
  }
 
1634
  }
1476
1635
  return func;
1477
1636
}
 
1637
#endif
1478
1638
 
1479
1639
 
1480
1640
Item*
1679
1839
Item*
1680
1840
Create_func_bin::create(THD *thd, Item *arg1)
1681
1841
{
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);
 
1842
  Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
 
1843
  Item *i2= new (thd->mem_root) Item_int((int32) 2,1);
1684
1844
  return new (thd->mem_root) Item_func_conv(arg1, i10, i2);
1685
1845
}
1686
1846
 
1791
1951
}
1792
1952
 
1793
1953
 
 
1954
Create_func_convert_tz Create_func_convert_tz::s_singleton;
 
1955
 
 
1956
Item*
 
1957
Create_func_convert_tz::create(THD *thd, Item *arg1, Item *arg2, Item *arg3)
 
1958
{
 
1959
  return new (thd->mem_root) Item_func_convert_tz(arg1, arg2, arg3);
 
1960
}
 
1961
 
 
1962
 
1794
1963
Create_func_cos Create_func_cos::s_singleton;
1795
1964
 
1796
1965
Item*
1810
1979
  return new (thd->mem_root) Item_func_div(i1, i2);
1811
1980
}
1812
1981
 
 
1982
 
 
1983
Create_func_crc32 Create_func_crc32::s_singleton;
 
1984
 
 
1985
Item*
 
1986
Create_func_crc32::create(THD *thd, Item *arg1)
 
1987
{
 
1988
  return new (thd->mem_root) Item_func_crc32(arg1);
 
1989
}
 
1990
 
 
1991
 
1813
1992
Create_func_date_format Create_func_date_format::s_singleton;
1814
1993
 
1815
1994
Item*
1867
2046
}
1868
2047
 
1869
2048
 
 
2049
Create_func_decode Create_func_decode::s_singleton;
 
2050
 
 
2051
Item*
 
2052
Create_func_decode::create(THD *thd, Item *arg1, Item *arg2)
 
2053
{
 
2054
  return new (thd->mem_root) Item_func_decode(arg1, arg2);
 
2055
}
 
2056
 
 
2057
 
1870
2058
Create_func_degrees Create_func_degrees::s_singleton;
1871
2059
 
1872
2060
Item*
1898
2086
}
1899
2087
 
1900
2088
 
 
2089
Create_func_encode Create_func_encode::s_singleton;
 
2090
 
 
2091
Item*
 
2092
Create_func_encode::create(THD *thd, Item *arg1, Item *arg2)
 
2093
{
 
2094
  return new (thd->mem_root) Item_func_encode(arg1, arg2);
 
2095
}
 
2096
 
 
2097
 
 
2098
Create_func_encrypt Create_func_encrypt::s_singleton;
 
2099
 
 
2100
Item*
 
2101
Create_func_encrypt::create_native(THD *thd, LEX_STRING name,
 
2102
                                   List<Item> *item_list)
 
2103
{
 
2104
  Item *func= NULL;
 
2105
  int arg_count= 0;
 
2106
 
 
2107
  if (item_list != NULL)
 
2108
    arg_count= item_list->elements;
 
2109
 
 
2110
  switch (arg_count) {
 
2111
  case 1:
 
2112
  {
 
2113
    Item *param_1= item_list->pop();
 
2114
    func= new (thd->mem_root) Item_func_encrypt(param_1);
 
2115
    break;
 
2116
  }
 
2117
  case 2:
 
2118
  {
 
2119
    Item *param_1= item_list->pop();
 
2120
    Item *param_2= item_list->pop();
 
2121
    func= new (thd->mem_root) Item_func_encrypt(param_1, param_2);
 
2122
    break;
 
2123
  }
 
2124
  default:
 
2125
  {
 
2126
    my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name.str);
 
2127
    break;
 
2128
  }
 
2129
  }
 
2130
 
 
2131
  return func;
 
2132
}
 
2133
 
 
2134
 
1901
2135
Create_func_exp Create_func_exp::s_singleton;
1902
2136
 
1903
2137
Item*
2417
2651
}
2418
2652
 
2419
2653
 
 
2654
Create_func_md5 Create_func_md5::s_singleton;
 
2655
 
 
2656
Item*
 
2657
Create_func_md5::create(THD *thd, Item *arg1)
 
2658
{
 
2659
  return new (thd->mem_root) Item_func_md5(arg1);
 
2660
}
 
2661
 
 
2662
 
2420
2663
Create_func_monthname Create_func_monthname::s_singleton;
2421
2664
 
2422
2665
Item*
2440
2683
Item*
2441
2684
Create_func_oct::create(THD *thd, Item *arg1)
2442
2685
{
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);
 
2686
  Item *i10= new (thd->mem_root) Item_int((int32) 10,2);
 
2687
  Item *i8= new (thd->mem_root) Item_int((int32) 8,1);
2445
2688
  return new (thd->mem_root) Item_func_conv(arg1, i10, i8);
2446
2689
}
2447
2690
 
2648
2891
    The parsed item tree should not depend on
2649
2892
    <code>thd->variables.collation_connection</code>.
2650
2893
  */
2651
 
  const CHARSET_INFO * const cs= thd->variables.collation_connection;
 
2894
  CHARSET_INFO *cs= thd->variables.collation_connection;
2652
2895
  Item *sp;
2653
2896
 
2654
2897
  if (cs->mbminlen > 1)
2655
2898
  {
2656
 
    uint32_t dummy_errors;
 
2899
    uint dummy_errors;
2657
2900
    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);
 
2901
    sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
2659
2902
  }
2660
2903
  else
2661
2904
  {
2819
3062
}
2820
3063
 
2821
3064
 
 
3065
Create_func_uuid_short Create_func_uuid_short::s_singleton;
 
3066
 
 
3067
Item*
 
3068
Create_func_uuid_short::create(THD *thd)
 
3069
{
 
3070
  thd->lex->set_stmt_unsafe();
 
3071
  return new (thd->mem_root) Item_func_uuid_short();
 
3072
}
 
3073
 
 
3074
 
2822
3075
Create_func_version Create_func_version::s_singleton;
2823
3076
 
2824
3077
Item*
2925
3178
  { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
2926
3179
  { { C_STRING_WITH_LEN("CONNECTION_ID") }, BUILDER(Create_func_connection_id)},
2927
3180
  { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
 
3181
  { { C_STRING_WITH_LEN("CONVERT_TZ") }, BUILDER(Create_func_convert_tz)},
2928
3182
  { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
2929
3183
  { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
 
3184
  { { C_STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)},
2930
3185
  { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
2931
3186
  { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
2932
3187
  { { C_STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
2933
3188
  { { C_STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
2934
3189
  { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
2935
3190
  { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
 
3191
  { { C_STRING_WITH_LEN("DECODE") }, BUILDER(Create_func_decode)},
2936
3192
  { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
2937
3193
  { { C_STRING_WITH_LEN("ELT") }, BUILDER(Create_func_elt)},
 
3194
  { { C_STRING_WITH_LEN("ENCODE") }, BUILDER(Create_func_encode)},
 
3195
  { { C_STRING_WITH_LEN("ENCRYPT") }, BUILDER(Create_func_encrypt)},
2938
3196
  { { C_STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
2939
3197
  { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
2940
3198
  { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
2967
3225
  { { C_STRING_WITH_LEN("MAKETIME") }, BUILDER(Create_func_maketime)},
2968
3226
  { { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
2969
3227
  { { C_STRING_WITH_LEN("MASTER_POS_WAIT") }, BUILDER(Create_func_master_pos_wait)},
 
3228
  { { C_STRING_WITH_LEN("MD5") }, BUILDER(Create_func_md5)},
2970
3229
  { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
2971
3230
  { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
2972
3231
  { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
3003
3262
  { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
3004
3263
  { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
3005
3264
  { { C_STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
 
3265
  { { C_STRING_WITH_LEN("UUID_SHORT") }, BUILDER(Create_func_uuid_short)},
3006
3266
  { { C_STRING_WITH_LEN("VERSION") }, BUILDER(Create_func_version)},
3007
3267
  { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
3008
3268
  { { C_STRING_WITH_LEN("WEEKOFYEAR") }, BUILDER(Create_func_weekofyear)},
3013
3273
 
3014
3274
static HASH native_functions_hash;
3015
3275
 
3016
 
extern "C" unsigned char*
3017
 
get_native_fct_hash_key(const unsigned char *buff, size_t *length,
3018
 
                        bool /* unused */)
 
3276
extern "C" uchar*
 
3277
get_native_fct_hash_key(const uchar *buff, size_t *length,
 
3278
                        my_bool /* unused */)
3019
3279
{
3020
3280
  Native_func_registry *func= (Native_func_registry*) buff;
3021
3281
  *length= func->name.length;
3022
 
  return (unsigned char*) func->name.str;
 
3282
  return (uchar*) func->name.str;
3023
3283
}
3024
3284
 
3025
3285
/*
3032
3292
{
3033
3293
  Native_func_registry *func;
3034
3294
 
 
3295
  DBUG_ENTER("item_create_init");
 
3296
 
3035
3297
  if (hash_init(& native_functions_hash,
3036
3298
                system_charset_info,
3037
3299
                array_elements(func_array),
3040
3302
                (hash_get_key) get_native_fct_hash_key,
3041
3303
                NULL,                          /* Nothing to free */
3042
3304
                MYF(0)))
3043
 
    return(1);
 
3305
    DBUG_RETURN(1);
3044
3306
 
3045
3307
  for (func= func_array; func->builder != NULL; func++)
3046
3308
  {
3047
 
    if (my_hash_insert(& native_functions_hash, (unsigned char*) func))
3048
 
      return(1);
3049
 
  }
3050
 
 
3051
 
  return(0);
 
3309
    if (my_hash_insert(& native_functions_hash, (uchar*) func))
 
3310
      DBUG_RETURN(1);
 
3311
  }
 
3312
 
 
3313
#ifndef DBUG_OFF
 
3314
  for (uint i=0 ; i < native_functions_hash.records ; i++)
 
3315
  {
 
3316
    func= (Native_func_registry*) hash_element(& native_functions_hash, i);
 
3317
    DBUG_PRINT("info", ("native function: %s  length: %u",
 
3318
                        func->name.str, (uint) func->name.length));
 
3319
  }
 
3320
#endif
 
3321
 
 
3322
  DBUG_RETURN(0);
3052
3323
}
3053
3324
 
3054
3325
/*
3059
3330
 
3060
3331
void item_create_cleanup()
3061
3332
{
 
3333
  DBUG_ENTER("item_create_cleanup");
3062
3334
  hash_free(& native_functions_hash);
3063
 
  return;
 
3335
  DBUG_VOID_RETURN;
3064
3336
}
3065
3337
 
3066
3338
Create_func *
3067
 
find_native_function_builder(THD *thd __attribute__((unused)),
3068
 
                             LEX_STRING name)
 
3339
find_native_function_builder(THD *thd, LEX_STRING name)
3069
3340
{
3070
3341
  Native_func_registry *func;
3071
3342
  Create_func *builder= NULL;
3072
3343
 
3073
3344
  /* Thread safe */
3074
3345
  func= (Native_func_registry*) hash_search(& native_functions_hash,
3075
 
                                            (unsigned char*) name.str,
 
3346
                                            (uchar*) name.str,
3076
3347
                                             name.length);
3077
3348
 
3078
3349
  if (func)
3085
3356
 
3086
3357
 
3087
3358
Item*
3088
 
create_func_char_cast(THD *thd, Item *a, int len, const CHARSET_INFO * const cs)
 
3359
create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs)
3089
3360
{
3090
 
  const CHARSET_INFO * const real_cs= (cs ? cs : thd->variables.collation_connection);
 
3361
  CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
3091
3362
  return new (thd->mem_root) Item_char_typecast(a, len, real_cs);
3092
3363
}
3093
3364
 
3095
3366
Item *
3096
3367
create_func_cast(THD *thd, Item *a, Cast_target cast_type,
3097
3368
                 const char *c_len, const char *c_dec,
3098
 
                 const CHARSET_INFO * const cs)
 
3369
                 CHARSET_INFO *cs)
3099
3370
{
3100
3371
  Item *res;
3101
 
  uint32_t len;
3102
 
  uint32_t dec;
 
3372
  ulong len;
 
3373
  uint dec;
3103
3374
 
3104
3375
  switch (cast_type) {
3105
3376
  case ITEM_CAST_BINARY:
3153
3424
  }
3154
3425
  default:
3155
3426
  {
3156
 
    assert(0);
 
3427
    DBUG_ASSERT(0);
3157
3428
    res= 0;
3158
3429
    break;
3159
3430
  }