~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-05-06 06:19:18 UTC
  • mto: This revision was merged to the branch mainline in revision 1007.
  • Revision ID: brian@gaz-20090506061918-3p5x847pn9cdruog
Clean up final  code bits (from previous builds).

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
 
{
 
26
 
 
27
#include <bitset>
 
28
 
 
29
using namespace std;
29
30
 
30
31
/*
31
32
  When a user variable is updated (in a SET command or a query like
44
45
     if this variable is a constant item in the query (it is if update_query_id
45
46
     is different from query_id).
46
47
  */
47
 
  entry->update_query_id= session->getQueryId();
 
48
  entry->update_query_id= session->query_id;
48
49
  /*
49
50
    As it is wrong and confusing to associate any
50
51
    character set with NULL, @a should be latin2
90
91
  if (result_field)
91
92
  {
92
93
    Table *table= (Table *) arg;
93
 
    if (result_field->getTable() == table || !table)
94
 
      result_field->getTable()->setReadSet(result_field->position());
95
 
  }
96
 
  return 0;
97
 
}
98
 
 
 
94
    if (result_field->table == table || !table)
 
95
      result_field->table->read_set->set(result_field->field_index);
 
96
  }
 
97
  return 0;
 
98
}
 
99
 
 
100
/*
 
101
  Mark field in bitmap supplied as *arg
 
102
 
 
103
*/
 
104
 
 
105
bool Item_func_set_user_var::register_field_in_bitmap(unsigned char *arg)
 
106
{
 
107
  bitset<MAX_FIELDS> *bitmap = (bitset<MAX_FIELDS> *) arg;
 
108
  assert(bitmap);
 
109
  if (result_field)
 
110
  {
 
111
    bitmap->set(result_field->field_index);
 
112
  }
 
113
  return 0;
 
114
}
99
115
 
100
116
bool
101
117
Item_func_set_user_var::update_hash(void *ptr, uint32_t length,
109
125
  */
110
126
  if ((null_value= args[0]->null_value) && null_item)
111
127
    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))
 
128
  if (::update_hash(entry, (null_value= args[0]->null_value),
 
129
                    ptr, length, res_type, cs, dv, unsigned_arg))
114
130
  {
115
131
    null_value= 1;
116
132
    return 1;
140
156
 
141
157
  switch (cached_result_type) {
142
158
  case REAL_RESULT:
143
 
    {
144
 
      save_result.vreal= use_result_field ? result_field->val_real() :
145
 
        args[0]->val_real();
146
 
      break;
147
 
    }
 
159
  {
 
160
    save_result.vreal= use_result_field ? result_field->val_real() :
 
161
                        args[0]->val_real();
 
162
    break;
 
163
  }
148
164
  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
 
    }
 
165
  {
 
166
    save_result.vint= use_result_field ? result_field->val_int() :
 
167
                       args[0]->val_int();
 
168
    unsigned_flag= use_result_field ? ((Field_num*)result_field)->unsigned_flag:
 
169
                    args[0]->unsigned_flag;
 
170
    break;
 
171
  }
156
172
  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
 
    }
 
173
  {
 
174
    save_result.vstr= use_result_field ? result_field->val_str(&value) :
 
175
                       args[0]->val_str(&value);
 
176
    break;
 
177
  }
162
178
  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
 
    }
 
179
  {
 
180
    save_result.vdec= use_result_field ?
 
181
                       result_field->val_decimal(&decimal_buff) :
 
182
                       args[0]->val_decimal(&decimal_buff);
 
183
    break;
 
184
  }
169
185
  case ROW_RESULT:
 
186
  default:
170
187
    // This case should never be chosen
171
188
    assert(0);
172
189
    break;
173
190
  }
174
 
 
175
 
  return false;
 
191
  return(false);
176
192
}
177
193
 
178
194
/**
197
213
 
198
214
  switch (cached_result_type) {
199
215
  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
 
 
 
216
  {
 
217
    res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
 
218
                     REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
 
219
    break;
 
220
  }
206
221
  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
 
 
 
222
  {
 
223
    res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
 
224
                     INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
 
225
                     unsigned_flag);
 
226
    break;
 
227
  }
214
228
  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
 
 
 
229
  {
 
230
    if (!save_result.vstr)                                      // Null value
 
231
      res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
 
232
                       DERIVATION_IMPLICIT, 0);
 
233
    else
 
234
      res= update_hash((void*) save_result.vstr->ptr(),
 
235
                       save_result.vstr->length(), STRING_RESULT,
 
236
                       save_result.vstr->charset(),
 
237
                       DERIVATION_IMPLICIT, 0);
 
238
    break;
 
239
  }
227
240
  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
 
 
 
241
  {
 
242
    if (!save_result.vdec)                                      // Null value
 
243
      res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
 
244
                       DERIVATION_IMPLICIT, 0);
 
245
    else
 
246
      res= update_hash((void*) save_result.vdec,
 
247
                       sizeof(my_decimal), DECIMAL_RESULT,
 
248
                       &my_charset_bin, DERIVATION_IMPLICIT, 0);
 
249
    break;
 
250
  }
239
251
  case ROW_RESULT:
 
252
  default:
240
253
    // This case should never be chosen
241
254
    assert(0);
242
255
    break;
243
256
  }
244
 
 
245
257
  return(res);
246
258
}
247
259
 
320
332
  str->append(')');
321
333
}
322
334
 
323
 
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
 
335
 
 
336
void Item_func_set_user_var::print_as_stmt(String *str,
 
337
                                           enum_query_type query_type)
 
338
{
 
339
  str->append(STRING_WITH_LEN("set @"));
 
340
  str->append(name.str, name.length);
 
341
  str->append(STRING_WITH_LEN(":="));
 
342
  args[0]->print(str, query_type);
 
343
  str->append(')');
 
344
}
 
345
 
 
346
bool Item_func_set_user_var::send(Protocol *protocol, String *str_arg)
324
347
{
325
348
  if (result_field)
326
349
  {
327
350
    check(1);
328
351
    update();
329
 
    return client->store(result_field);
 
352
    return protocol->store(result_field);
330
353
  }
331
 
  return Item::send(client, str_arg);
 
354
  return Item::send(protocol, str_arg);
332
355
}
333
356
 
334
 
void Item_func_set_user_var::make_field(SendField *tmp_field)
 
357
void Item_func_set_user_var::make_field(Send_field *tmp_field)
335
358
{
336
359
  if (result_field)
337
360
  {
443
466
}
444
467
 
445
468
 
446
 
} /* namespace drizzled */