~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/create.cc

  • Committer: Brian Aker
  • Date: 2010-10-20 20:26:18 UTC
  • mfrom: (1859.2.13 refactor)
  • Revision ID: brian@tangent.org-20101020202618-9222n39lm329urv5
Merge for Brian 

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
91
86
using namespace std;
92
87
 
93
88
namespace drizzled
2047
2042
  {
2048
2043
    func_name.assign(func->name.str, func->name.length);
2049
2044
 
2050
 
    FunctionContainer::getMap()[func_name]= func->builder;
 
2045
    FunctionContainer::getMap()[func_name]= func;
2051
2046
  }
2052
2047
 
2053
2048
  return 0;
2057
2052
Create_func *
2058
2053
find_native_function_builder(LEX_STRING name)
2059
2054
{
 
2055
  Native_func_registry *func;
2060
2056
  Create_func *builder= NULL;
2061
2057
 
2062
2058
  string func_name(name.str, name.length);
2063
2059
 
2064
 
  FunctionContainer::Map::iterator func_iter=
 
2060
  NativeFunctionsMap::iterator func_iter=
2065
2061
    FunctionContainer::getMap().find(func_name);
2066
2062
 
2067
2063
  if (func_iter != FunctionContainer::getMap().end())
2068
2064
  {
2069
 
    builder= (*func_iter).second;
 
2065
    func= (*func_iter).second;
 
2066
    builder= func->builder;
2070
2067
  }
2071
2068
 
2072
2069
  return builder;
2086
2083
                 const char *c_len, const char *c_dec,
2087
2084
                 const CHARSET_INFO * const cs)
2088
2085
{
2089
 
  Item *res= NULL;
 
2086
  Item *res;
2090
2087
  uint32_t len;
2091
2088
  uint32_t dec;
2092
2089
 
2093
2090
  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
 
 
2102
2091
  case ITEM_CAST_BINARY:
2103
2092
    res= new (session->mem_root) Item_func_binary(a);
2104
2093
    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
 
 
2114
2094
  case ITEM_CAST_DATE:
2115
2095
    res= new (session->mem_root) Item_date_typecast(a);
2116
2096
    break;
2117
 
 
2118
2097
  case ITEM_CAST_DATETIME:
2119
2098
    res= new (session->mem_root) Item_datetime_typecast(a);
2120
2099
    break;
2121
 
 
2122
2100
  case ITEM_CAST_DECIMAL:
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
 
    }
 
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
  }
2147
2125
  case ITEM_CAST_CHAR:
2148
 
    {
2149
 
      len= c_len ? atoi(c_len) : -1;
2150
 
      res= create_func_char_cast(session, a, len, cs);
2151
 
      break;
2152
 
    }
2153
 
  }
2154
 
 
 
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
  }
2155
2138
  return res;
2156
2139
}
2157
2140