~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
20
20
#include "config.h"
21
21
 
22
22
#include <boost/lexical_cast.hpp>
 
23
#include <boost/exception/get_error_info.hpp>
23
24
#include <string>
24
25
 
25
26
#include "drizzled/session.h"
51
52
    -1  ERROR, message not sent
52
53
*/
53
54
 
54
 
int sql_set_variables(Session *session, List<set_var_base> *var_list)
 
55
int sql_set_variables(Session *session, const SetVarVector &var_list)
55
56
{
56
57
  int error;
57
 
  List_iterator_fast<set_var_base> it(*var_list);
58
 
 
59
 
  set_var_base *var;
60
 
  while ((var=it++))
 
58
 
 
59
  SetVarVector::const_iterator it(var_list.begin());
 
60
 
 
61
  while (it != var_list.end())
61
62
  {
62
 
    if ((error= var->check(session)))
 
63
    if ((error= (*it)->check(session)))
63
64
      goto err;
 
65
    ++it;
64
66
  }
65
67
  if (!(error= test(session->is_error())))
66
68
  {
67
 
    it.rewind();
68
 
    while ((var= it++))
69
 
      error|= var->update(session);         // Returns 0, -1 or 1
 
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
    }
70
75
  }
71
76
 
72
77
err:
80
85
*****************************************************************************/
81
86
set_var::set_var(sql_var_t type_arg, sys_var *var_arg,
82
87
                 const LEX_STRING *base_name_arg, Item *value_arg) :
83
 
  var(var_arg), type(type_arg), base(*base_name_arg)
 
88
  uint64_t_value(0),
 
89
  str_value(""),
 
90
  var(var_arg),
 
91
  type(type_arg),
 
92
  base(*base_name_arg)
84
93
{
85
94
  /*
86
95
    If the set value is a field, change it to a string to allow things like
95
104
      value=value_arg;                  /* Give error message later */
96
105
  }
97
106
  else
98
 
    value=value_arg;
 
107
  {
 
108
    value= value_arg;
 
109
  }
99
110
}
100
111
 
101
112
int set_var::check(Session *session)
108
119
  if (var->check_type(type))
109
120
  {
110
121
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
111
 
    my_error(err, MYF(0), var->getName().c_str());
 
122
    my_error(static_cast<drizzled::error_t>(err), MYF(0), var->getName().c_str());
112
123
    return -1;
113
124
  }
114
125
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
156
167
    if (var->getAfterUpdateTrigger())
157
168
      (*var->getAfterUpdateTrigger())(session, type);
158
169
  }
159
 
  catch (boost::exception &)
 
170
  catch (invalid_option_value &ex)
160
171
  {
161
172
    /* TODO: Fix this to be typesafe once we have properly typed set_var */
162
 
    string new_val= boost::lexical_cast<string>(save_result.uint32_t_value);
163
 
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
164
 
                        ER_TRUNCATED_WRONG_VALUE,
165
 
                        ER(ER_TRUNCATED_WRONG_VALUE), var->getName().c_str(),
166
 
                        new_val.c_str());
 
173
    string new_val= boost::lexical_cast<string>(uint64_t_value);
 
174
    if (boost::get_error_info<invalid_max_info>(ex) != NULL)
 
175
    { 
 
176
      const uint64_t max_val= *(boost::get_error_info<invalid_max_info>(ex));
 
177
      string explanation("(> ");
 
178
      explanation.append(boost::lexical_cast<std::string>(max_val));
 
179
      explanation.push_back(')');
 
180
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
181
                          ER_INVALID_OPTION_VALUE,
 
182
                          ER(ER_INVALID_OPTION_VALUE),
 
183
                          var->getName().c_str(),
 
184
                          new_val.c_str(),
 
185
                          explanation.c_str());
 
186
    }
 
187
    else if (boost::get_error_info<invalid_min_info>(ex) != NULL)
 
188
    { 
 
189
      const int64_t min_val= *(boost::get_error_info<invalid_min_info>(ex));
 
190
      string explanation("(< ");
 
191
      explanation.append(boost::lexical_cast<std::string>(min_val));
 
192
      explanation.push_back(')');
 
193
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
194
                          ER_INVALID_OPTION_VALUE,
 
195
                          ER(ER_INVALID_OPTION_VALUE),
 
196
                          var->getName().c_str(),
 
197
                          new_val.c_str(),
 
198
                          explanation.c_str());
 
199
    }
 
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
    else
 
214
    {
 
215
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
216
                          ER_INVALID_OPTION_VALUE,
 
217
                          ER(ER_INVALID_OPTION_VALUE),
 
218
                          var->getName().c_str(),
 
219
                          new_val.c_str(),
 
220
                          "");
 
221
    }
167
222
  }
168
223
  return 0;
169
224
}
194
249
  return 0;
195
250
}
196
251
 
 
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
 
197
271
} /* namespace drizzled */