~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/set_user_var.cc

  • Committer: Brian Aker
  • Date: 2009-08-04 06:21:17 UTC
  • mfrom: (1108.2.2 merge)
  • Revision ID: brian@gaz-20090804062117-fef8x6y3ydzrvab3
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/function/set_user_var.h>
23
23
#include <drizzled/field/num.h>
24
24
#include <drizzled/session.h>
25
 
#include <drizzled/plugin/client.h>
26
 
 
27
 
namespace drizzled
28
 
{
29
25
 
30
26
/*
31
27
  When a user variable is updated (in a SET command or a query like
44
40
     if this variable is a constant item in the query (it is if update_query_id
45
41
     is different from query_id).
46
42
  */
47
 
  entry->update_query_id= session->getQueryId();
 
43
  entry->update_query_id= session->query_id;
48
44
  /*
49
45
    As it is wrong and confusing to associate any
50
46
    character set with NULL, @a should be latin2
90
86
  if (result_field)
91
87
  {
92
88
    Table *table= (Table *) arg;
93
 
    if (result_field->getTable() == table || !table)
94
 
      result_field->getTable()->setReadSet(result_field->position());
 
89
    if (result_field->table == table || !table)
 
90
      result_field->table->setReadSet(result_field->field_index);
95
91
  }
96
92
  return 0;
97
93
}
140
136
 
141
137
  switch (cached_result_type) {
142
138
  case REAL_RESULT:
143
 
    {
144
 
      save_result.vreal= use_result_field ? result_field->val_real() :
145
 
        args[0]->val_real();
146
 
      break;
147
 
    }
 
139
  {
 
140
    save_result.vreal= use_result_field ? result_field->val_real() :
 
141
                        args[0]->val_real();
 
142
    break;
 
143
  }
148
144
  case INT_RESULT:
149
 
    {
150
 
      save_result.vint= use_result_field ? result_field->val_int() :
151
 
        args[0]->val_int();
152
 
      unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
153
 
        args[0]->unsigned_flag;
154
 
      break;
155
 
    }
 
145
  {
 
146
    save_result.vint= use_result_field ? result_field->val_int() :
 
147
                       args[0]->val_int();
 
148
    unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
 
149
                    args[0]->unsigned_flag;
 
150
    break;
 
151
  }
156
152
  case STRING_RESULT:
157
 
    {
158
 
      save_result.vstr= use_result_field ? result_field->val_str_internal(&value) :
159
 
        args[0]->val_str(&value);
160
 
      break;
161
 
    }
 
153
  {
 
154
    save_result.vstr= use_result_field ? result_field->val_str(&value) :
 
155
                       args[0]->val_str(&value);
 
156
    break;
 
157
  }
162
158
  case DECIMAL_RESULT:
163
 
    {
164
 
      save_result.vdec= use_result_field ?
165
 
        result_field->val_decimal(&decimal_buff) :
166
 
        args[0]->val_decimal(&decimal_buff);
167
 
      break;
168
 
    }
 
159
  {
 
160
    save_result.vdec= use_result_field ?
 
161
                       result_field->val_decimal(&decimal_buff) :
 
162
                       args[0]->val_decimal(&decimal_buff);
 
163
    break;
 
164
  }
169
165
  case ROW_RESULT:
 
166
  default:
170
167
    // This case should never be chosen
171
168
    assert(0);
172
169
    break;
173
170
  }
174
 
 
175
 
  return false;
 
171
  return(false);
176
172
}
177
173
 
178
174
/**
197
193
 
198
194
  switch (cached_result_type) {
199
195
  case REAL_RESULT:
200
 
    {
201
 
      res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
202
 
                       REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
203
 
      break;
204
 
    }
205
 
 
 
196
  {
 
197
    res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
 
198
                     REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
 
199
    break;
 
200
  }
206
201
  case INT_RESULT:
207
 
    {
208
 
      res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
209
 
                       INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
210
 
                       unsigned_flag);
211
 
      break;
212
 
    }
213
 
 
 
202
  {
 
203
    res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
 
204
                     INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
 
205
                     unsigned_flag);
 
206
    break;
 
207
  }
214
208
  case STRING_RESULT:
215
 
    {
216
 
      if (!save_result.vstr)                                      // Null value
217
 
        res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
218
 
                         DERIVATION_IMPLICIT, 0);
219
 
      else
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);
224
 
      break;
225
 
    }
226
 
 
 
209
  {
 
210
    if (!save_result.vstr)                                      // Null value
 
211
      res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
 
212
                       DERIVATION_IMPLICIT, 0);
 
213
    else
 
214
      res= update_hash((void*) save_result.vstr->ptr(),
 
215
                       save_result.vstr->length(), STRING_RESULT,
 
216
                       save_result.vstr->charset(),
 
217
                       DERIVATION_IMPLICIT, 0);
 
218
    break;
 
219
  }
227
220
  case DECIMAL_RESULT:
228
 
    {
229
 
      if (!save_result.vdec)                                      // Null value
230
 
        res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
231
 
                         DERIVATION_IMPLICIT, 0);
232
 
      else
233
 
        res= update_hash((void*) save_result.vdec,
234
 
                         sizeof(type::Decimal), DECIMAL_RESULT,
235
 
                         &my_charset_bin, DERIVATION_IMPLICIT, 0);
236
 
      break;
237
 
    }
238
 
 
 
221
  {
 
222
    if (!save_result.vdec)                                      // Null value
 
223
      res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
 
224
                       DERIVATION_IMPLICIT, 0);
 
225
    else
 
226
      res= update_hash((void*) save_result.vdec,
 
227
                       sizeof(my_decimal), DECIMAL_RESULT,
 
228
                       &my_charset_bin, DERIVATION_IMPLICIT, 0);
 
229
    break;
 
230
  }
239
231
  case ROW_RESULT:
 
232
  default:
240
233
    // This case should never be chosen
241
234
    assert(0);
242
235
    break;
243
236
  }
244
 
 
245
237
  return(res);
246
238
}
247
239
 
270
262
}
271
263
 
272
264
 
273
 
type::Decimal *Item_func_set_user_var::val_decimal(type::Decimal *val)
 
265
my_decimal *Item_func_set_user_var::val_decimal(my_decimal *val)
274
266
{
275
267
  assert(fixed == 1);
276
268
  check(0);
303
295
}
304
296
 
305
297
 
306
 
type::Decimal *Item_func_set_user_var::val_decimal_result(type::Decimal *val)
 
298
my_decimal *Item_func_set_user_var::val_decimal_result(my_decimal *val)
307
299
{
308
300
  assert(fixed == 1);
309
301
  check(true);
320
312
  str->append(')');
321
313
}
322
314
 
323
 
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
 
315
 
 
316
void Item_func_set_user_var::print_as_stmt(String *str,
 
317
                                           enum_query_type query_type)
 
318
{
 
319
  str->append(STRING_WITH_LEN("set @"));
 
320
  str->append(name.str, name.length);
 
321
  str->append(STRING_WITH_LEN(":="));
 
322
  args[0]->print(str, query_type);
 
323
  str->append(')');
 
324
}
 
325
 
 
326
bool Item_func_set_user_var::send(Protocol *protocol, String *str_arg)
324
327
{
325
328
  if (result_field)
326
329
  {
327
330
    check(1);
328
331
    update();
329
 
    return client->store(result_field);
 
332
    return protocol->store(result_field);
330
333
  }
331
 
  return Item::send(client, str_arg);
 
334
  return Item::send(protocol, str_arg);
332
335
}
333
336
 
334
337
void Item_func_set_user_var::make_field(SendField *tmp_field)
341
344
      tmp_field->col_name=Item::name;               // Use user supplied name
342
345
  }
343
346
  else
344
 
  {
345
347
    Item::make_field(tmp_field);
346
 
  }
347
348
}
348
349
 
349
350
/*
426
427
  }
427
428
  else if (result_type() == DECIMAL_RESULT)
428
429
  {
429
 
    type::Decimal decimal_value;
430
 
    type::Decimal *val= entry->val_decimal(&null_value, &decimal_value);
 
430
    my_decimal decimal_value;
 
431
    my_decimal *val= entry->val_decimal(&null_value, &decimal_value);
431
432
    if (null_value)
432
433
      return set_field_to_null(field);
433
434
    field->set_notnull();
445
446
}
446
447
 
447
448
 
448
 
} /* namespace drizzled */