~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/numhybrid.cc

  • Committer: Stewart Smith
  • Date: 2008-12-18 23:54:47 UTC
  • mto: This revision was merged to the branch mainline in revision 719.
  • Revision ID: stewart@flamingspork.com-20081218235447-qf6dofgd6guwefo2
fix RENAME TABLE

(problem was missing hton to mysql_rename_table)

If engine implements table_exists_in_engine we get the hton from there.

Else, we reintroduce the mysql_frm_type hackery (temporarily, it *will* go away again with FRM removal).

also fix rename test: no views, plus current FLUSH LOCKS bug.

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>
 
21
 
 
22
#include CSTDINT_H
 
23
#include <cassert>
 
24
 
22
25
#include <drizzled/function/numhybrid.h>
 
26
#include CMATH_H
23
27
 
24
 
namespace drizzled
25
 
{
 
28
#if defined(CMATH_NAMESPACE)
 
29
using namespace CMATH_NAMESPACE;
 
30
#endif
26
31
 
27
32
void Item_func_numhybrid::fix_num_length_and_dec()
28
33
{}
38
43
  assert(fixed == 1);
39
44
  switch (hybrid_type) {
40
45
  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
 
    }
 
46
  {
 
47
    my_decimal decimal_value, *val;
 
48
    if (!(val= decimal_op(&decimal_value)))
 
49
      return 0;                                 // null is set
 
50
    my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
 
51
    my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
 
52
    break;
 
53
  }
49
54
  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
 
    }
 
55
  {
 
56
    int64_t nr= int_op();
 
57
    if (null_value)
 
58
      return 0; /* purecov: inspected */
 
59
    str->set_int(nr, unsigned_flag, &my_charset_bin);
 
60
    break;
 
61
  }
57
62
  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
 
    }
 
63
  {
 
64
    double nr= real_op();
 
65
    if (null_value)
 
66
      return 0; /* purecov: inspected */
 
67
    str->set_real(nr,decimals,&my_charset_bin);
 
68
    break;
 
69
  }
65
70
  case STRING_RESULT:
66
71
    return str_op(&str_value);
67
 
  case ROW_RESULT:
 
72
  default:
68
73
    assert(0);
69
74
  }
70
75
  return str;
76
81
  assert(fixed == 1);
77
82
  switch (hybrid_type) {
78
83
  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
 
    }
 
84
  {
 
85
    my_decimal decimal_value, *val;
 
86
    double result;
 
87
    if (!(val= decimal_op(&decimal_value)))
 
88
      return 0.0;                               // null is set
 
89
    my_decimal2double(E_DEC_FATAL_ERROR, val, &result);
 
90
    return result;
 
91
  }
87
92
  case INT_RESULT:
88
 
    {
89
 
      int64_t result= int_op();
90
 
      return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
91
 
    }
 
93
  {
 
94
    int64_t result= int_op();
 
95
    return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
 
96
  }
92
97
  case REAL_RESULT:
93
98
    return real_op();
94
99
  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:
 
100
  {
 
101
    char *end_not_used;
 
102
    int err_not_used;
 
103
    String *res= str_op(&str_value);
 
104
    return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
 
105
                             &end_not_used, &err_not_used) : 0.0);
 
106
  }
 
107
  default:
103
108
    assert(0);
104
109
  }
105
 
 
106
110
  return 0.0;
107
111
}
108
112
 
112
116
  assert(fixed == 1);
113
117
  switch (hybrid_type) {
114
118
  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
 
    }
 
119
  {
 
120
    my_decimal decimal_value, *val;
 
121
    if (!(val= decimal_op(&decimal_value)))
 
122
      return 0;                                 // null is set
 
123
    int64_t result;
 
124
    my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
 
125
    return result;
 
126
  }
123
127
  case INT_RESULT:
124
128
    return int_op();
125
129
  case REAL_RESULT:
126
130
    return (int64_t) rint(real_op());
127
131
  case STRING_RESULT:
128
 
    {
129
 
      int err_not_used;
130
 
      String *res;
131
 
      if (!(res= str_op(&str_value)))
132
 
        return 0;
 
132
  {
 
133
    int err_not_used;
 
134
    String *res;
 
135
    if (!(res= str_op(&str_value)))
 
136
      return 0;
133
137
 
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
    char *end= (char*) res->ptr() + res->length();
 
139
    const CHARSET_INFO * const cs= str_value.charset();
 
140
    return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
 
141
  }
 
142
  default:
139
143
    assert(0);
140
144
  }
141
145
  return 0;
142
146
}
143
147
 
144
148
 
145
 
type::Decimal *Item_func_numhybrid::val_decimal(type::Decimal *decimal_value)
 
149
my_decimal *Item_func_numhybrid::val_decimal(my_decimal *decimal_value)
146
150
{
147
 
  type::Decimal *val= decimal_value;
 
151
  my_decimal *val= decimal_value;
148
152
  assert(fixed == 1);
149
 
 
150
153
  switch (hybrid_type) {
151
154
  case DECIMAL_RESULT:
152
155
    val= decimal_op(decimal_value);
153
156
    break;
154
157
  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
 
    }
 
158
  {
 
159
    int64_t result= int_op();
 
160
    int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
 
161
    break;
 
162
  }
160
163
  case REAL_RESULT:
161
 
    {
162
 
      double result= (double)real_op();
163
 
      double2_class_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
164
 
      break;
165
 
    }
 
164
  {
 
165
    double result= (double)real_op();
 
166
    double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
 
167
    break;
 
168
  }
166
169
  case STRING_RESULT:
167
 
    {
168
 
      String *res;
169
 
      if (!(res= str_op(&str_value)))
170
 
        return NULL;
 
170
  {
 
171
    String *res;
 
172
    if (!(res= str_op(&str_value)))
 
173
      return NULL;
171
174
 
172
 
      decimal_value->store(E_DEC_FATAL_ERROR, (char*) res->ptr(),
173
 
                           res->length(), res->charset());
174
 
      break;
175
 
    }
 
175
    str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
 
176
                   res->length(), res->charset(), decimal_value);
 
177
    break;
 
178
  }
176
179
  case ROW_RESULT:
 
180
  default:
177
181
    assert(0);
178
182
  }
179
 
 
180
183
  return val;
181
184
}
182
 
 
183
 
} /* namespace drizzled */