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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
21 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
22 |
#include <drizzled/session.h> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
23 |
#include <drizzled/internal/m_string.h> |
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
24 |
#include <drizzled/user_var_entry.h> |
2241.2.14
by Olaf van der Spek
Refactor |
25 |
#include <drizzled/type/decimal.h> |
2281.5.1
by Muhammad Umair
Merged charset declarations of global_charset_info.h and charset_info.h into charset.h header file. |
26 |
#include <drizzled/charset.h> |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
27 |
|
2241.2.14
by Olaf van der Spek
Refactor |
28 |
namespace drizzled { |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
29 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
30 |
/** Get the value of a variable as a double. */
|
31 |
||
2445.1.13
by Olaf van der Spek
Refactor |
32 |
double user_var_entry::val_real(bool *null_value) const |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
33 |
{
|
2445.1.13
by Olaf van der Spek
Refactor |
34 |
if ((*null_value= not value)) |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
35 |
return 0.0; |
36 |
||
2445.1.13
by Olaf van der Spek
Refactor |
37 |
switch (type) |
38 |
{
|
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
39 |
case REAL_RESULT: |
40 |
return *(double*) value; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
41 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
42 |
case INT_RESULT: |
43 |
return (double) *(int64_t*) value; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
44 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
45 |
case DECIMAL_RESULT: |
2008
by Brian Aker
Formatting + remove default from switch/case. |
46 |
{
|
47 |
double result; |
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
48 |
class_decimal2double(E_DEC_FATAL_ERROR, (type::Decimal *)value, &result); |
2008
by Brian Aker
Formatting + remove default from switch/case. |
49 |
return result; |
50 |
}
|
|
51 |
||
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
52 |
case STRING_RESULT: |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
53 |
return internal::my_atof(value); // This is null terminated |
2008
by Brian Aker
Formatting + remove default from switch/case. |
54 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
55 |
case ROW_RESULT: |
2318.7.22
by Olaf van der Spek
Use assert(false) instead of assert(1) |
56 |
assert(false); // Impossible |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
57 |
break; |
58 |
}
|
|
59 |
return 0.0; // Impossible |
|
60 |
}
|
|
61 |
||
62 |
||
63 |
/** Get the value of a variable as an integer. */
|
|
64 |
||
65 |
int64_t user_var_entry::val_int(bool *null_value) const |
|
66 |
{
|
|
2445.1.13
by Olaf van der Spek
Refactor |
67 |
if ((*null_value= not value)) |
68 |
return 0; |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
69 |
|
2445.1.13
by Olaf van der Spek
Refactor |
70 |
switch (type) |
71 |
{
|
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
72 |
case REAL_RESULT: |
73 |
return (int64_t) *(double*) value; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
74 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
75 |
case INT_RESULT: |
76 |
return *(int64_t*) value; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
77 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
78 |
case DECIMAL_RESULT: |
2008
by Brian Aker
Formatting + remove default from switch/case. |
79 |
{
|
80 |
int64_t result; |
|
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
81 |
((type::Decimal *)(value))->val_int32(E_DEC_FATAL_ERROR, 0, &result); |
2008
by Brian Aker
Formatting + remove default from switch/case. |
82 |
return result; |
83 |
}
|
|
84 |
||
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
85 |
case STRING_RESULT: |
2008
by Brian Aker
Formatting + remove default from switch/case. |
86 |
{
|
87 |
int error; |
|
88 |
return internal::my_strtoll10(value, (char**) 0, &error);// String is null terminated |
|
89 |
}
|
|
90 |
||
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
91 |
case ROW_RESULT: |
2318.7.22
by Olaf van der Spek
Use assert(false) instead of assert(1) |
92 |
assert(false); // Impossible |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
93 |
break; |
94 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
95 |
|
2445.1.13
by Olaf van der Spek
Refactor |
96 |
assert(false); |
97 |
return 0; // Impossible |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
98 |
}
|
99 |
||
100 |
||
101 |
/** Get the value of a variable as a string. */
|
|
102 |
||
2445.1.13
by Olaf van der Spek
Refactor |
103 |
String *user_var_entry::val_str(bool *null_value, String *str, uint32_t decimals) const |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
104 |
{
|
2318.7.22
by Olaf van der Spek
Use assert(false) instead of assert(1) |
105 |
if ((*null_value= not value)) |
106 |
return NULL; |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
107 |
|
2318.7.22
by Olaf van der Spek
Use assert(false) instead of assert(1) |
108 |
switch (type) |
109 |
{
|
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
110 |
case REAL_RESULT: |
111 |
str->set_real(*(double*) value, decimals, &my_charset_bin); |
|
112 |
break; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
113 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
114 |
case INT_RESULT: |
115 |
if (!unsigned_flag) |
|
116 |
str->set(*(int64_t*) value, &my_charset_bin); |
|
117 |
else
|
|
118 |
str->set(*(uint64_t*) value, &my_charset_bin); |
|
119 |
break; |
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
120 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
121 |
case DECIMAL_RESULT: |
2137.1.8
by Brian Aker
Remove error type from str convert since we always want an error. |
122 |
class_decimal2string((type::Decimal *)value, 0, str); |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
123 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
124 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
125 |
case STRING_RESULT: |
2281.4.6
by Olaf van der Spek
Return void |
126 |
str->copy(value, length, collation.collation); |
2318.7.22
by Olaf van der Spek
Use assert(false) instead of assert(1) |
127 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
128 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
129 |
case ROW_RESULT: |
2318.7.22
by Olaf van der Spek
Use assert(false) instead of assert(1) |
130 |
assert(false); // Impossible |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
131 |
break; |
132 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
133 |
|
2445.1.13
by Olaf van der Spek
Refactor |
134 |
return str; |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
135 |
}
|
136 |
||
137 |
/** Get the value of a variable as a decimal. */
|
|
138 |
||
2445.1.13
by Olaf van der Spek
Refactor |
139 |
type::Decimal *user_var_entry::val_decimal(bool *null_value, type::Decimal *val) const |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
140 |
{
|
2445.1.13
by Olaf van der Spek
Refactor |
141 |
if ((*null_value= not value)) |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
142 |
return 0; |
143 |
||
2445.1.13
by Olaf van der Spek
Refactor |
144 |
switch (type) |
145 |
{
|
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
146 |
case REAL_RESULT: |
2030.1.3
by Brian Aker
Second pass through function names. |
147 |
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 |
148 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
149 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
150 |
case INT_RESULT: |
2030.1.3
by Brian Aker
Second pass through function names. |
151 |
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 |
152 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
153 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
154 |
case DECIMAL_RESULT: |
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
155 |
val= (type::Decimal *)value; |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
156 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
157 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
158 |
case STRING_RESULT: |
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
159 |
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 |
160 |
break; |
2008
by Brian Aker
Formatting + remove default from switch/case. |
161 |
|
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
162 |
case ROW_RESULT: |
2318.7.22
by Olaf van der Spek
Use assert(false) instead of assert(1) |
163 |
assert(false); // Impossible |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
164 |
break; |
165 |
}
|
|
2008
by Brian Aker
Formatting + remove default from switch/case. |
166 |
|
2445.1.13
by Olaf van der Spek
Refactor |
167 |
return val; |
629.6.7
by Lee
final clean up of item/func functions moving them to the functions directory |
168 |
}
|
1089.1.5
by Brian Aker
Cleanup of user_var |
169 |
|
170 |
/**
|
|
171 |
Set value to user variable.
|
|
172 |
||
173 |
@param entry pointer to structure representing variable
|
|
174 |
@param set_null should we set NULL value ?
|
|
175 |
@param ptr pointer to buffer with new value
|
|
176 |
@param length length of new value
|
|
177 |
@param type type of new value
|
|
178 |
@param cs charset info for new value
|
|
179 |
@param dv derivation for new value
|
|
180 |
@param unsigned_arg indiates if a value of type INT_RESULT is unsigned
|
|
181 |
||
182 |
@note Sets error and fatal error if allocation fails.
|
|
183 |
||
184 |
@retval
|
|
185 |
false success
|
|
186 |
@retval
|
|
187 |
true failure
|
|
188 |
*/
|
|
189 |
||
2440.2.10
by Olaf van der Spek
Use data_ref |
190 |
void user_var_entry::update_hash(bool set_null, data_ref data, Item_result arg_type, const charset_info_st* cs, Derivation dv, bool unsigned_arg) |
1089.1.5
by Brian Aker
Cleanup of user_var |
191 |
{
|
192 |
if (set_null) |
|
193 |
{
|
|
194 |
if (value) |
|
195 |
{
|
|
196 |
assert(length && size); |
|
197 |
free(value); |
|
198 |
value= NULL; |
|
199 |
length= 0; |
|
200 |
size= 0; |
|
201 |
}
|
|
202 |
}
|
|
203 |
else
|
|
204 |
{
|
|
2440.2.10
by Olaf van der Spek
Use data_ref |
205 |
size_t needed_size= data.size() + ((arg_type == STRING_RESULT) ? 1 : 0); |
1089.1.5
by Brian Aker
Cleanup of user_var |
206 |
|
207 |
if (needed_size > size) |
|
208 |
{
|
|
2246.3.4
by Olaf van der Spek
Propogate return void |
209 |
value= (char *)realloc(value, needed_size); |
1089.1.5
by Brian Aker
Cleanup of user_var |
210 |
size= needed_size; |
211 |
}
|
|
212 |
||
213 |
if (arg_type == STRING_RESULT) |
|
2440.2.10
by Olaf van der Spek
Use data_ref |
214 |
value[data.size()]= 0; // Store end \0 |
1089.1.5
by Brian Aker
Cleanup of user_var |
215 |
|
2440.2.10
by Olaf van der Spek
Use data_ref |
216 |
memcpy(value, data.data(), data.size()); |
1089.1.5
by Brian Aker
Cleanup of user_var |
217 |
if (arg_type == DECIMAL_RESULT) |
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
218 |
((type::Decimal*)value)->fix_buffer_pointer(); |
2440.2.10
by Olaf van der Spek
Use data_ref |
219 |
length= data.size(); |
1089.1.5
by Brian Aker
Cleanup of user_var |
220 |
collation.set(cs, dv); |
221 |
unsigned_flag= unsigned_arg; |
|
222 |
}
|
|
223 |
type= arg_type; |
|
224 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
225 |
|
226 |
} /* namespace drizzled */ |