~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_create.cc

  • Committer: Mats Kindahl
  • Date: 2008-08-07 06:24:22 UTC
  • mfrom: (265 drizzle)
  • mto: (264.1.19 codestyle)
  • mto: This revision was merged to the branch mainline in revision 266.
  • Revision ID: mats@mysql.com-20080807062422-20kyv6ssp4grfm0s
Manual merge of lp:drizzle into ~mkindahl/remove-mem-casts.

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
=============================================================================
1461
1462
Item*
1462
1463
Create_udf_func::create(THD *thd, udf_func *udf, List<Item> *item_list)
1463
1464
{
1464
 
  Item_func *func= NULL;
 
1465
  Item *func= NULL;
1465
1466
  int arg_count= 0;
1466
1467
 
1467
1468
  if (item_list != NULL)
1469
1470
 
1470
1471
  thd->lex->set_stmt_unsafe();
1471
1472
 
1472
 
  func= udf->create_func(thd->mem_root);
1473
 
 
1474
 
  func->set_arguments(*item_list);
1475
 
 
 
1473
  assert(   (udf->type == UDFTYPE_FUNCTION)
 
1474
              || (udf->type == UDFTYPE_AGGREGATE));
 
1475
 
 
1476
  switch(udf->returns) {
 
1477
  case STRING_RESULT:
 
1478
  {
 
1479
    if (udf->type == UDFTYPE_FUNCTION)
 
1480
    {
 
1481
      if (arg_count)
 
1482
        func= new (thd->mem_root) Item_func_udf_str(udf, *item_list);
 
1483
      else
 
1484
        func= new (thd->mem_root) Item_func_udf_str(udf);
 
1485
    }
 
1486
    else
 
1487
    {
 
1488
      if (arg_count)
 
1489
        func= new (thd->mem_root) Item_sum_udf_str(udf, *item_list);
 
1490
      else
 
1491
        func= new (thd->mem_root) Item_sum_udf_str(udf);
 
1492
    }
 
1493
    break;
 
1494
  }
 
1495
  case REAL_RESULT:
 
1496
  {
 
1497
    if (udf->type == UDFTYPE_FUNCTION)
 
1498
    {
 
1499
      if (arg_count)
 
1500
        func= new (thd->mem_root) Item_func_udf_float(udf, *item_list);
 
1501
      else
 
1502
        func= new (thd->mem_root) Item_func_udf_float(udf);
 
1503
    }
 
1504
    else
 
1505
    {
 
1506
      if (arg_count)
 
1507
        func= new (thd->mem_root) Item_sum_udf_float(udf, *item_list);
 
1508
      else
 
1509
        func= new (thd->mem_root) Item_sum_udf_float(udf);
 
1510
    }
 
1511
    break;
 
1512
  }
 
1513
  case INT_RESULT:
 
1514
  {
 
1515
    if (udf->type == UDFTYPE_FUNCTION)
 
1516
    {
 
1517
      if (arg_count)
 
1518
        func= new (thd->mem_root) Item_func_udf_int(udf, *item_list);
 
1519
      else
 
1520
        func= new (thd->mem_root) Item_func_udf_int(udf);
 
1521
    }
 
1522
    else
 
1523
    {
 
1524
      if (arg_count)
 
1525
        func= new (thd->mem_root) Item_sum_udf_int(udf, *item_list);
 
1526
      else
 
1527
        func= new (thd->mem_root) Item_sum_udf_int(udf);
 
1528
    }
 
1529
    break;
 
1530
  }
 
1531
  case DECIMAL_RESULT:
 
1532
  {
 
1533
    if (udf->type == UDFTYPE_FUNCTION)
 
1534
    {
 
1535
      if (arg_count)
 
1536
        func= new (thd->mem_root) Item_func_udf_decimal(udf, *item_list);
 
1537
      else
 
1538
        func= new (thd->mem_root) Item_func_udf_decimal(udf);
 
1539
    }
 
1540
    else
 
1541
    {
 
1542
      if (arg_count)
 
1543
        func= new (thd->mem_root) Item_sum_udf_decimal(udf, *item_list);
 
1544
      else
 
1545
        func= new (thd->mem_root) Item_sum_udf_decimal(udf);
 
1546
    }
 
1547
    break;
 
1548
  }
 
1549
  default:
 
1550
  {
 
1551
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "UDF return type");
 
1552
  }
 
1553
  }
1476
1554
  return func;
1477
1555
}
1478
1556
 
2648
2726
    The parsed item tree should not depend on
2649
2727
    <code>thd->variables.collation_connection</code>.
2650
2728
  */
2651
 
  const CHARSET_INFO * const cs= thd->variables.collation_connection;
 
2729
  CHARSET_INFO *cs= thd->variables.collation_connection;
2652
2730
  Item *sp;
2653
2731
 
2654
2732
  if (cs->mbminlen > 1)
2655
2733
  {
2656
 
    uint32_t dummy_errors;
 
2734
    uint dummy_errors;
2657
2735
    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);
 
2736
    sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
2659
2737
  }
2660
2738
  else
2661
2739
  {
3013
3091
 
3014
3092
static HASH native_functions_hash;
3015
3093
 
3016
 
extern "C" unsigned char*
3017
 
get_native_fct_hash_key(const unsigned char *buff, size_t *length,
3018
 
                        bool /* unused */)
 
3094
extern "C" uchar*
 
3095
get_native_fct_hash_key(const uchar *buff, size_t *length,
 
3096
                        my_bool /* unused */)
3019
3097
{
3020
3098
  Native_func_registry *func= (Native_func_registry*) buff;
3021
3099
  *length= func->name.length;
3022
 
  return (unsigned char*) func->name.str;
 
3100
  return (uchar*) func->name.str;
3023
3101
}
3024
3102
 
3025
3103
/*
3044
3122
 
3045
3123
  for (func= func_array; func->builder != NULL; func++)
3046
3124
  {
3047
 
    if (my_hash_insert(& native_functions_hash, (unsigned char*) func))
 
3125
    if (my_hash_insert(& native_functions_hash, (uchar*) func))
3048
3126
      return(1);
3049
3127
  }
3050
3128
 
3072
3150
 
3073
3151
  /* Thread safe */
3074
3152
  func= (Native_func_registry*) hash_search(& native_functions_hash,
3075
 
                                            (unsigned char*) name.str,
 
3153
                                            (uchar*) name.str,
3076
3154
                                             name.length);
3077
3155
 
3078
3156
  if (func)
3085
3163
 
3086
3164
 
3087
3165
Item*
3088
 
create_func_char_cast(THD *thd, Item *a, int len, const CHARSET_INFO * const cs)
 
3166
create_func_char_cast(THD *thd, Item *a, int len, CHARSET_INFO *cs)
3089
3167
{
3090
 
  const CHARSET_INFO * const real_cs= (cs ? cs : thd->variables.collation_connection);
 
3168
  CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
3091
3169
  return new (thd->mem_root) Item_char_typecast(a, len, real_cs);
3092
3170
}
3093
3171
 
3095
3173
Item *
3096
3174
create_func_cast(THD *thd, Item *a, Cast_target cast_type,
3097
3175
                 const char *c_len, const char *c_dec,
3098
 
                 const CHARSET_INFO * const cs)
 
3176
                 CHARSET_INFO *cs)
3099
3177
{
3100
3178
  Item *res;
3101
 
  uint32_t len;
3102
 
  uint32_t dec;
 
3179
  ulong len;
 
3180
  uint dec;
3103
3181
 
3104
3182
  switch (cast_type) {
3105
3183
  case ITEM_CAST_BINARY: