~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/user_var_entry.cc

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

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