~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/function/numhybrid.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-12-21 16:39:40 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20101221163940-c1pfo1jjvx7909xq
Tags: 2010.12.06-0ubuntu1
* New upstream release.
* Added libaio-dev build depend for InnoDB.
* Removed libpcre patch - applied upstream.

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
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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
38
38
  assert(fixed == 1);
39
39
  switch (hybrid_type) {
40
40
  case DECIMAL_RESULT:
41
 
  {
42
 
    my_decimal decimal_value, *val;
43
 
    if (!(val= decimal_op(&decimal_value)))
44
 
      return 0;                                 // null is set
45
 
    my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
46
 
    my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
47
 
    break;
48
 
  }
 
41
    {
 
42
      my_decimal decimal_value, *val;
 
43
      if (!(val= decimal_op(&decimal_value)))
 
44
        return 0;                                 // null is set
 
45
      my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
 
46
      my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
 
47
      break;
 
48
    }
49
49
  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
 
  }
 
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
    }
57
57
  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
 
  }
 
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
    }
65
65
  case STRING_RESULT:
66
66
    return str_op(&str_value);
67
 
  default:
 
67
  case ROW_RESULT:
68
68
    assert(0);
69
69
  }
70
70
  return str;
76
76
  assert(fixed == 1);
77
77
  switch (hybrid_type) {
78
78
  case DECIMAL_RESULT:
79
 
  {
80
 
    my_decimal decimal_value, *val;
81
 
    double result;
82
 
    if (!(val= decimal_op(&decimal_value)))
83
 
      return 0.0;                               // null is set
84
 
    my_decimal2double(E_DEC_FATAL_ERROR, val, &result);
85
 
    return result;
86
 
  }
 
79
    {
 
80
      my_decimal decimal_value, *val;
 
81
      double result;
 
82
      if (!(val= decimal_op(&decimal_value)))
 
83
        return 0.0;                               // null is set
 
84
      my_decimal2double(E_DEC_FATAL_ERROR, val, &result);
 
85
      return result;
 
86
    }
87
87
  case INT_RESULT:
88
 
  {
89
 
    int64_t result= int_op();
90
 
    return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
91
 
  }
 
88
    {
 
89
      int64_t result= int_op();
 
90
      return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
 
91
    }
92
92
  case REAL_RESULT:
93
93
    return real_op();
94
94
  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
 
  default:
 
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:
103
103
    assert(0);
104
104
  }
 
105
 
105
106
  return 0.0;
106
107
}
107
108
 
111
112
  assert(fixed == 1);
112
113
  switch (hybrid_type) {
113
114
  case DECIMAL_RESULT:
114
 
  {
115
 
    my_decimal decimal_value, *val;
116
 
    if (!(val= decimal_op(&decimal_value)))
117
 
      return 0;                                 // null is set
118
 
    int64_t result;
119
 
    my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
120
 
    return result;
121
 
  }
 
115
    {
 
116
      my_decimal decimal_value, *val;
 
117
      if (!(val= decimal_op(&decimal_value)))
 
118
        return 0;                                 // null is set
 
119
      int64_t result;
 
120
      my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
 
121
      return result;
 
122
    }
122
123
  case INT_RESULT:
123
124
    return int_op();
124
125
  case REAL_RESULT:
125
126
    return (int64_t) rint(real_op());
126
127
  case STRING_RESULT:
127
 
  {
128
 
    int err_not_used;
129
 
    String *res;
130
 
    if (!(res= str_op(&str_value)))
131
 
      return 0;
 
128
    {
 
129
      int err_not_used;
 
130
      String *res;
 
131
      if (!(res= str_op(&str_value)))
 
132
        return 0;
132
133
 
133
 
    char *end= (char*) res->ptr() + res->length();
134
 
    const CHARSET_INFO * const cs= str_value.charset();
135
 
    return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
136
 
  }
137
 
  default:
 
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:
138
139
    assert(0);
139
140
  }
140
141
  return 0;
145
146
{
146
147
  my_decimal *val= decimal_value;
147
148
  assert(fixed == 1);
 
149
 
148
150
  switch (hybrid_type) {
149
151
  case DECIMAL_RESULT:
150
152
    val= decimal_op(decimal_value);
151
153
    break;
152
154
  case INT_RESULT:
153
 
  {
154
 
    int64_t result= int_op();
155
 
    int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
156
 
    break;
157
 
  }
 
155
    {
 
156
      int64_t result= int_op();
 
157
      int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
 
158
      break;
 
159
    }
158
160
  case REAL_RESULT:
159
 
  {
160
 
    double result= (double)real_op();
161
 
    double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
162
 
    break;
163
 
  }
 
161
    {
 
162
      double result= (double)real_op();
 
163
      double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
 
164
      break;
 
165
    }
164
166
  case STRING_RESULT:
165
 
  {
166
 
    String *res;
167
 
    if (!(res= str_op(&str_value)))
168
 
      return NULL;
 
167
    {
 
168
      String *res;
 
169
      if (!(res= str_op(&str_value)))
 
170
        return NULL;
169
171
 
170
 
    str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
171
 
                   res->length(), res->charset(), decimal_value);
172
 
    break;
173
 
  }
 
172
      str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
 
173
                     res->length(), res->charset(), decimal_value);
 
174
      break;
 
175
    }
174
176
  case ROW_RESULT:
175
 
  default:
176
177
    assert(0);
177
178
  }
 
179
 
178
180
  return val;
179
181
}
180
182