17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
22
22
#include <drizzled/function/set_user_var.h>
23
#include <drizzled/function/update_hash.h>
23
24
#include <drizzled/field/num.h>
24
25
#include <drizzled/session.h>
25
#include <drizzled/plugin/client.h>
31
28
When a user variable is updated (in a SET command or a query like
110
107
if ((null_value= args[0]->null_value) && null_item)
111
108
res_type= entry->type; // Don't change type of item
112
if (entry->update_hash((null_value= args[0]->null_value),
113
ptr, length, res_type, cs, dv, unsigned_arg))
109
if (::update_hash(entry, (null_value= args[0]->null_value),
110
ptr, length, res_type, cs, dv, unsigned_arg))
141
138
switch (cached_result_type) {
142
139
case REAL_RESULT:
144
save_result.vreal= use_result_field ? result_field->val_real() :
141
save_result.vreal= use_result_field ? result_field->val_real() :
150
save_result.vint= use_result_field ? result_field->val_int() :
152
unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
153
args[0]->unsigned_flag;
147
save_result.vint= use_result_field ? result_field->val_int() :
149
unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
150
args[0]->unsigned_flag;
156
153
case STRING_RESULT:
158
save_result.vstr= use_result_field ? result_field->val_str_internal(&value) :
159
args[0]->val_str(&value);
155
save_result.vstr= use_result_field ? result_field->val_str(&value) :
156
args[0]->val_str(&value);
162
159
case DECIMAL_RESULT:
164
save_result.vdec= use_result_field ?
165
result_field->val_decimal(&decimal_buff) :
166
args[0]->val_decimal(&decimal_buff);
161
save_result.vdec= use_result_field ?
162
result_field->val_decimal(&decimal_buff) :
163
args[0]->val_decimal(&decimal_buff);
170
168
// This case should never be chosen
198
195
switch (cached_result_type) {
199
196
case REAL_RESULT:
201
res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
202
REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
198
res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
199
REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
208
res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
209
INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
204
res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
205
INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
214
209
case STRING_RESULT:
216
if (!save_result.vstr) // Null value
217
res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
218
DERIVATION_IMPLICIT, 0);
220
res= update_hash((void*) save_result.vstr->ptr(),
221
save_result.vstr->length(), STRING_RESULT,
222
save_result.vstr->charset(),
223
DERIVATION_IMPLICIT, 0);
211
if (!save_result.vstr) // Null value
212
res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
213
DERIVATION_IMPLICIT, 0);
215
res= update_hash((void*) save_result.vstr->ptr(),
216
save_result.vstr->length(), STRING_RESULT,
217
save_result.vstr->charset(),
218
DERIVATION_IMPLICIT, 0);
227
221
case DECIMAL_RESULT:
229
if (!save_result.vdec) // Null value
230
res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
231
DERIVATION_IMPLICIT, 0);
233
res= update_hash((void*) save_result.vdec,
234
sizeof(my_decimal), DECIMAL_RESULT,
235
&my_charset_bin, DERIVATION_IMPLICIT, 0);
223
if (!save_result.vdec) // Null value
224
res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
225
DERIVATION_IMPLICIT, 0);
227
res= update_hash((void*) save_result.vdec,
228
sizeof(my_decimal), DECIMAL_RESULT,
229
&my_charset_bin, DERIVATION_IMPLICIT, 0);
240
234
// This case should never be chosen
320
313
str->append(')');
323
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
317
void Item_func_set_user_var::print_as_stmt(String *str,
318
enum_query_type query_type)
320
str->append(STRING_WITH_LEN("set @"));
321
str->append(name.str, name.length);
322
str->append(STRING_WITH_LEN(":="));
323
args[0]->print(str, query_type);
327
bool Item_func_set_user_var::send(Protocol *protocol, String *str_arg)
325
329
if (result_field)
329
return client->store(result_field);
333
return protocol->store(result_field);
331
return Item::send(client, str_arg);
335
return Item::send(protocol, str_arg);
334
338
void Item_func_set_user_var::make_field(SendField *tmp_field)