~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/set_user_var.cc

  • Committer: Olaf van der Spek
  • Date: 2011-04-05 12:26:58 UTC
  • mto: (2278.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2272.
  • Revision ID: olafvdspek@gmail.com-20110405122658-xxrvmobwwwwf3oct
Refactor Open_tables_state

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/plugin/client.h>
26
26
#include <drizzled/user_var_entry.h>
 
27
#include <drizzled/table.h>
27
28
 
28
 
namespace drizzled
29
 
{
 
29
namespace drizzled {
30
30
 
31
31
/*
32
32
  When a user variable is updated (in a SET command or a query like
98
98
}
99
99
 
100
100
 
101
 
bool
 
101
void
102
102
Item_func_set_user_var::update_hash(void *ptr, uint32_t length,
103
103
                                    Item_result res_type,
104
 
                                    const CHARSET_INFO * const cs, Derivation dv,
 
104
                                    const charset_info_st * const cs, Derivation dv,
105
105
                                    bool unsigned_arg)
106
106
{
107
107
  /*
110
110
  */
111
111
  if ((null_value= args[0]->null_value) && null_item)
112
112
    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))
115
 
  {
116
 
    null_value= 1;
117
 
    return 1;
118
 
  }
119
 
  return 0;
 
113
  entry->update_hash((null_value= args[0]->null_value), ptr, length, res_type, cs, dv, unsigned_arg);
120
114
}
121
115
 
122
116
/**
191
185
 
192
186
*/
193
187
 
194
 
bool
 
188
void
195
189
Item_func_set_user_var::update()
196
190
{
197
 
  bool res= false;
198
 
 
199
191
  switch (cached_result_type) {
200
192
  case REAL_RESULT:
201
193
    {
202
 
      res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
 
194
      update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
203
195
                       REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
204
196
      break;
205
197
    }
206
198
 
207
199
  case INT_RESULT:
208
200
    {
209
 
      res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
 
201
      update_hash((void*) &save_result.vint, sizeof(save_result.vint),
210
202
                       INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
211
203
                       unsigned_flag);
212
204
      break;
215
207
  case STRING_RESULT:
216
208
    {
217
209
      if (!save_result.vstr)                                      // Null value
218
 
        res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
 
210
        update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
219
211
                         DERIVATION_IMPLICIT, 0);
220
212
      else
221
 
        res= update_hash((void*) save_result.vstr->ptr(),
 
213
        update_hash((void*) save_result.vstr->ptr(),
222
214
                         save_result.vstr->length(), STRING_RESULT,
223
215
                         save_result.vstr->charset(),
224
216
                         DERIVATION_IMPLICIT, 0);
228
220
  case DECIMAL_RESULT:
229
221
    {
230
222
      if (!save_result.vdec)                                      // Null value
231
 
        res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
 
223
        update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
232
224
                         DERIVATION_IMPLICIT, 0);
233
225
      else
234
 
        res= update_hash((void*) save_result.vdec,
 
226
        update_hash((void*) save_result.vdec,
235
227
                         sizeof(type::Decimal), DECIMAL_RESULT,
236
228
                         &my_charset_bin, DERIVATION_IMPLICIT, 0);
237
229
      break;
242
234
    assert(0);
243
235
    break;
244
236
  }
245
 
 
246
 
  return(res);
247
237
}
248
238
 
249
239
double Item_func_set_user_var::val_real()
312
302
  return entry->val_decimal(&null_value, val);
313
303
}
314
304
 
315
 
void Item_func_set_user_var::print(String *str, enum_query_type query_type)
 
305
void Item_func_set_user_var::print(String *str)
316
306
{
317
307
  str->append(STRING_WITH_LEN("(@"));
318
308
  str->append(name.str, name.length);
319
309
  str->append(STRING_WITH_LEN(":="));
320
 
  args[0]->print(str, query_type);
 
310
  args[0]->print(str);
321
311
  str->append(')');
322
312
}
323
313
 
400
390
      (result_type() == REAL_RESULT && field->result_type() == STRING_RESULT))
401
391
  {
402
392
    String *result;
403
 
    const CHARSET_INFO * const cs= collation.collation;
 
393
    const charset_info_st * const cs= collation.collation;
404
394
    char buff[MAX_FIELD_WIDTH];         // Alloc buffer for small columns
405
395
    str_value.set_quick(buff, sizeof(buff), cs);
406
396
    result= entry->val_str(&null_value, &str_value, decimals);