~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/set_user_var.cc

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
mergeĀ lp:~olafvdspek/drizzle/refactor4

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <config.h>
21
21
 
22
22
#include <drizzled/function/set_user_var.h>
23
23
#include <drizzled/field/num.h>
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/plugin/client.h>
 
26
#include <drizzled/user_var_entry.h>
 
27
#include <drizzled/table.h>
26
28
 
27
 
namespace drizzled
28
 
{
 
29
namespace drizzled {
29
30
 
30
31
/*
31
32
  When a user variable is updated (in a SET command or a query like
97
98
}
98
99
 
99
100
 
100
 
bool
 
101
void
101
102
Item_func_set_user_var::update_hash(void *ptr, uint32_t length,
102
103
                                    Item_result res_type,
103
 
                                    const CHARSET_INFO * const cs, Derivation dv,
 
104
                                    const charset_info_st * const cs, Derivation dv,
104
105
                                    bool unsigned_arg)
105
106
{
106
107
  /*
109
110
  */
110
111
  if ((null_value= args[0]->null_value) && null_item)
111
112
    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))
114
 
  {
115
 
    null_value= 1;
116
 
    return 1;
117
 
  }
118
 
  return 0;
 
113
  entry->update_hash((null_value= args[0]->null_value), ptr, length, res_type, cs, dv, unsigned_arg);
119
114
}
120
115
 
121
116
/**
149
144
    {
150
145
      save_result.vint= use_result_field ? result_field->val_int() :
151
146
        args[0]->val_int();
 
147
 
152
148
      unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
153
149
        args[0]->unsigned_flag;
 
150
 
154
151
      break;
155
152
    }
156
153
  case STRING_RESULT:
190
187
 
191
188
*/
192
189
 
193
 
bool
 
190
void
194
191
Item_func_set_user_var::update()
195
192
{
196
 
  bool res= false;
197
 
 
198
193
  switch (cached_result_type) {
199
194
  case REAL_RESULT:
200
195
    {
201
 
      res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
 
196
      update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
202
197
                       REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
203
198
      break;
204
199
    }
205
200
 
206
201
  case INT_RESULT:
207
202
    {
208
 
      res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
 
203
      update_hash((void*) &save_result.vint, sizeof(save_result.vint),
209
204
                       INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
210
205
                       unsigned_flag);
211
206
      break;
214
209
  case STRING_RESULT:
215
210
    {
216
211
      if (!save_result.vstr)                                      // Null value
217
 
        res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
 
212
        update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
218
213
                         DERIVATION_IMPLICIT, 0);
219
214
      else
220
 
        res= update_hash((void*) save_result.vstr->ptr(),
 
215
        update_hash((void*) save_result.vstr->ptr(),
221
216
                         save_result.vstr->length(), STRING_RESULT,
222
217
                         save_result.vstr->charset(),
223
218
                         DERIVATION_IMPLICIT, 0);
227
222
  case DECIMAL_RESULT:
228
223
    {
229
224
      if (!save_result.vdec)                                      // Null value
230
 
        res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
 
225
        update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
231
226
                         DERIVATION_IMPLICIT, 0);
232
227
      else
233
 
        res= update_hash((void*) save_result.vdec,
 
228
        update_hash((void*) save_result.vdec,
234
229
                         sizeof(type::Decimal), DECIMAL_RESULT,
235
230
                         &my_charset_bin, DERIVATION_IMPLICIT, 0);
236
231
      break;
241
236
    assert(0);
242
237
    break;
243
238
  }
244
 
 
245
 
  return(res);
246
239
}
247
240
 
248
241
double Item_func_set_user_var::val_real()
311
304
  return entry->val_decimal(&null_value, val);
312
305
}
313
306
 
314
 
void Item_func_set_user_var::print(String *str, enum_query_type query_type)
 
307
void Item_func_set_user_var::print(String *str)
315
308
{
316
309
  str->append(STRING_WITH_LEN("(@"));
317
310
  str->append(name.str, name.length);
318
311
  str->append(STRING_WITH_LEN(":="));
319
 
  args[0]->print(str, query_type);
 
312
  args[0]->print(str);
320
313
  str->append(')');
321
314
}
322
315
 
323
 
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
 
316
void Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
324
317
{
325
318
  if (result_field)
326
319
  {
327
320
    check(1);
328
321
    update();
329
 
    return client->store(result_field);
 
322
    client->store(result_field);
 
323
    return;
330
324
  }
331
 
  return Item::send(client, str_arg);
 
325
  Item::send(client, str_arg);
332
326
}
333
327
 
334
328
void Item_func_set_user_var::make_field(SendField *tmp_field)
399
393
      (result_type() == REAL_RESULT && field->result_type() == STRING_RESULT))
400
394
  {
401
395
    String *result;
402
 
    const CHARSET_INFO * const cs= collation.collation;
 
396
    const charset_info_st * const cs= collation.collation;
403
397
    char buff[MAX_FIELD_WIDTH];         // Alloc buffer for small columns
404
398
    str_value.set_quick(buff, sizeof(buff), cs);
405
399
    result= entry->val_str(&null_value, &str_value, decimals);