1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
1897.4.14
by Monty Taylor
Update to support default values and properly throw warnings on value |
21 |
|
2207.8.2
by Olaf van der Spek
x |
22 |
#include <boost/foreach.hpp> |
1897.4.14
by Monty Taylor
Update to support default values and properly throw warnings on value |
23 |
#include <boost/lexical_cast.hpp> |
1964.1.4
by Monty Taylor
Use boost::exception data bundling instead of co-opting the exceptions |
24 |
#include <boost/exception/get_error_info.hpp> |
1897.4.14
by Monty Taylor
Update to support default values and properly throw warnings on value |
25 |
#include <string> |
26 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
27 |
#include <drizzled/session.h> |
28 |
#include <drizzled/item/string.h> |
|
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
29 |
#include <drizzled/function/set_user_var.h> |
2234.1.4
by Olaf van der Spek
Refactor includes |
30 |
#include <drizzled/sql_lex.h> |
2239.1.9
by Olaf van der Spek
Refactor includes |
31 |
#include <drizzled/util/test.h> |
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
32 |
|
33 |
using namespace std; |
|
34 |
||
35 |
namespace drizzled |
|
36 |
{
|
|
37 |
||
38 |
/**
|
|
39 |
Execute update of all variables.
|
|
40 |
||
41 |
First run a check of all variables that all updates will go ok.
|
|
42 |
If yes, then execute all updates, returning an error if any one failed.
|
|
43 |
||
44 |
This should ensure that in all normal cases none all or variables are
|
|
45 |
updated.
|
|
46 |
||
47 |
@param Session Thread id
|
|
48 |
@param var_list List of variables to update
|
|
49 |
||
50 |
@retval
|
|
51 |
0 ok
|
|
52 |
@retval
|
|
53 |
1 ERROR, message sent (normally no variables was updated)
|
|
54 |
@retval
|
|
55 |
-1 ERROR, message not sent
|
|
56 |
*/
|
|
57 |
||
2040.6.4
by Monty Taylor
Replaced List<set_var_base> with |
58 |
int sql_set_variables(Session *session, const SetVarVector &var_list) |
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
59 |
{
|
60 |
int error; |
|
2207.8.2
by Olaf van der Spek
x |
61 |
BOOST_FOREACH(SetVarVector::const_reference it, var_list) |
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
62 |
{
|
2207.8.2
by Olaf van der Spek
x |
63 |
if ((error= it->check(session))) |
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
64 |
goto err; |
65 |
}
|
|
66 |
if (!(error= test(session->is_error()))) |
|
67 |
{
|
|
2207.8.2
by Olaf van der Spek
x |
68 |
BOOST_FOREACH(SetVarVector::const_reference it, var_list) |
2040.6.4
by Monty Taylor
Replaced List<set_var_base> with |
69 |
{
|
2207.8.2
by Olaf van der Spek
x |
70 |
error|= it->update(session); // Returns 0, -1 or 1 |
2040.6.4
by Monty Taylor
Replaced List<set_var_base> with |
71 |
}
|
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
72 |
}
|
2363.1.4
by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly. |
73 |
|
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
74 |
err: |
2227.4.8
by Olaf van der Spek
Session::lex() |
75 |
free_underlaid_joins(session, &session->lex().select_lex); |
2207.8.2
by Olaf van der Spek
x |
76 |
return error; |
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
77 |
}
|
78 |
||
79 |
||
80 |
/*****************************************************************************
|
|
81 |
Functions to handle SET mysql_internal_variable=const_expr
|
|
82 |
*****************************************************************************/
|
|
2445.1.11
by Olaf van der Spek
Use str_ref |
83 |
set_var::set_var(sql_var_t type_arg, sys_var *var_arg, str_ref base_name_arg, Item *value_arg) : |
2070.2.2
by Monty Taylor
Removed some guts from set_var. |
84 |
uint64_t_value(0), |
85 |
var(var_arg), |
|
86 |
type(type_arg), |
|
2445.1.11
by Olaf van der Spek
Use str_ref |
87 |
base(base_name_arg) |
1878.3.2
by Monty Taylor
Split out show_type into its own header and made sys_var work through |
88 |
{
|
89 |
/*
|
|
90 |
If the set value is a field, change it to a string to allow things like
|
|
91 |
SET table_type=MYISAM;
|
|
92 |
*/
|
|
93 |
if (value_arg && value_arg->type() == Item::FIELD_ITEM) |
|
94 |
{
|
|
95 |
Item_field *item= (Item_field*) value_arg; |
|
2440.2.24
by Olaf van der Spek
Use str_ref |
96 |
value= new Item_string(str_ref(item->field_name), item->collation.collation); |
1878.3.2
by Monty Taylor
Split out show_type into its own header and made sys_var work through |
97 |
}
|
98 |
else
|
|
2070.2.2
by Monty Taylor
Removed some guts from set_var. |
99 |
{
|
100 |
value= value_arg; |
|
101 |
}
|
|
1878.3.2
by Monty Taylor
Split out show_type into its own header and made sys_var work through |
102 |
}
|
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
103 |
|
104 |
int set_var::check(Session *session) |
|
105 |
{
|
|
106 |
if (var->is_readonly()) |
|
107 |
{
|
|
108 |
my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->getName().c_str(), "read only"); |
|
109 |
return -1; |
|
110 |
}
|
|
111 |
if (var->check_type(type)) |
|
112 |
{
|
|
113 |
int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; |
|
2054.1.2
by Brian Aker
Rename of the Loooongggggg error type over to simply drizzled::error_t |
114 |
my_error(static_cast<drizzled::error_t>(err), MYF(0), var->getName().c_str()); |
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
115 |
return -1; |
116 |
}
|
|
117 |
/* value is a NULL pointer if we are using SET ... = DEFAULT */
|
|
2318.6.78
by Olaf van der Spek
Refactor |
118 |
if (not value) |
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
119 |
{
|
120 |
if (var->check_default(type)) |
|
121 |
{
|
|
122 |
my_error(ER_NO_DEFAULT, MYF(0), var->getName().c_str()); |
|
123 |
return -1; |
|
124 |
}
|
|
125 |
return 0; |
|
126 |
}
|
|
127 |
||
128 |
if ((!value->fixed && |
|
129 |
value->fix_fields(session, &value)) || value->check_cols(1)) |
|
130 |
return -1; |
|
131 |
if (var->check_update_type(value->result_type())) |
|
132 |
{
|
|
133 |
my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->getName().c_str()); |
|
134 |
return -1; |
|
135 |
}
|
|
136 |
return var->check(session, this) ? -1 : 0; |
|
137 |
}
|
|
138 |
||
139 |
/**
|
|
140 |
Update variable
|
|
141 |
||
142 |
@param session thread handler
|
|
143 |
@returns 0|1 ok or ERROR
|
|
144 |
||
145 |
@note ERROR can be only due to abnormal operations involving
|
|
146 |
the server's execution evironment such as
|
|
147 |
out of memory, hard disk failure or the computer blows up.
|
|
148 |
Consider set_var::check() method if there is a need to return
|
|
149 |
an error due to logics.
|
|
150 |
*/
|
|
151 |
int set_var::update(Session *session) |
|
152 |
{
|
|
1897.4.14
by Monty Taylor
Update to support default values and properly throw warnings on value |
153 |
try
|
154 |
{
|
|
2318.6.78
by Olaf van der Spek
Refactor |
155 |
if (not value) |
1897.4.14
by Monty Taylor
Update to support default values and properly throw warnings on value |
156 |
var->set_default(session, type); |
157 |
else if (var->update(session, this)) |
|
158 |
return -1; // should never happen |
|
159 |
if (var->getAfterUpdateTrigger()) |
|
160 |
(*var->getAfterUpdateTrigger())(session, type); |
|
161 |
}
|
|
1964.1.4
by Monty Taylor
Use boost::exception data bundling instead of co-opting the exceptions |
162 |
catch (invalid_option_value &ex) |
1897.4.14
by Monty Taylor
Update to support default values and properly throw warnings on value |
163 |
{
|
1897.4.18
by Monty Taylor
Cleaned up another debugging leftover. |
164 |
/* TODO: Fix this to be typesafe once we have properly typed set_var */
|
2070.2.2
by Monty Taylor
Removed some guts from set_var. |
165 |
string new_val= boost::lexical_cast<string>(uint64_t_value); |
1964.1.5
by Monty Taylor
Change how we deal with error_info, because on karmic it's returning a shared_ptr. Sigh. |
166 |
if (boost::get_error_info<invalid_max_info>(ex) != NULL) |
1964.1.4
by Monty Taylor
Use boost::exception data bundling instead of co-opting the exceptions |
167 |
{
|
1964.1.5
by Monty Taylor
Change how we deal with error_info, because on karmic it's returning a shared_ptr. Sigh. |
168 |
const uint64_t max_val= *(boost::get_error_info<invalid_max_info>(ex)); |
1964.1.4
by Monty Taylor
Use boost::exception data bundling instead of co-opting the exceptions |
169 |
string explanation("(> "); |
1964.1.5
by Monty Taylor
Change how we deal with error_info, because on karmic it's returning a shared_ptr. Sigh. |
170 |
explanation.append(boost::lexical_cast<std::string>(max_val)); |
1964.1.4
by Monty Taylor
Use boost::exception data bundling instead of co-opting the exceptions |
171 |
explanation.push_back(')'); |
172 |
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
|
173 |
ER_INVALID_OPTION_VALUE, |
|
174 |
ER(ER_INVALID_OPTION_VALUE), |
|
175 |
var->getName().c_str(), |
|
176 |
new_val.c_str(), |
|
177 |
explanation.c_str()); |
|
178 |
}
|
|
1964.1.5
by Monty Taylor
Change how we deal with error_info, because on karmic it's returning a shared_ptr. Sigh. |
179 |
else if (boost::get_error_info<invalid_min_info>(ex) != NULL) |
180 |
{
|
|
181 |
const int64_t min_val= *(boost::get_error_info<invalid_min_info>(ex)); |
|
1964.1.4
by Monty Taylor
Use boost::exception data bundling instead of co-opting the exceptions |
182 |
string explanation("(< "); |
1964.1.5
by Monty Taylor
Change how we deal with error_info, because on karmic it's returning a shared_ptr. Sigh. |
183 |
explanation.append(boost::lexical_cast<std::string>(min_val)); |
1964.1.4
by Monty Taylor
Use boost::exception data bundling instead of co-opting the exceptions |
184 |
explanation.push_back(')'); |
185 |
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
|
186 |
ER_INVALID_OPTION_VALUE, |
|
187 |
ER(ER_INVALID_OPTION_VALUE), |
|
188 |
var->getName().c_str(), |
|
189 |
new_val.c_str(), |
|
190 |
explanation.c_str()); |
|
191 |
}
|
|
2070.2.1
by Monty Taylor
First step in getting that anonymous union out of set_var. |
192 |
else if (boost::get_error_info<invalid_value>(ex) != NULL) |
193 |
{
|
|
194 |
const std::string str_val= *(boost::get_error_info<invalid_value>(ex)); |
|
195 |
string explanation("("); |
|
196 |
explanation.append(str_val); |
|
197 |
explanation.push_back(')'); |
|
198 |
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, |
|
199 |
ER_INVALID_OPTION_VALUE, |
|
200 |
ER(ER_INVALID_OPTION_VALUE), |
|
201 |
var->getName().c_str(), |
|
202 |
new_val.c_str(), |
|
203 |
explanation.c_str()); |
|
204 |
}
|
|
1964.1.4
by Monty Taylor
Use boost::exception data bundling instead of co-opting the exceptions |
205 |
else
|
206 |
{
|
|
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 |
""); |
|
213 |
}
|
|
1897.4.14
by Monty Taylor
Update to support default values and properly throw warnings on value |
214 |
}
|
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
215 |
return 0; |
216 |
}
|
|
217 |
||
218 |
/*****************************************************************************
|
|
219 |
Functions to handle SET @user_variable=const_expr
|
|
220 |
*****************************************************************************/
|
|
221 |
||
222 |
int set_var_user::check(Session *session) |
|
223 |
{
|
|
224 |
/*
|
|
225 |
Item_func_set_user_var can't substitute something else on its place =>
|
|
226 |
0 can be passed as last argument (reference on item)
|
|
227 |
*/
|
|
228 |
return (user_var_item->fix_fields(session, (Item**) 0) || |
|
229 |
user_var_item->check(0)) ? -1 : 0; |
|
230 |
}
|
|
231 |
||
232 |
||
233 |
int set_var_user::update(Session *) |
|
234 |
{
|
|
2246.3.5
by Olaf van der Spek
Propogate return void |
235 |
user_var_item->update(); |
236 |
return 0; |
|
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
237 |
}
|
238 |
||
2070.2.1
by Monty Taylor
First step in getting that anonymous union out of set_var. |
239 |
void set_var::setValue(const std::string &new_value) |
240 |
{
|
|
241 |
str_value= new_value; |
|
242 |
}
|
|
243 |
||
244 |
void set_var::setValue(uint64_t new_value) |
|
245 |
{
|
|
2070.2.2
by Monty Taylor
Removed some guts from set_var. |
246 |
uint64_t_value= new_value; |
2070.2.1
by Monty Taylor
First step in getting that anonymous union out of set_var. |
247 |
}
|
248 |
||
249 |
void set_var::updateValue() |
|
250 |
{
|
|
2070.2.2
by Monty Taylor
Removed some guts from set_var. |
251 |
if (var->show_type() != SHOW_CHAR) |
252 |
{
|
|
253 |
uint64_t_value= value->val_int(); |
|
254 |
}
|
|
2070.2.1
by Monty Taylor
First step in getting that anonymous union out of set_var. |
255 |
}
|
256 |
||
257 |
||
1878.3.1
by Monty Taylor
Split set_var.* into sys_var.* and set_var.* |
258 |
} /* namespace drizzled */ |