~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-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

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/get_variable.h>
 
24
#include <drizzled/function/update_hash.h>
23
25
#include <drizzled/field/num.h>
 
26
#include <drizzled/virtual_column_info.h>
24
27
#include <drizzled/session.h>
25
 
#include <drizzled/plugin/client.h>
26
 
 
27
 
namespace drizzled
28
 
{
 
28
 
 
29
#include <bitset>
 
30
 
 
31
using namespace std;
29
32
 
30
33
/*
31
34
  When a user variable is updated (in a SET command or a query like
37
40
  assert(fixed == 0);
38
41
  /* fix_fields will call Item_func_set_user_var::fix_length_and_dec */
39
42
  if (Item_func::fix_fields(session, ref) ||
40
 
      !(entry= session->getVariable(name, true)))
 
43
      !(entry= get_variable(&session->user_vars, name, 1)))
41
44
    return true;
42
45
  /*
43
46
     Remember the last query which updated it, this way a query can later know
44
47
     if this variable is a constant item in the query (it is if update_query_id
45
48
     is different from query_id).
46
49
  */
47
 
  entry->update_query_id= session->getQueryId();
 
50
  entry->update_query_id= session->query_id;
48
51
  /*
49
52
    As it is wrong and confusing to associate any
50
53
    character set with NULL, @a should be latin2
91
94
  {
92
95
    Table *table= (Table *) arg;
93
96
    if (result_field->table == table || !table)
94
 
      result_field->table->setReadSet(result_field->field_index);
95
 
  }
96
 
  return 0;
97
 
}
98
 
 
 
97
      result_field->table->read_set->set(result_field->field_index);
 
98
    if (result_field->vcol_info && result_field->vcol_info->expr_item)
 
99
      return result_field->vcol_info->
 
100
               expr_item->walk(&Item::register_field_in_read_map, 1, arg);
 
101
  }
 
102
  return 0;
 
103
}
 
104
 
 
105
/*
 
106
  Mark field in bitmap supplied as *arg
 
107
 
 
108
*/
 
109
 
 
110
bool Item_func_set_user_var::register_field_in_bitmap(unsigned char *arg)
 
111
{
 
112
  bitset<MAX_FIELDS> *bitmap = (bitset<MAX_FIELDS> *) arg;
 
113
  assert(bitmap);
 
114
  if (result_field)
 
115
  {
 
116
    bitmap->set(result_field->field_index);
 
117
  }
 
118
  return 0;
 
119
}
99
120
 
100
121
bool
101
122
Item_func_set_user_var::update_hash(void *ptr, uint32_t length,
109
130
  */
110
131
  if ((null_value= args[0]->null_value) && null_item)
111
132
    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))
 
133
  if (::update_hash(entry, (null_value= args[0]->null_value),
 
134
                    ptr, length, res_type, cs, dv, unsigned_arg))
114
135
  {
115
136
    null_value= 1;
116
137
    return 1;
316
337
  str->append(')');
317
338
}
318
339
 
319
 
bool Item_func_set_user_var::send(plugin::Client *client, String *str_arg)
 
340
 
 
341
void Item_func_set_user_var::print_as_stmt(String *str,
 
342
                                           enum_query_type query_type)
 
343
{
 
344
  str->append(STRING_WITH_LEN("set @"));
 
345
  str->append(name.str, name.length);
 
346
  str->append(STRING_WITH_LEN(":="));
 
347
  args[0]->print(str, query_type);
 
348
  str->append(')');
 
349
}
 
350
 
 
351
bool Item_func_set_user_var::send(Protocol *protocol, String *str_arg)
320
352
{
321
353
  if (result_field)
322
354
  {
323
355
    check(1);
324
356
    update();
325
 
    return client->store(result_field);
 
357
    return protocol->store(result_field);
326
358
  }
327
 
  return Item::send(client, str_arg);
 
359
  return Item::send(protocol, str_arg);
328
360
}
329
361
 
330
 
void Item_func_set_user_var::make_field(SendField *tmp_field)
 
362
void Item_func_set_user_var::make_field(Send_field *tmp_field)
331
363
{
332
364
  if (result_field)
333
365
  {
439
471
}
440
472
 
441
473
 
442
 
} /* namespace drizzled */