~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Lee Bieber
  • Date: 2010-12-23 23:11:00 UTC
  • mfrom: (2024.1.1 clean)
  • Revision ID: kalebral@gmail.com-20101223231100-0rqirgz7ugkl10yp
Merge Brian - session list cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    -1  ERROR, message not sent
53
53
*/
54
54
 
55
 
int sql_set_variables(Session *session, const SetVarVector &var_list)
 
55
int sql_set_variables(Session *session, List<set_var_base> *var_list)
56
56
{
57
57
  int error;
58
 
 
59
 
  SetVarVector::const_iterator it(var_list.begin());
60
 
 
61
 
  while (it != var_list.end())
 
58
  List_iterator_fast<set_var_base> it(*var_list);
 
59
 
 
60
  set_var_base *var;
 
61
  while ((var=it++))
62
62
  {
63
 
    if ((error= (*it)->check(session)))
 
63
    if ((error= var->check(session)))
64
64
      goto err;
65
 
    ++it;
66
65
  }
67
66
  if (!(error= test(session->is_error())))
68
67
  {
69
 
    it= var_list.begin();
70
 
    while (it != var_list.end())
71
 
    {
72
 
      error|= (*it)->update(session);         // Returns 0, -1 or 1
73
 
      ++it;
74
 
    }
 
68
    it.rewind();
 
69
    while ((var= it++))
 
70
      error|= var->update(session);         // Returns 0, -1 or 1
75
71
  }
76
72
 
77
73
err:
85
81
*****************************************************************************/
86
82
set_var::set_var(sql_var_t type_arg, sys_var *var_arg,
87
83
                 const LEX_STRING *base_name_arg, Item *value_arg) :
88
 
  uint64_t_value(0),
89
 
  str_value(""),
90
 
  var(var_arg),
91
 
  type(type_arg),
92
 
  base(*base_name_arg)
 
84
  var(var_arg), type(type_arg), base(*base_name_arg)
93
85
{
94
86
  /*
95
87
    If the set value is a field, change it to a string to allow things like
104
96
      value=value_arg;                  /* Give error message later */
105
97
  }
106
98
  else
107
 
  {
108
 
    value= value_arg;
109
 
  }
 
99
    value=value_arg;
110
100
}
111
101
 
112
102
int set_var::check(Session *session)
119
109
  if (var->check_type(type))
120
110
  {
121
111
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
122
 
    my_error(static_cast<drizzled::error_t>(err), MYF(0), var->getName().c_str());
 
112
    my_error(err, MYF(0), var->getName().c_str());
123
113
    return -1;
124
114
  }
125
115
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
170
160
  catch (invalid_option_value &ex)
171
161
  {
172
162
    /* TODO: Fix this to be typesafe once we have properly typed set_var */
173
 
    string new_val= boost::lexical_cast<string>(uint64_t_value);
 
163
    string new_val= boost::lexical_cast<string>(save_result.uint32_t_value);
174
164
    if (boost::get_error_info<invalid_max_info>(ex) != NULL)
175
165
    { 
176
166
      const uint64_t max_val= *(boost::get_error_info<invalid_max_info>(ex));
197
187
                          new_val.c_str(),
198
188
                          explanation.c_str());
199
189
    }
200
 
    else if (boost::get_error_info<invalid_value>(ex) != NULL)
201
 
    {
202
 
      const std::string str_val= *(boost::get_error_info<invalid_value>(ex));
203
 
      string explanation("(");
204
 
      explanation.append(str_val);
205
 
      explanation.push_back(')');
206
 
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
207
 
                          ER_INVALID_OPTION_VALUE,
208
 
                          ER(ER_INVALID_OPTION_VALUE),
209
 
                          var->getName().c_str(),
210
 
                          new_val.c_str(),
211
 
                          explanation.c_str());
212
 
    }
213
190
    else
214
191
    {
215
192
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
249
226
  return 0;
250
227
}
251
228
 
252
 
void set_var::setValue(const std::string &new_value)
253
 
{
254
 
  str_value= new_value;
255
 
}
256
 
 
257
 
void set_var::setValue(uint64_t new_value)
258
 
{
259
 
  uint64_t_value= new_value;
260
 
}
261
 
 
262
 
void set_var::updateValue()
263
 
{
264
 
  if (var->show_type() != SHOW_CHAR)
265
 
  {
266
 
    uint64_t_value= value->val_int();
267
 
  }
268
 
}
269
 
 
270
 
 
271
229
} /* namespace drizzled */