~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/create.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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 "config.h"
 
23
#include <config.h>
24
24
#include <drizzled/item/create.h>
25
25
#include <drizzled/item/func.h>
26
26
#include <drizzled/error.h>
27
27
 
28
 
#include "drizzled/function_container.h"
 
28
#include <drizzled/function_container.h>
29
29
 
30
30
#include <drizzled/function/str/binary.h>
31
31
#include <drizzled/function/str/concat.h>
83
83
#include <drizzled/function/math/tan.h>
84
84
#include <drizzled/function/units.h>
85
85
 
 
86
#include <drizzled/function/cast/boolean.h>
 
87
#include <drizzled/function/cast/signed.h>
 
88
#include <drizzled/function/cast/time.h>
 
89
#include <drizzled/function/cast/unsigned.h>
 
90
 
86
91
using namespace std;
87
92
 
88
93
namespace drizzled
1048
1053
  if (params)
1049
1054
  {
1050
1055
    Item *param;
1051
 
    List_iterator<Item> it(*params);
 
1056
    List<Item>::iterator it(params->begin());
1052
1057
    while ((param= it++))
1053
1058
    {
1054
1059
      if (! param->is_autogenerated_name)
2042
2047
  {
2043
2048
    func_name.assign(func->name.str, func->name.length);
2044
2049
 
2045
 
    FunctionContainer::getMap()[func_name]= func;
 
2050
    FunctionContainer::getMap()[func_name]= func->builder;
2046
2051
  }
2047
2052
 
2048
2053
  return 0;
2052
2057
Create_func *
2053
2058
find_native_function_builder(LEX_STRING name)
2054
2059
{
2055
 
  Native_func_registry *func;
2056
2060
  Create_func *builder= NULL;
2057
2061
 
2058
2062
  string func_name(name.str, name.length);
2059
2063
 
2060
 
  NativeFunctionsMap::iterator func_iter=
 
2064
  FunctionContainer::Map::iterator func_iter=
2061
2065
    FunctionContainer::getMap().find(func_name);
2062
2066
 
2063
2067
  if (func_iter != FunctionContainer::getMap().end())
2064
2068
  {
2065
 
    func= (*func_iter).second;
2066
 
    builder= func->builder;
 
2069
    builder= (*func_iter).second;
2067
2070
  }
2068
2071
 
2069
2072
  return builder;
2083
2086
                 const char *c_len, const char *c_dec,
2084
2087
                 const CHARSET_INFO * const cs)
2085
2088
{
2086
 
  Item *res;
 
2089
  Item *res= NULL;
2087
2090
  uint32_t len;
2088
2091
  uint32_t dec;
2089
2092
 
2090
2093
  switch (cast_type) {
 
2094
  case ITEM_CAST_SIGNED:
 
2095
    res= new (session->mem_root) function::cast::Signed(a);
 
2096
    break;
 
2097
 
 
2098
  case ITEM_CAST_UNSIGNED:
 
2099
    res= new (session->mem_root) function::cast::Unsigned(a);
 
2100
    break;
 
2101
 
2091
2102
  case ITEM_CAST_BINARY:
2092
2103
    res= new (session->mem_root) Item_func_binary(a);
2093
2104
    break;
 
2105
 
 
2106
  case ITEM_CAST_BOOLEAN:
 
2107
    res= new (session->mem_root) function::cast::Boolean(a);
 
2108
    break;
 
2109
 
 
2110
  case ITEM_CAST_TIME:
 
2111
    res= new (session->mem_root) function::cast::Time(a);
 
2112
    break;
 
2113
 
2094
2114
  case ITEM_CAST_DATE:
2095
2115
    res= new (session->mem_root) Item_date_typecast(a);
2096
2116
    break;
 
2117
 
2097
2118
  case ITEM_CAST_DATETIME:
2098
2119
    res= new (session->mem_root) Item_datetime_typecast(a);
2099
2120
    break;
 
2121
 
2100
2122
  case ITEM_CAST_DECIMAL:
2101
 
  {
2102
 
    len= c_len ? atoi(c_len) : 0;
2103
 
    dec= c_dec ? atoi(c_dec) : 0;
2104
 
    my_decimal_trim(&len, &dec);
2105
 
    if (len < dec)
2106
 
    {
2107
 
      my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
2108
 
      return 0;
2109
 
    }
2110
 
    if (len > DECIMAL_MAX_PRECISION)
2111
 
    {
2112
 
      my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
2113
 
               DECIMAL_MAX_PRECISION);
2114
 
      return 0;
2115
 
    }
2116
 
    if (dec > DECIMAL_MAX_SCALE)
2117
 
    {
2118
 
      my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
2119
 
               DECIMAL_MAX_SCALE);
2120
 
      return 0;
2121
 
    }
2122
 
    res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
2123
 
    break;
2124
 
  }
 
2123
    {
 
2124
      len= c_len ? atoi(c_len) : 0;
 
2125
      dec= c_dec ? atoi(c_dec) : 0;
 
2126
      class_decimal_trim(&len, &dec);
 
2127
      if (len < dec)
 
2128
      {
 
2129
        my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
 
2130
        return 0;
 
2131
      }
 
2132
      if (len > DECIMAL_MAX_PRECISION)
 
2133
      {
 
2134
        my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
 
2135
                 DECIMAL_MAX_PRECISION);
 
2136
        return 0;
 
2137
      }
 
2138
      if (dec > DECIMAL_MAX_SCALE)
 
2139
      {
 
2140
        my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
 
2141
                 DECIMAL_MAX_SCALE);
 
2142
        return 0;
 
2143
      }
 
2144
      res= new (session->mem_root) Item_decimal_typecast(a, len, dec);
 
2145
      break;
 
2146
    }
2125
2147
  case ITEM_CAST_CHAR:
2126
 
  {
2127
 
    len= c_len ? atoi(c_len) : -1;
2128
 
    res= create_func_char_cast(session, a, len, cs);
2129
 
    break;
2130
 
  }
2131
 
  default:
2132
 
  {
2133
 
    assert(0);
2134
 
    res= 0;
2135
 
    break;
2136
 
  }
2137
 
  }
 
2148
    {
 
2149
      len= c_len ? atoi(c_len) : -1;
 
2150
      res= create_func_char_cast(session, a, len, cs);
 
2151
      break;
 
2152
    }
 
2153
  }
 
2154
 
2138
2155
  return res;
2139
2156
}
2140
2157