~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/set_user_var.cc

  • Committer: Eric Day
  • Date: 2009-11-10 21:50:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1218.
  • Revision ID: eday@oddments.org-20091110215022-0b2nqmurv7b2l6wo
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port.

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
25
#include <drizzled/plugin/client.h>
26
26
 
27
 
namespace drizzled
28
 
{
 
27
using namespace drizzled;
29
28
 
30
29
/*
31
30
  When a user variable is updated (in a SET command or a query like
44
43
     if this variable is a constant item in the query (it is if update_query_id
45
44
     is different from query_id).
46
45
  */
47
 
  entry->update_query_id= session->getQueryId();
 
46
  entry->update_query_id= session->query_id;
48
47
  /*
49
48
    As it is wrong and confusing to associate any
50
49
    character set with NULL, @a should be latin2
90
89
  if (result_field)
91
90
  {
92
91
    Table *table= (Table *) arg;
93
 
    if (result_field->getTable() == table || !table)
94
 
      result_field->getTable()->setReadSet(result_field->position());
 
92
    if (result_field->table == table || !table)
 
93
      result_field->table->setReadSet(result_field->field_index);
95
94
  }
96
95
  return 0;
97
96
}
140
139
 
141
140
  switch (cached_result_type) {
142
141
  case REAL_RESULT:
143
 
    {
144
 
      save_result.vreal= use_result_field ? result_field->val_real() :
145
 
        args[0]->val_real();
146
 
      break;
147
 
    }
 
142
  {
 
143
    save_result.vreal= use_result_field ? result_field->val_real() :
 
144
                        args[0]->val_real();
 
145
    break;
 
146
  }
148
147
  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
 
    }
 
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
  }
156
155
  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
 
    }
 
156
  {
 
157
    save_result.vstr= use_result_field ? result_field->val_str(&value) :
 
158
                       args[0]->val_str(&value);
 
159
    break;
 
160
  }
162
161
  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
 
    }
 
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
  }
169
168
  case ROW_RESULT:
 
169
  default:
170
170
    // This case should never be chosen
171
171
    assert(0);
172
172
    break;
173
173
  }
174
 
 
175
 
  return false;
 
174
  return(false);
176
175
}
177
176
 
178
177
/**
197
196
 
198
197
  switch (cached_result_type) {
199
198
  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
 
 
 
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
  }
206
204
  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
 
 
 
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
  }
214
211
  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
 
 
 
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
  }
227
223
  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
 
 
 
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
  }
239
234
  case ROW_RESULT:
 
235
  default:
240
236
    // This case should never be chosen
241
237
    assert(0);
242
238
    break;
243
239
  }
244
 
 
245
240
  return(res);
246
241
}
247
242
 
320
315
  str->append(')');
321
316
}
322
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
 
323
329
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
324
330
{
325
331
  if (result_field)
443
449
}
444
450
 
445
451
 
446
 
} /* namespace drizzled */