~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/numhybrid.cc

  • Committer: Stewart Smith
  • Date: 2009-10-19 03:27:43 UTC
  • mto: This revision was merged to the branch mainline in revision 1188.
  • Revision ID: stewart@flamingspork.com-20091019032743-xajbflq0ktpe9vw2
remove --disable-warnings in func_in_null_scan.test

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include <math.h>
 
20
#include <drizzled/server_includes.h>
22
21
#include <drizzled/function/numhybrid.h>
23
22
 
24
 
namespace drizzled
25
 
{
26
 
 
27
23
void Item_func_numhybrid::fix_num_length_and_dec()
28
24
{}
29
25
 
38
34
  assert(fixed == 1);
39
35
  switch (hybrid_type) {
40
36
  case DECIMAL_RESULT:
41
 
    {
42
 
      type::Decimal decimal_value, *val;
43
 
      if (!(val= decimal_op(&decimal_value)))
44
 
        return 0;                                 // null is set
45
 
      class_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
46
 
      class_decimal2string(val, 0, str);
47
 
      break;
48
 
    }
 
37
  {
 
38
    my_decimal decimal_value, *val;
 
39
    if (!(val= decimal_op(&decimal_value)))
 
40
      return 0;                                 // null is set
 
41
    my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
 
42
    my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
 
43
    break;
 
44
  }
49
45
  case INT_RESULT:
50
 
    {
51
 
      int64_t nr= int_op();
52
 
      if (null_value)
53
 
        return 0;
54
 
      str->set_int(nr, unsigned_flag, &my_charset_bin);
55
 
      break;
56
 
    }
 
46
  {
 
47
    int64_t nr= int_op();
 
48
    if (null_value)
 
49
      return 0;
 
50
    str->set_int(nr, unsigned_flag, &my_charset_bin);
 
51
    break;
 
52
  }
57
53
  case REAL_RESULT:
58
 
    {
59
 
      double nr= real_op();
60
 
      if (null_value)
61
 
        return 0;
62
 
      str->set_real(nr,decimals,&my_charset_bin);
63
 
      break;
64
 
    }
 
54
  {
 
55
    double nr= real_op();
 
56
    if (null_value)
 
57
      return 0;
 
58
    str->set_real(nr,decimals,&my_charset_bin);
 
59
    break;
 
60
  }
65
61
  case STRING_RESULT:
66
62
    return str_op(&str_value);
67
 
  case ROW_RESULT:
 
63
  default:
68
64
    assert(0);
69
65
  }
70
66
  return str;
76
72
  assert(fixed == 1);
77
73
  switch (hybrid_type) {
78
74
  case DECIMAL_RESULT:
79
 
    {
80
 
      type::Decimal decimal_value, *val;
81
 
      double result;
82
 
      if (!(val= decimal_op(&decimal_value)))
83
 
        return 0.0;                               // null is set
84
 
      class_decimal2double(E_DEC_FATAL_ERROR, val, &result);
85
 
      return result;
86
 
    }
 
75
  {
 
76
    my_decimal decimal_value, *val;
 
77
    double result;
 
78
    if (!(val= decimal_op(&decimal_value)))
 
79
      return 0.0;                               // null is set
 
80
    my_decimal2double(E_DEC_FATAL_ERROR, val, &result);
 
81
    return result;
 
82
  }
87
83
  case INT_RESULT:
88
 
    {
89
 
      int64_t result= int_op();
90
 
      return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
91
 
    }
 
84
  {
 
85
    int64_t result= int_op();
 
86
    return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
 
87
  }
92
88
  case REAL_RESULT:
93
89
    return real_op();
94
90
  case STRING_RESULT:
95
 
    {
96
 
      char *end_not_used;
97
 
      int err_not_used;
98
 
      String *res= str_op(&str_value);
99
 
      return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
100
 
                               &end_not_used, &err_not_used) : 0.0);
101
 
    }
102
 
  case ROW_RESULT:
 
