~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/set_user_var.cc

  • Committer: Stewart Smith
  • Date: 2009-06-16 03:43:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: stewart@flamingspork.com-20090616034300-bamg5dsfaknwi05b
fix join_outer for MyISAM as temp only: 1x open table twice, 1x CREATE TEMP

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