~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/user_var_entry.cc

  • Committer: Marisa Plumb
  • Date: 2010-12-04 02:38:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1984.
  • Revision ID: marisa.plumb@gmail.com-20101204023829-2khzxh30wxi256db
updates to a few sql docs 

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
 
 
 
20
#include "config.h"
22
21
#include <drizzled/session.h>
23
 
#include <drizzled/internal/m_string.h>
24
 
#include <drizzled/user_var_entry.h>
 
22
#include "drizzled/internal/m_string.h"
25
23
 
26
24
namespace drizzled
27
25
{
36
34
  switch (type) {
37
35
  case REAL_RESULT:
38
36
    return *(double*) value;
39
 
 
40
37
  case INT_RESULT:
41
38
    return (double) *(int64_t*) value;
42
 
 
43
39
  case DECIMAL_RESULT:
44
 
    {
45
 
      double result;
46
 
      class_decimal2double(E_DEC_FATAL_ERROR, (type::Decimal *)value, &result);
47
 
      return result;
48
 
    }
49
 
 
 
40
  {
 
41
    double result;
 
42
    my_decimal2double(E_DEC_FATAL_ERROR, (my_decimal *)value, &result);
 
43
    return result;
 
44
  }
50
45
  case STRING_RESULT:
51
46
    return internal::my_atof(value);                      // This is null terminated
52
 
 
53
47
  case ROW_RESULT:
54
48
    assert(1);                          // Impossible
55
49
    break;
68
62
  switch (type) {
69
63
  case REAL_RESULT:
70
64
    return (int64_t) *(double*) value;
71
 
 
72
65
  case INT_RESULT:
73
66
    return *(int64_t*) value;
74
 
 
75
67
  case DECIMAL_RESULT:
76
 
    {
77
 
      int64_t result;
78
 
      ((type::Decimal *)(value))->val_int32(E_DEC_FATAL_ERROR, 0, &result);
79
 
      return result;
80
 
    }
81
 
 
 
68
  {
 
69
    int64_t result;
 
70
    my_decimal2int(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, &result);
 
71
    return result;
 
72
  }
82
73
  case STRING_RESULT:
83
 
    {
84
 
      int error;
85
 
      return internal::my_strtoll10(value, (char**) 0, &error);// String is null terminated
86
 
    }
87
 
 
 
74
  {
 
75
    int error;
 
76
    return internal::my_strtoll10(value, (char**) 0, &error);// String is null terminated
 
77
  }
88
78
  case ROW_RESULT:
89
79
    assert(1);                          // Impossible
90
80
    break;
91
81
  }
92
 
 
93
82
  return 0L;                                    // Impossible
94
83
}
95
84
 
106
95
  case REAL_RESULT:
107
96
    str->set_real(*(double*) value, decimals, &my_charset_bin);
108
97
    break;
109
 
 
110
98
  case INT_RESULT:
111
99
    if (!unsigned_flag)
112
100
      str->set(*(int64_t*) value, &my_charset_bin);
113
101
    else
114
102
      str->set(*(uint64_t*) value, &my_charset_bin);
115
103
    break;
116
 
 
117
104
  case DECIMAL_RESULT:
118
 
    class_decimal2string((type::Decimal *)value, 0, str);
 
105
    my_decimal2string(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, 0, 0, str);
119
106
    break;
120
 
 
121
107
  case STRING_RESULT:
122
108
    if (str->copy(value, length, collation.collation))
123
109
      str= 0;                                   // EOM error
124
 
 
125
110
  case ROW_RESULT:
126
111
    assert(1);                          // Impossible
127
112
    break;
128
113
  }
129
 
 
130
114
  return(str);
131
115
}
132
116
 
133
117
/** Get the value of a variable as a decimal. */
134
118
 
135
 
type::Decimal *user_var_entry::val_decimal(bool *null_value, type::Decimal *val)
 
119
my_decimal *user_var_entry::val_decimal(bool *null_value, my_decimal *val)
136
120
{
137
121
  if ((*null_value= (value == 0)))
138
122
    return 0;
139
123
 
140
124
  switch (type) {
141
125
  case REAL_RESULT:
142
 
    double2_class_decimal(E_DEC_FATAL_ERROR, *(double*) value, val);
 
126
    double2my_decimal(E_DEC_FATAL_ERROR, *(double*) value, val);
143
127
    break;
144
 
 
145
128
  case INT_RESULT:
146
 
    int2_class_decimal(E_DEC_FATAL_ERROR, *(int64_t*) value, 0, val);
 
129
    int2my_decimal(E_DEC_FATAL_ERROR, *(int64_t*) value, 0, val);
147
130
    break;
148
 
 
149
131
  case DECIMAL_RESULT:
150
 
    val= (type::Decimal *)value;
 
132
    val= (my_decimal *)value;
151
133
    break;
152
 
 
153
134
  case STRING_RESULT:
154
 
    val->store(E_DEC_FATAL_ERROR, value, length, collation.collation);
 
135
    str2my_decimal(E_DEC_FATAL_ERROR, value, length, collation.collation, val);
155
136
    break;
156
 
 
157
137
  case ROW_RESULT:
158
138
    assert(1);                          // Impossible
159
139
    break;
160
140
  }
161
 
 
162
141
  return(val);
163
142
}
164
143
 
219
198
 
220
199
    memcpy(value, ptr, arg_length);
221
200
    if (arg_type == DECIMAL_RESULT)
222
 
      ((type::Decimal*)value)->fix_buffer_pointer();
 
201
      ((my_decimal*)value)->fix_buffer_pointer();
223
202
    length= arg_length;
224
203
    collation.set(cs, dv);
225
204
    unsigned_flag= unsigned_arg;