~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Stewart Smith
  • Date: 2011-02-24 07:46:16 UTC
  • mto: (2200.1.2 drizzle-staging)
  • mto: This revision was merged to the branch mainline in revision 2201.
  • Revision ID: stewart@flamingspork.com-20110224074616-l2rmp406vf78x71q
add ER_NO_LOCK_HELD error code, and expect it in case of UNLOCK TABLES without any locks held.

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