1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
21
#include <drizzled/session.h>
24
/** Get the value of a variable as a double. */
26
double user_var_entry::val_real(bool *null_value)
28
if ((*null_value= (value == 0)))
33
return *(double*) value;
35
return (double) *(int64_t*) value;
39
my_decimal2double(E_DEC_FATAL_ERROR, (my_decimal *)value, &result);
43
return my_atof(value); // This is null terminated
45
assert(1); // Impossible
48
return 0.0; // Impossible
52
/** Get the value of a variable as an integer. */
54
int64_t user_var_entry::val_int(bool *null_value) const
56
if ((*null_value= (value == 0)))
61
return (int64_t) *(double*) value;
63
return *(int64_t*) value;
67
my_decimal2int(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, &result);
73
return my_strtoll10(value, (char**) 0, &error);// String is null terminated
76
assert(1); // Impossible
79
return 0L; // Impossible
83
/** Get the value of a variable as a string. */
85
String *user_var_entry::val_str(bool *null_value, String *str,
88
if ((*null_value= (value == 0)))
93
str->set_real(*(double*) value, decimals, &my_charset_bin);
97
str->set(*(int64_t*) value, &my_charset_bin);
99
str->set(*(uint64_t*) value, &my_charset_bin);
102
my_decimal2string(E_DEC_FATAL_ERROR, (my_decimal *)value, 0, 0, 0, str);
105
if (str->copy(value, length, collation.collation))
108
assert(1); // Impossible
114
/** Get the value of a variable as a decimal. */
116
my_decimal *user_var_entry::val_decimal(bool *null_value, my_decimal *val)
118
if ((*null_value= (value == 0)))
123
double2my_decimal(E_DEC_FATAL_ERROR, *(double*) value, val);
126
int2my_decimal(E_DEC_FATAL_ERROR, *(int64_t*) value, 0, val);
129
val= (my_decimal *)value;
132
str2my_decimal(E_DEC_FATAL_ERROR, value, length, collation.collation, val);
135
assert(1); // Impossible