~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/user_var_entry.cc

  • Committer: Monty Taylor
  • Date: 2010-01-02 05:11:55 UTC
  • mto: (1259.3.1 build)
  • mto: This revision was merged to the branch mainline in revision 1262.
  • Revision ID: mordred@inaugust.com-20100102051155-akdm8w5rr6xwzayu
pandora-build - proper detection of memcached.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <drizzled/session.h>
22
22
#include "drizzled/internal/m_string.h"
23
23
 
24
 
namespace drizzled
25
 
{
26
 
 
27
24
/** Get the value of a variable as a double. */
28
25
 
29
26
double user_var_entry::val_real(bool *null_value)
34
31
  switch (type) {
35
32
  case REAL_RESULT:
36
33
    return *(double*) value;
37
 
 
38
34
  case INT_RESULT:
39
35
    return (double) *(int64_t*) value;
40
 
 
41
36
  case DECIMAL_RESULT:
42
 
    {
43
 
      double result;
44
 
      my_decimal2double(E_DEC_FATAL_ERROR, (my_decimal *)value, &result);
45
 
      return result;
46
 
    }
47
 
 
 
37
  {
 
38
    double result;
 
39
    my_decimal2double(E_DEC_FATAL_ERROR, (my_decimal *)value, &result);
 
40
    return result;
 
41
  }
48
42
  case STRING_RESULT:
49
 
    return internal::my_atof(value);                      // This is null terminated
50
 
 
 
43
    return my_atof(value);                      // This is null terminated
51
44
  case ROW_RESULT:
52
45
    assert(1);                          // Impossible
53
46
    break;
66
59
  switch (type) {
67
60
  case REAL_RESULT:
68
61
    return (int64_t) *(double*) value;
69
 
 
70
62
  case INT_RESULT:
71
63
    return *(int64_t*) value;
72
 
 
73
64
  case DECIMAL_RESULT:
74
 
    {
75
 
      int64_t result;
76
 
      my_decimal2int(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, &result);
77
 
      return result;
78
 
    }
79
 
 
 
65
  {
 
66
    int64_t result;
 
67
    my_decimal2int(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, &result);
 
68
    return result;
 
69
  }
80
70
  case STRING_RESULT:
81
 
    {
82
 
      int error;
83
 
      return internal::my_strtoll10(value, (char**) 0, &error);// String is null terminated
84
 
    }
85
 
 
 
71
  {
 
72
    int error;
 
73
    return my_strtoll10(value, (char**) 0, &error);// String is null terminated
 
74
  }
86
75
  case ROW_RESULT:
87
76
    assert(1);                          // Impossible
88
77
    break;
89
78
  }
90
 
 
91
79
  return 0L;                                    // Impossible
92
80
}
93
81
 
95
83
/** Get the value of a variable as a string. */
96
84
 
97
85
String *user_var_entry::val_str(bool *null_value, String *str,
98
 
                                uint32_t decimals)
 
86
                                uint32_t decimals)
99
87
{
100
88
  if ((*null_value= (value == 0)))
101
89
    return (String*) 0;
104
92
  case REAL_RESULT:
105
93
    str->set_real(*(double*) value, decimals, &my_charset_bin);
106
94
    break;
107
 
 
108
95
  case INT_RESULT:
109
96
    if (!unsigned_flag)
110
97
      str->set(*(int64_t*) value, &my_charset_bin);
111
98
    else
112
99
      str->set(*(uint64_t*) value, &my_charset_bin);
113
100
    break;
114
 
 
115
101
  case DECIMAL_RESULT:
116
102
    my_decimal2string(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, 0, 0, str);
117
103
    break;
118
 
 
119
104
  case STRING_RESULT:
120
105
    if (str->copy(value, length, collation.collation))
121
106
      str= 0;                                   // EOM error
122
 
 
123
107
  case ROW_RESULT:
124
108
    assert(1);                          // Impossible
125
109
    break;
126
110
  }
127
 
 
128
111
  return(str);
129
112
}
130
113
 
139
122
  case REAL_RESULT:
140
123
    double2my_decimal(E_DEC_FATAL_ERROR, *(double*) value, val);
141
124
    break;
142
 
 
143
125
  case INT_RESULT:
144
126
    int2my_decimal(E_DEC_FATAL_ERROR, *(int64_t*) value, 0, val);
145
127
    break;
146
 
 
147
128
  case DECIMAL_RESULT:
148
129
    val= (my_decimal *)value;
149
130
    break;
150
 
 
151
131
  case STRING_RESULT:
152
132
    str2my_decimal(E_DEC_FATAL_ERROR, value, length, collation.collation, val);
153
133
    break;
154
 
 
155
134
  case ROW_RESULT:
156
135
    assert(1);                          // Impossible
157
136
    break;
158
137
  }
159
 
 
160
138
  return(val);
161
139
}
162
140
 
226
204
 
227
205
  return false;
228
206
}
229
 
 
230
 
} /* namespace drizzled */