91
  {
 
92
    char *end_not_used;
 
93
    int err_not_used;
 
94
    String *res= str_op(&str_value);
 
95
    return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
 
96
                             &end_not_used, &err_not_used) : 0.0);
 
97
  }
 
98
  default:
103
99
    assert(0);
104
100
  }
105
 
 
106
101
  return 0.0;
107
102
}
108
103
 
112
107
  assert(fixed == 1);
113
108
  switch (hybrid_type) {
114
109
  case DECIMAL_RESULT:
115
 
    {
116
 
      type::Decimal decimal_value, *val;
117
 
      if (!(val= decimal_op(&decimal_value)))
118
 
        return 0;                                 // null is set
119
 
      int64_t result;
120
 
      val->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
121
 
      return result;
122
 
    }
 
110
  {
 
111
    my_decimal decimal_value, *val;
 
112
    if (!(val= decimal_op(&decimal_value)))
 
113
      return 0;                                 // null is set
 
114
    int64_t result;
 
115
    my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
 
116
    return result;
 
117
  }
123
118
  case INT_RESULT:
124
119
    return int_op();
125
120
  case REAL_RESULT:
126
121
    return (int64_t) rint(real_op());
127
122
  case STRING_RESULT:
128
 
    {
129
 
      int err_not_used;
130
 
      String *res;
131
 
      if (!(res= str_op(&str_value)))
132
 
        return 0;
 
123
  {
 
124
    int err_not_used;
 
125
    String *res;
 
126
    if (!(res= str_op(&str_value)))
 
127
      return 0;
133
128
 
134
 
      char *end= (char*) res->ptr() + res->length();
135
 
      const CHARSET_INFO * const cs= str_value.charset();
136
 
      return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
137
 
    }
138
 
  case ROW_RESULT:
 
129
    char *end= (char*) res->ptr() + res->length();
 
130
    const CHARSET_INFO * const cs= str_value.charset();
 
131
    return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
 
132
  }
 
133
  default:
139
134
    assert(0);
140
135
  }
141
136
  return 0;
142
137
}
143
138
 
144
139
 
145
 
type::Decimal *Item_func_numhybrid::val_decimal(type::Decimal *decimal_value)
 
140
my_decimal *Item_func_numhybrid::val_decimal(my_decimal *decimal_value)
146
141
{
147
 
  type::Decimal *val= decimal_value;
 
142
  my_decimal *val= decimal_value;
148
143
  assert(fixed == 1);
149
 
 
150
144
  switch (hybrid_type) {
151
145
  case DECIMAL_RESULT:
152
146
    val= decimal_op(decimal_value);
153
147
    break;
154
148
  case INT_RESULT:
155
 
    {
156
 
      int64_t result= int_op();
157
 
      int2_class_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
158
 
      break;
159
 
    }
 
149
  {
 
150
    int64_t result= int_op();
 
151
    int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
 
152
    break;
 
153
  }
160
154
  case REAL_RESULT:
161
 
    {
162
 
      double result= (double)real_op();
163
 
      double2_class_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
164
 
      break;
165
 
    }
 
155
  {
 
156
    double result= (double)real_op();
 
157
    double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
 
158
    break;
 
159
  }
166
160
  case STRING_RESULT:
167
 
    {
168
 
      String *res;
169
 
      if (!(res= str_op(&str_value)))
170
 
        return NULL;
 
161
  {
 
162
    String *res;
 
163
    if (!(res= str_op(&str_value)))
 
164
      return NULL;
171
165
 
172
 
      decimal_value->store(E_DEC_FATAL_ERROR, (char*) res->ptr(),
173
 
                           res->length(), res->charset());
174
 
      break;
175
 
    }
 
166
    str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
 
167
                   res->length(), res->charset(), decimal_value);
 
168
    break;
 
169
  }
176
170
  case ROW_RESULT:
 
171
  default:
177
172
    assert(0);
178
173
  }
179
 
 
180
174
  return val;
181
175
}
182
 
 
183
 
} /* namespace drizzled */