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>
31
30
When a user variable is updated (in a SET command or a query like
37
36
assert(fixed == 0);
38
37
/* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
39
38
if (Item_func::fix_fields(session, ref) ||
40
!(entry= session->getVariable(name, true)))
39
!(entry= get_variable(&session->user_vars, name, 1)))
43
42
Remember the last query which updated it, this way a query can later know
44
43
if this variable is a constant item in the query (it is if update_query_id
45
44
is different from query_id).
47
entry->update_query_id= session->getQueryId();
46
entry->update_query_id= session->query_id;
49
48
As it is wrong and confusing to associate any
50
49
character set with NULL, @a should be latin2
92
91
Table *table= (Table *) arg;
93
if (result_field->getTable() == table || !table)
94
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);
101
118
Item_func_set_user_var::update_hash(void *ptr, uint32_t length,
110
127
if ((null_value= args[0]->null_value) && null_item)
111
128
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))
129
if (::update_hash(entry, (null_value= args[0]->null_value),
130
ptr, length, res_type, cs, dv, unsigned_arg))
141
158
switch (cached_result_type) {
142
159
case REAL_RESULT:
144
save_result.vreal= use_result_field ? result_field->val_real() :
161
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;
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;
156
173
case STRING_RESULT:
158
save_result.vstr= use_result_field ? result_field->val_str_internal(&value) :
159
args[0]->val_str(&value);
175
save_result.vstr= use_result_field ? result_field->val_str(&value) :
176
args[0]->val_str(&value);
162
179
case DECIMAL_RESULT:
164
save_result.vdec= use_result_field ?
165
result_field->val_decimal(&decimal_buff) :
166
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);
170
188
// This case should never be chosen
198
215
switch (cached_result_type) {
199
216
case REAL_RESULT:
201
res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
202
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);
208
res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
209
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,
214
229
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);
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);
227
241
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(type::Decimal), DECIMAL_RESULT,
235
&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);
240
254
// This case should never be chosen
320
333
str->append(')');
323
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)
325
349
if (result_field)
329
return client->store(result_field);
353
return protocol->store(result_field);
331
return Item::send(client, str_arg);
355
return Item::send(protocol, str_arg);
334
void Item_func_set_user_var::make_field(SendField *tmp_field)
358
void Item_func_set_user_var::make_field(Send_field *tmp_field)
336
360
if (result_field)