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/get_variable.h>
24
#include <drizzled/function/update_hash.h>
23
25
#include <drizzled/field/num.h>
26
#include <drizzled/virtual_column_info.h>
24
27
#include <drizzled/session.h>
25
#include <drizzled/plugin/client.h>
26
#include <drizzled/user_var_entry.h>
32
30
When a user variable is updated (in a SET command or a query like
38
36
assert(fixed == 0);
39
37
/* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
40
38
if (Item_func::fix_fields(session, ref) ||
41
!(entry= session->getVariable(name, true)))
39
!(entry= get_variable(&session->user_vars, name, 1)))
44
42
Remember the last query which updated it, this way a query can later know
45
43
if this variable is a constant item in the query (it is if update_query_id
46
44
is different from query_id).
48
entry->update_query_id= session->getQueryId();
46
entry->update_query_id= session->query_id;
50
48
As it is wrong and confusing to associate any
51
49
character set with NULL, @a should be latin2
93
91
Table *table= (Table *) arg;
94
if (result_field->getTable() == table || !table)
95
result_field->getTable()->setReadSet(result_field->position());
92
if (result_field->table == table || !table)
93
bitmap_set_bit(result_field->table->read_set, result_field->field_index);
94
if (result_field->vcol_info && result_field->vcol_info->expr_item)
95
return result_field->vcol_info->
96
expr_item->walk(&Item::register_field_in_read_map, 1, arg);
102
Mark field in bitmap supplied as *arg
106
bool Item_func_set_user_var::register_field_in_bitmap(unsigned char *arg)
108
MY_BITMAP *bitmap = (MY_BITMAP *) arg;
112
bitmap_set_bit(bitmap, result_field->field_index);
102
118
Item_func_set_user_var::update_hash(void *ptr, uint32_t length,
111
127
if ((null_value= args[0]->null_value) && null_item)
112
128
res_type= entry->type; // Don't change type of item
113
if (entry->update_hash((null_value= args[0]->null_value),
114
ptr, length, res_type, cs, dv, unsigned_arg))
129
if (::update_hash(entry, (null_value= args[0]->null_value),
130
ptr, length, res_type, cs, dv, unsigned_arg))
142
158
switch (cached_result_type) {
143
159
case REAL_RESULT:
145
save_result.vreal= use_result_field ? result_field->val_real() :
161
save_result.vreal= use_result_field ? result_field->val_real() :
151
save_result.vint= use_result_field ? result_field->val_int() :
153
unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
154
args[0]->unsigned_flag;
167
save_result.vint= use_result_field ? result_field->val_int() :
169
unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
170
args[0]->unsigned_flag;
157
173
case STRING_RESULT:
159
save_result.vstr= use_result_field ? result_field->val_str_internal(&value) :
160
args[0]->val_str(&value);
175
save_result.vstr= use_result_field ? result_field->val_str(&value) :
176
args[0]->val_str(&value);
163
179
case DECIMAL_RESULT:
165
save_result.vdec= use_result_field ?
166
result_field->val_decimal(&decimal_buff) :
167
args[0]->val_decimal(&decimal_buff);
181
save_result.vdec= use_result_field ?
182
result_field->val_decimal(&decimal_buff) :
183
args[0]->val_decimal(&decimal_buff);
171
188
// This case should never be chosen
199
215
switch (cached_result_type) {
200
216
case REAL_RESULT:
202
res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
203
REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
218
res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
219
REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
209
res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
210
INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
224
res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
225
INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
215
229
case STRING_RESULT:
217
if (!save_result.vstr) // Null value
218
res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
219
DERIVATION_IMPLICIT, 0);
221
res= update_hash((void*) save_result.vstr->ptr(),
222
save_result.vstr->length(), STRING_RESULT,
223
save_result.vstr->charset(),
224
DERIVATION_IMPLICIT, 0);
231
if (!save_result.vstr) // Null value
232
res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
233
DERIVATION_IMPLICIT, 0);
235
res= update_hash((void*) save_result.vstr->ptr(),
236
save_result.vstr->length(), STRING_RESULT,
237
save_result.vstr->charset(),
238
DERIVATION_IMPLICIT, 0);
228
241
case DECIMAL_RESULT:
230
if (!save_result.vdec) // Null value
231
res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
232
DERIVATION_IMPLICIT, 0);
234
res= update_hash((void*) save_result.vdec,
235
sizeof(type::Decimal), DECIMAL_RESULT,
236
&my_charset_bin, DERIVATION_IMPLICIT, 0);
243
if (!save_result.vdec) // Null value
244
res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
245
DERIVATION_IMPLICIT, 0);
247
res= update_hash((void*) save_result.vdec,
248
sizeof(my_decimal), DECIMAL_RESULT,
249
&my_charset_bin, DERIVATION_IMPLICIT, 0);
241
254
// This case should never be chosen
321
333
str->append(')');
324
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
337
void Item_func_set_user_var::print_as_stmt(String *str,
338
enum_query_type query_type)
340
str->append(STRING_WITH_LEN("set @"));
341
str->append(name.str, name.length);
342
str->append(STRING_WITH_LEN(":="));
343
args[0]->print(str, query_type);
347
bool Item_func_set_user_var::send(Protocol *protocol, String *str_arg)
326
349
if (result_field)
330
return client->store(result_field);
353
return protocol->store(result_field);
332
return Item::send(client, str_arg);
355
return Item::send(protocol, str_arg);
335
void Item_func_set_user_var::make_field(SendField *tmp_field)
358
void Item_func_set_user_var::make_field(Send_field *tmp_field)
337
360
if (result_field)