~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/set_user_var.cc

  • Committer: Lee Bieber
  • Date: 2011-03-29 22:31:41 UTC
  • mfrom: (2257.1.3 build)
  • Revision ID: kalebral@gmail.com-20110329223141-yxc22h3l2he58sk0
Merge Andrew - 743842: Build failure using GCC 4.6
Merge Stewart - 738022: CachedDirectory silently fails to add entries if stat() fails
Merge Olaf - Common fwd: add copyright, add more declaration

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"
 
20
#include <config.h>
21
21
 
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
#include <drizzled/table.h>
26
28
 
27
 
namespace drizzled
28
 
{
 
29
namespace drizzled {
29
30
 
30
31
/*
31
32
  When a user variable is updated (in a SET command or a query like
97
98
}
98
99
 
99
100
 
100
 
bool
 
101
void
101
102
Item_func_set_user_var::update_hash(void *ptr, uint32_t length,
102
103
                                    Item_result res_type,
103
 
                                    const CHARSET_INFO * const cs, Derivation dv,
 
104
                                    const charset_info_st * const cs, Derivation dv,
104
105
                                    bool unsigned_arg)
105
106
{
106
107
  /*
109
110
  */
110
111
  if ((null_value= args[0]->null_value) && null_item)
111
112
    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))
114
 
  {
115
 
    null_value= 1;
116
 
    return 1;
117
 
  }
118
 
  return 0;
 
113
  entry->update_hash((null_value= args[0]->null_value), ptr, length, res_type, cs, dv, unsigned_arg);
119
114
}
120
115
 
121
116
/**
190
185
 
191
186
*/
192
187
 
193
 
bool
 
188
void
194
189
Item_func_set_user_var::update()
195
190
{
196
 
  bool res= false;
197
 
 
198
191
  switch (cached_result_type) {
199
192
  case REAL_RESULT:
200
193
    {
201
 
      res= update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
 
194
      update_hash((void*) &save_result.vreal,sizeof(save_result.vreal),
202
195
                       REAL_RESULT, &my_charset_bin, DERIVATION_IMPLICIT, 0);
203
196
      break;
204
197
    }
205
198
 
206
199
  case INT_RESULT:
207
200
    {
208
 
      res= update_hash((void*) &save_result.vint, sizeof(save_result.vint),
 
201
      update_hash((void*) &save_result.vint, sizeof(save_result.vint),
209
202
                       INT_RESULT, &my_charset_bin, DERIVATION_IMPLICIT,
210
203
                       unsigned_flag);
211
204
      break;
214
207
  case STRING_RESULT:
215
208
    {
216
209
      if (!save_result.vstr)                                      // Null value
217
 
        res= update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
 
210
        update_hash((void*) 0, 0, STRING_RESULT, &my_charset_bin,
218
211
                         DERIVATION_IMPLICIT, 0);
219
212
      else
220
 
        res= update_hash((void*) save_result.vstr->ptr(),
 
213
        update_hash((void*) save_result.vstr->ptr(),
221
214
                         save_result.vstr->length(), STRING_RESULT,
222
215
                         save_result.vstr->charset(),
223
216
                         DERIVATION_IMPLICIT, 0);
227
220
  case DECIMAL_RESULT:
228
221
    {
229
222
      if (!save_result.vdec)                                      // Null value
230
 
        res= update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
 
223
        update_hash((void*) 0, 0, DECIMAL_RESULT, &my_charset_bin,
231
224
                         DERIVATION_IMPLICIT, 0);
232
225
      else
233
 
        res= update_hash((void*) save_result.vdec,
 
226
        update_hash((void*) save_result.vdec,
234
227
                         sizeof(type::Decimal), DECIMAL_RESULT,
235
228
                         &my_charset_bin, DERIVATION_IMPLICIT, 0);
236
229
      break;
241
234
    assert(0);
242
235
    break;
243
236
  }
244
 
 
245
 
  return(res);
246
237
}
247
238
 
248
239
double Item_func_set_user_var::val_real()
311
302
  return entry->val_decimal(&null_value, val);
312
303
}
313
304
 
314
 
void Item_func_set_user_var::print(String *str, enum_query_type query_type)
 
305
void Item_func_set_user_var::print(String *str)
315
306
{
316
307
  str->append(STRING_WITH_LEN("(@"));
317
308
  str->append(name.str, name.length);
318
309
  str->append(STRING_WITH_LEN(":="));
319
 
  args[0]->print(str, query_type);
 
310
  args[0]->print(str);
320
311
  str->append(')');
321
312
}
322
313
 
399
390
      (result_type() == REAL_RESULT && field->result_type() == STRING_RESULT))
400
391
  {
401
392
    String *result;
402
 
    const CHARSET_INFO * const cs= collation.collation;
 
393
    const charset_info_st * const cs= collation.collation;
403
394
    char buff[MAX_FIELD_WIDTH];         // Alloc buffer for small columns
404
395
    str_value.set_quick(buff, sizeof(buff), cs);
405
396
    result= entry->val_str(&null_value, &str_value, decimals);