629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
5 |
*
|
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.
|
|
9 |
*
|
|
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.
|
|
14 |
*
|
|
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
|
|
18 |
*/
|
|
19 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
20 |
#include "config.h" |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
21 |
#include <drizzled/session.h> |
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
22 |
#include "drizzled/internal/m_string.h" |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
23 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
24 |
namespace drizzled |
25 |
{
|
|
26 |
||
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
27 |
/** Get the value of a variable as a double. */
|
28 |
||
29 |
double user_var_entry::val_real(bool *null_value) |
|
30 |
{
|
|
31 |
if ((*null_value= (value == 0))) |
|
32 |
return 0.0; |
|
33 |
||
34 |
switch (type) { |
|
35 |
case REAL_RESULT: |
|
36 |
return *(double*) value; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
37 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
38 |
case INT_RESULT: |
39 |
return (double) *(int64_t*) value; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
40 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
41 |
case DECIMAL_RESULT: |
2008
by Brian Aker
Formatting + remove default from switch/case. |
42 |
{
|
43 |
double result; |
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
44 |
class_decimal2double(E_DEC_FATAL_ERROR, (type::Decimal *)value, &result); |
2008
by Brian Aker
Formatting + remove default from switch/case. |
45 |
return result; |
46 |
}
|
|
47 |
||
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
48 |
case STRING_RESULT: |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
49 |
return internal::my_atof(value); // This is null terminated |
2008
by Brian Aker
Formatting + remove default from switch/case. |
50 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
51 |
case ROW_RESULT: |
52 |
assert(1); // Impossible |
|
53 |
break; |
|
54 |
}
|
|
55 |
return 0.0; // Impossible |
|
56 |
}
|
|
57 |
||
58 |
||
59 |
/** Get the value of a variable as an integer. */
|
|
60 |
||
61 |
int64_t user_var_entry::val_int(bool *null_value) const |
|
62 |
{
|
|
63 |
if ((*null_value= (value == 0))) |
|
64 |
return 0L; |
|
65 |
||
66 |
switch (type) { |
|
67 |
case REAL_RESULT: |
|
68 |
return (int64_t) *(double*) value; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
69 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
70 |
case INT_RESULT: |
71 |
return *(int64_t*) value; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
72 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
73 |
case DECIMAL_RESULT: |
2008
by Brian Aker
Formatting + remove default from switch/case. |
74 |
{
|
75 |
int64_t result; |
|
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
76 |
((type::Decimal *)(value))->val_int32(E_DEC_FATAL_ERROR, 0, &result); |
2008
by Brian Aker
Formatting + remove default from switch/case. |
77 |
return result; |
78 |
}
|
|
79 |
||
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
80 |
case STRING_RESULT: |
2008
by Brian Aker
Formatting + remove default from switch/case. |
81 |
{
|
82 |
int error; |
|
83 |
return internal::my_strtoll10(value, (char**) 0, &error);// String is null terminated |
|
84 |
}
|
|
85 |
||
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
86 |
case ROW_RESULT: |
87 |
assert(1); // Impossible |
|
88 |
break; |
|
89 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
90 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
91 |
return 0L; // Impossible |
92 |
}
|
|
93 |
||
94 |
||
95 |
/** Get the value of a variable as a string. */
|
|
96 |
||
97 |
String *user_var_entry::val_str(bool *null_value, String *str, |
|
1927.2.1
by Brian Aker
Merge up the tree. |
98 |
uint32_t decimals) |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
99 |
{
|
100 |
if ((*null_value= (value == 0))) |
|
101 |
return (String*) 0; |
|
102 |
||
103 |
switch (type) { |
|
104 |
case REAL_RESULT: |
|
105 |
str->set_real(*(double*) value, decimals, &my_charset_bin); |
|
106 |
break; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
107 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
108 |
case INT_RESULT: |
109 |
if (!unsigned_flag) |
|
110 |
str->set(*(int64_t*) value, &my_charset_bin); |
|
111 |
else
|
|
112 |
str->set(*(uint64_t*) value, &my_charset_bin); |
|
113 |
break; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
114 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
115 |
case DECIMAL_RESULT: |
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
116 |
class_decimal2string(E_DEC_FATAL_ERROR, (type::Decimal *)value, 0, 0, 0, str); |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
117 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
118 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
119 |
case STRING_RESULT: |
120 |
if (str->copy(value, length, collation.collation)) |
|
121 |
str= 0; // EOM error |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
122 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
123 |
case ROW_RESULT: |
124 |
assert(1); // Impossible |
|
125 |
break; |
|
126 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
127 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
128 |
return(str); |
129 |
}
|
|
130 |
||
131 |
/** Get the value of a variable as a decimal. */
|
|
132 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
133 |
type::Decimal *user_var_entry::val_decimal(bool *null_value, type::Decimal *val) |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
134 |
{
|
135 |
if ((*null_value= (value == 0))) |
|
136 |
return 0; |
|
137 |
||
138 |
switch (type) { |
|
139 |
case REAL_RESULT: |
|
2030.1.3
by Brian Aker
Second pass through function names. |
140 |
double2_class_decimal(E_DEC_FATAL_ERROR, *(double*) value, val); |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
141 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
142 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
143 |
case INT_RESULT: |
2030.1.3
by Brian Aker
Second pass through function names. |
144 |
int2_class_decimal(E_DEC_FATAL_ERROR, *(int64_t*) value, 0, val); |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
145 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
146 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
147 |
case DECIMAL_RESULT: |
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
148 |
val= (type::Decimal *)value; |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
149 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
150 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
151 |
case STRING_RESULT: |
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
152 |
val->store(E_DEC_FATAL_ERROR, value, length, collation.collation); |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
153 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
154 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
155 |
case ROW_RESULT: |
156 |
assert(1); // Impossible |
|
157 |
break; |
|
158 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
159 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
160 |
return(val); |
161 |
}
|
|
1089.1.5
by Brian Aker
Cleanup of user_var |
162 |
|
163 |
/**
|
|
164 |
Set value to user variable.
|
|
165 |
||
166 |
@param entry pointer to structure representing variable
|
|
167 |
@param set_null should we set NULL value ?
|
|
168 |
@param ptr pointer to buffer with new value
|
|
169 |
@param length length of new value
|
|
170 |
@param type type of new value
|
|
171 |
@param cs charset info for new value
|
|
172 |
@param dv derivation for new value
|
|
173 |
@param unsigned_arg indiates if a value of type INT_RESULT is unsigned
|
|
174 |
||
175 |
@note Sets error and fatal error if allocation fails.
|
|
176 |
||
177 |
@retval
|
|
178 |
false success
|
|
179 |
@retval
|
|
180 |
true failure
|
|
181 |
*/
|
|
182 |
||
183 |
bool user_var_entry::update_hash(bool set_null, void *ptr, uint32_t arg_length, |
|
184 |
Item_result arg_type, const CHARSET_INFO * const cs, Derivation dv, |
|
185 |
bool unsigned_arg) |
|
186 |
{
|
|
187 |
if (set_null) |
|
188 |
{
|
|
189 |
if (value) |
|
190 |
{
|
|
191 |
assert(length && size); |
|
192 |
free(value); |
|
193 |
value= NULL; |
|
194 |
length= 0; |
|
195 |
size= 0; |
|
196 |
}
|
|
197 |
}
|
|
198 |
else
|
|
199 |
{
|
|
200 |
size_t needed_size= arg_length + ((arg_type == STRING_RESULT) ? 1 : 0); |
|
201 |
||
202 |
if (needed_size > size) |
|
203 |
{
|
|
204 |
char *new_ptr; |
|
205 |
||
206 |
new_ptr= (char *)realloc(value, needed_size); |
|
207 |
||
208 |
if (new_ptr == NULL) |
|
209 |
return true; |
|
210 |
||
211 |
value= new_ptr; |
|
212 |
size= needed_size; |
|
213 |
}
|
|
214 |
||
215 |
if (arg_type == STRING_RESULT) |
|
216 |
value[arg_length]= 0; // Store end \0 |
|
217 |
||
218 |
memcpy(value, ptr, arg_length); |
|
219 |
if (arg_type == DECIMAL_RESULT) |
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
220 |
((type::Decimal*)value)->fix_buffer_pointer(); |
1089.1.5
by Brian Aker
Cleanup of user_var |
221 |
length= arg_length; |
222 |
collation.set(cs, dv); |
|
223 |
unsigned_flag= unsigned_arg; |
|
224 |
}
|
|
225 |
type= arg_type; |
|
226 |
||
227 |
return false; |
|
228 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
229 |
|
230 |
} /* namespace drizzled */ |