~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-09-22 21:56:03 UTC
  • mto: This revision was merged to the branch mainline in revision 1144.
  • Revision ID: mordred@inaugust.com-20090922215603-yf2itjcwbndu2m4k
pandora-build v0.62 - cleaned up some copyright header mistakes. Merged in trond's innodb detection.

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"
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
25
 
27
 
namespace drizzled
28
 
{
 
26
using namespace drizzled;
29
27
 
30
28
/*
31
29
  When a user variable is updated (in a SET command or a query like
44
42
     if this variable is a constant item in the query (it is if update_query_id
45
43
     is different from query_id).
46
44
  */
47
 
  entry->update_query_id= session->getQueryId();
 
45
  entry->update_query_id= session->query_id;
48
46
  /*
49
47
    As it is wrong and confusing to associate any
50
48
    character set with NULL, @a should be latin2
90
88
  if (result_field)
91
89
  {
92
90
    Table *table= (Table *) arg;
93
 
    if (result_field->getTable() == table || !table)
94
 
      result_field->getTable()->setReadSet(result_field->position());
 
91
    if (result_field->table == table || !table)
 
92
      result_field->table->setReadSet(result_field->field_index);
95
93
  }
96
94
  return 0;
97
95
}
140
138
 
141
139
  switch (cached_result_type) {
142
140
  case REAL_RESULT:
143
 
    {
144
 
      save_result.vreal= use_result_field ? result_field->val_real() :
145
 
        args[0]->val_real();
146
 
      break;
147
 
    }
 
141
  {
 
142
    save_result.vreal= use_result_field ? result_field->val_real() :
 
143
                        args[0]->val_real();
 
144
    break;
 
145
  }
148
146
  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
 
    }
 
147
  {
 
148
    save_result.vint= use_result_field ? result_field->val_int() :
 
149
                       args[0]->val_int();
 
150
    unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
 
151
                    args[0]->unsigned_flag;
 
152
    break;
 
153
  }
156
154
  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
 
    }
 
155
  {
 
156
    save_result.vstr= use_result_field ? result_field->val_str(&value) :
 
157
                       args[0]->val_str(&value);
 
158
    break;
 
159
  }
162
160
  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
 
    }
 
161
  {
 
162
    save_result.vdec= use_result_field ?
 
163
                       result_field->val_decimal(&decimal_buff) :
 
164
                       args[0]->val_decimal(&decimal_buff);
 
165
    break;
 
166
  }
169
167
  case ROW_RESULT:
 
168
  default:
170
169
    // This case should never be chosen
171
170
    assert(0);
172
171
    break;
173
172
  }
174
 
 
175
 
  return false;
 
173
  return(false);
176
174
}
177
175
 
178
176
/**
197
195
 
198
196
  switch (cached_result_type) {
199
197
  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
 
 
 
198
  {
 
199
    res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
 
200
                     REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
 
201
    break;
 
202
  }
206
203
  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
 
 
 
204
  {
 
205
    res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
 
206
                     INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
 
207
                     unsigned_flag);
 
208
    break;
 
209
  }
214
210
  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
 
 
 
211
  {
 
212
    if (!save_result.vstr)                                      // Null value
 
213
      res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
 
214
                       DERIVATION_IMPLICIT, 0);
 
215
    else
 
216
      res= update_hash((void*) save_result.vstr->ptr(),
 
217
                       save_result.vstr->length(), STRING_RESULT,
 
218
                       save_result.vstr->charset(),
 
219
                       DERIVATION_IMPLICIT, 0);
 
220
    break;
 
221
  }
227
222
  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(my_decimal), DECIMAL_RESULT,
235
 
                         &my_charset_bin, DERIVATION_IMPLICIT, 0);
236
 
      break;
237
 
    }
238
 
 
 
223
  {
 
224
    if (!save_result.vdec)                                      // Null value
 
225
      res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
 
226
                       DERIVATION_IMPLICIT, 0);
 
227
    else
 
228
      res= update_hash((void*) save_result.vdec,
 
229
                       sizeof(my_decimal), DECIMAL_RESULT,
 
230
                       &my_charset_bin, DERIVATION_IMPLICIT, 0);
 
231
    break;
 
232
  }
239
233
  case ROW_RESULT:
 
234
  default:
240
235
    // This case should never be chosen
241
236
    assert(0);
242
237
    break;
243
238
  }
244
 
 
245
239
  return(res);
246
240
}
247
241
 
320
314
  str->append(')');
321
315
}
322
316
 
323
 
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
 
317
 
 
318
void Item_func_set_user_var::print_as_stmt(String *str,
 
319
                                           enum_query_type query_type)
 
320
{
 
321
  str->append(STRING_WITH_LEN("set @"));
 
322
  str->append(name.str, name.length);
 
323
  str->append(STRING_WITH_LEN(":="));
 
324
  args[0]->print(str, query_type);
 
325
  str->append(')');
 
326
}
 
327
 
 
328
bool Item_func_set_user_var::send(plugin::Protocol *protocol, String *str_arg)
324
329
{
325
330
  if (result_field)
326
331
  {
327
332
    check(1);
328
333
    update();
329
 
    return client->store(result_field);
 
334
    return protocol->store(result_field);
330
335
  }
331
 
  return Item::send(client, str_arg);
 
336
  return Item::send(protocol, str_arg);
332
337
}
333
338
 
334
339
void Item_func_set_user_var::make_field(SendField *tmp_field)
443
448
}
444
449
 
445
450
 
446
 
} /* namespace drizzled */