~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/set_user_var.cc

  • Committer: Monty Taylor
  • Date: 2009-10-06 19:40:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20091006194045-ojptaq2sx6ck6q63
No more server_includes.h in headers.

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
25
#include <drizzled/plugin/client.h>
26
 
#include <drizzled/user_var_entry.h>
27
26
 
28
 
namespace drizzled
29
 
{
 
27
using namespace drizzled;
30
28
 
31
29
/*
32
30
  When a user variable is updated (in a SET command or a query like
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).
47
45
  */
48
 
  entry->update_query_id= session->getQueryId();
 
46
  entry->update_query_id= session->query_id;
49
47
  /*
50
48
    As it is wrong and confusing to associate any
51
49
    character set with NULL, @a should be latin2
91
89
  if (result_field)
92
90
  {
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
      result_field->table->setReadSet(result_field->field_index);
96
94
  }
97
95
  return 0;
98
96
}
141
139
 
142
140
  switch (cached_result_type) {
143
141
  case REAL_RESULT:
144
 
    {
145
 
      save_result.vreal= use_result_field ? result_field->val_real() :
146
 
        args[0]->val_real();
147
 
      break;
148
 
    }
 
142
  {
 
143
    save_result.vreal= use_result_field ? result_field->val_real() :
 
144
                        args[0]->val_real();
 
145
    break;
 
146
  }
149
147
  case INT_RESULT:
150
 
    {
151
 
      save_result.vint= use_result_field ? result_field->val_int() :
152
 
        args[0]->val_int();
153
 
      unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
154
 
        args[0]->unsigned_flag;
155
 
      break;
156
 
    }
 
148
  {
 
149
    save_result.vint= use_result_field ? result_field->val_int() :
 
150
                       args[0]->val_int();
 
151
    unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
 
152
                    args[0]->unsigned_flag;
 
153
    break;
 
154
  }
157
155
  case STRING_RESULT:
158
 
    {
159
 
      save_result.vstr= use_result_field ? result_field->val_str_internal(&value) :
160
 
        args[0]->val_str(&value);
161
 
      break;
162
 
    }
 
156
  {
 
157
    save_result.vstr= use_result_field ? result_field->val_str(&value) :
 
158
                       args[0]->val_str(&value);
 
159
    break;
 
160
  }
163
161
  case DECIMAL_RESULT:
164
 
    {
165
 
      save_result.vdec= use_result_field ?
166
 
        result_field->val_decimal(&decimal_buff) :
167
 
        args[0]->val_decimal(&decimal_buff);
168
 
      break;
169
 
    }
 
162
  {
 
163
    save_result.vdec= use_result_field ?
 
164
                       result_field->val_decimal(&decimal_buff) :
 
165
                       args[0]->val_decimal(&decimal_buff);
 
166
    break;
 
167
  }
170
168
  case ROW_RESULT:
 
169
  default:
171
170
    // This case should never be chosen
172
171
    assert(0);
173
172
    break;
174
173
  }
175
 
 
176
 
  return false;
 
174
  return(false);
177
175
}
178
176
 
179
177
/**
198
196
 
199
197
  switch (cached_result_type) {
200
198
  case REAL_RESULT:
201
 
    {
202
 
      res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
203
 
                       REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
204
 
      break;
205
 
    }
206
 
 
 
199
  {
 
200
    res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
 
201
                     REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
 
202
    break;
 
203
  }
207
204
  case INT_RESULT:
208
 
    {
209
 
      res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
210
 
                       INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
211
 
                       unsigned_flag);
212
 
      break;
213
 
    }
214
 
 
 
205
  {
 
206
    res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
 
207
                     INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
 
208
                     unsigned_flag);
 
209
    break;
 
210
  }
215
211
  case STRING_RESULT:
216
 
    {
217
 
      if (!save_result.vstr)                                      // Null value
218
 
        res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
219
 
                         DERIVATION_IMPLICIT, 0);
220
 
      else
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);
225
 
      break;
226
 
    }
227
 
 
 
212
  {
 
213
    if (!save_result.vstr)                                      // Null value
 
214
      res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
 
215
                       DERIVATION_IMPLICIT, 0);
 
216
    else
 
217
      res= update_hash((void*) save_result.vstr->ptr(),
 
218
                       save_result.vstr->length(), STRING_RESULT,
 
219
                       save_result.vstr->charset(),
 
220
                       DERIVATION_IMPLICIT, 0);
 
221
    break;
 
222
  }
228
223
  case DECIMAL_RESULT:
229
 
    {
230
 
      if (!save_result.vdec)                                      // Null value
231
 
        res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
232
 
                         DERIVATION_IMPLICIT, 0);
233
 
      else
234
 
        res= update_hash((void*) save_result.vdec,
235
 
                         sizeof(type::Decimal), DECIMAL_RESULT,
236
 
                         &my_charset_bin, DERIVATION_IMPLICIT, 0);
237
 
      break;
238
 
    }
239
 
 
 
224
  {
 
225
    if (!save_result.vdec)                                      // Null value
 
226
      res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
 
227
                       DERIVATION_IMPLICIT, 0);
 
228
    else
 
229
      res= update_hash((void*) save_result.vdec,
 
230
                       sizeof(my_decimal), DECIMAL_RESULT,
 
231
                       &my_charset_bin, DERIVATION_IMPLICIT, 0);
 
232
    break;
 
233
  }
240
234
  case ROW_RESULT:
 
235
  default:
241
236
    // This case should never be chosen
242
237
    assert(0);
243
238
    break;
244
239
  }
245
 
 
246
240
  return(res);
247
241
}
248
242
 
271
265
}
272
266
 
273
267
 
274
 
type::Decimal *Item_func_set_user_var::val_decimal(type::Decimal *val)
 
268
my_decimal *Item_func_set_user_var::val_decimal(my_decimal *val)
275
269
{
276
270
  assert(fixed == 1);
277
271
  check(0);
304
298
}
305
299
 
306
300
 
307
 
type::Decimal *Item_func_set_user_var::val_decimal_result(type::Decimal *val)
 
301
my_decimal *Item_func_set_user_var::val_decimal_result(my_decimal *val)
308
302
{
309
303
  assert(fixed == 1);
310
304
  check(true);
321
315
  str->append(')');
322
316
}
323
317
 
 
318
 
 
319
void Item_func_set_user_var::print_as_stmt(String *str,
 
320
                                           enum_query_type query_type)
 
321
{
 
322
  str->append(STRING_WITH_LEN("set @"));
 
323
  str->append(name.str, name.length);
 
324
  str->append(STRING_WITH_LEN(":="));
 
325
  args[0]->print(str, query_type);
 
326
  str->append(')');
 
327
}
 
328
 
324
329
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
325
330
{
326
331
  if (result_field)
342
347
      tmp_field->col_name=Item::name;               // Use user supplied name
343
348
  }
344
349
  else
345
 
  {
346
350
    Item::make_field(tmp_field);
347
 
  }
348
351
}
349
352
 
350
353
/*
427
430
  }
428
431
  else if (result_type() == DECIMAL_RESULT)
429
432
  {
430
 
    type::Decimal decimal_value;
431
 
    type::Decimal *val= entry->val_decimal(&null_value, &decimal_value);
 
433
    my_decimal decimal_value;
 
434
    my_decimal *val= entry->val_decimal(&null_value, &decimal_value);
432
435
    if (null_value)
433
436
      return set_field_to_null(field);
434
437
    field->set_notnull();
446
449
}
447
450
 
448
451
 
449
 
} /* namespace drizzled */