2014-01-06 10:52:35 +05:30
|
|
|
/* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
|
2002-07-23 18:31:22 +03:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2002-07-23 18:31:22 +03:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-30 17:46:53 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2005-05-26 12:09:14 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2009-12-22 10:35:56 +01:00
|
|
|
#pragma implementation
|
2002-07-23 18:31:22 +03:00
|
|
|
#endif
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
/* variable declarations are in sys_vars.cc now !!! */
|
2005-11-07 16:25:06 +01:00
|
|
|
|
2010-04-07 13:58:40 +02:00
|
|
|
#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_class.h" // set_var.h: session_var_ptr
|
|
|
|
#include "set_var.h"
|
|
|
|
#include "sql_priv.h"
|
|
|
|
#include "unireg.h"
|
|
|
|
#include "mysqld.h" // lc_messages_dir
|
2009-12-22 10:35:56 +01:00
|
|
|
#include "sys_vars_shared.h"
|
2009-12-03 21:37:38 +03:00
|
|
|
#include "transaction.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_locale.h" // my_locale_by_number,
|
|
|
|
// my_locale_by_name
|
|
|
|
#include "strfunc.h" // find_set_from_flags, find_set
|
|
|
|
#include "sql_parse.h" // check_global_access
|
|
|
|
#include "sql_table.h" // reassign_keycache_tables
|
|
|
|
#include "sql_time.h" // date_time_format_copy,
|
|
|
|
// date_time_format_make
|
|
|
|
#include "derror.h"
|
|
|
|
#include "tztime.h" // my_tz_find, my_tz_SYSTEM, struct Time_zone
|
|
|
|
#include "sql_acl.h" // SUPER_ACL
|
|
|
|
#include "sql_select.h" // free_underlaid_joins
|
|
|
|
#include "sql_show.h" // make_default_log_name
|
|
|
|
#include "sql_view.h" // updatable_views_with_limit_typelib
|
|
|
|
#include "lock.h" // lock_global_read_lock,
|
|
|
|
// make_global_read_lock_block_commit,
|
|
|
|
// unlock_global_read_lock
|
2006-05-22 20:46:13 +02:00
|
|
|
|
2002-07-23 18:31:22 +03:00
|
|
|
static HASH system_variable_hash;
|
2009-12-22 10:35:56 +01:00
|
|
|
static PolyLock_mutex PLock_global_system_variables(&LOCK_global_system_variables);
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-10-29 12:19:36 +01:00
|
|
|
/**
|
2009-12-22 10:35:56 +01:00
|
|
|
Return variable name and length for hashing of variables.
|
2009-10-29 12:19:36 +01:00
|
|
|
*/
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
|
|
|
|
my_bool first)
|
2002-08-13 02:18:39 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
*length= var->name.length;
|
|
|
|
return (uchar*) var->name.str;
|
2002-08-13 02:18:39 +03:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
sys_var_chain all_sys_vars = { NULL, NULL };
|
2007-12-12 12:14:59 +02:00
|
|
|
|
2010-01-06 22:42:07 -07:00
|
|
|
int sys_var_init()
|
2007-12-12 12:14:59 +02:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_ENTER("sys_var_init");
|
2007-12-12 12:14:59 +02:00
|
|
|
|
2010-01-06 22:42:07 -07:00
|
|
|
/* Must be already initialized. */
|
|
|
|
DBUG_ASSERT(system_charset_info != NULL);
|
2007-12-12 12:14:59 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (my_hash_init(&system_variable_hash, system_charset_info, 100, 0,
|
|
|
|
0, (my_hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
|
|
|
|
goto error;
|
2009-10-15 17:23:43 +05:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (mysql_add_sys_var_chain(all_sys_vars.first))
|
|
|
|
goto error;
|
2009-10-15 17:23:43 +05:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_RETURN(0);
|
2009-10-15 17:23:43 +05:00
|
|
|
|
2010-01-06 22:42:07 -07:00
|
|
|
error:
|
|
|
|
fprintf(stderr, "failed to initialize System variables");
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sys_var_add_options(DYNAMIC_ARRAY *long_options, int parse_flags)
|
|
|
|
{
|
|
|
|
uint saved_elements= long_options->elements;
|
|
|
|
|
|
|
|
DBUG_ENTER("sys_var_add_options");
|
|
|
|
|
|
|
|
for (sys_var *var=all_sys_vars.first; var; var= var->next)
|
|
|
|
{
|
|
|
|
if (var->register_option(long_options, parse_flags))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
error:
|
|
|
|
fprintf(stderr, "failed to initialize System variables");
|
|
|
|
long_options->elements= saved_elements;
|
|
|
|
DBUG_RETURN(1);
|
2006-07-04 17:40:40 +05:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
void sys_var_end()
|
2006-07-04 17:40:40 +05:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_ENTER("sys_var_end");
|
2006-07-04 17:40:40 +05:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
my_hash_free(&system_variable_hash);
|
2006-07-04 17:40:40 +05:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
for (sys_var *var=all_sys_vars.first; var; var= var->next)
|
2010-09-02 23:37:04 +05:00
|
|
|
var->cleanup();
|
2006-07-04 17:40:40 +05:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2006-07-04 17:40:40 +05:00
|
|
|
}
|
2004-12-29 20:30:37 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
/**
|
|
|
|
sys_var constructor
|
|
|
|
|
|
|
|
@param chain variables are linked into chain for mysql_add_sys_var_chain()
|
2011-05-21 10:21:08 +02:00
|
|
|
@param name_arg the name of the variable. Must be 0-terminated and exist
|
|
|
|
for the liftime of the sys_var object. @sa my_option::name
|
2009-12-22 10:35:56 +01:00
|
|
|
@param comment shown in mysqld --help, @sa my_option::comment
|
|
|
|
@param flags_arg or'ed flag_enum values
|
|
|
|
@param off offset of the global variable value from the
|
|
|
|
&global_system_variables.
|
|
|
|
@param getopt_id -1 for no command-line option, otherwise @sa my_option::id
|
|
|
|
@param getopt_arg_type @sa my_option::arg_type
|
|
|
|
@param show_val_type_arg what value_ptr() returns for sql_show.cc
|
|
|
|
@param def_val default value, @sa my_option::def_value
|
|
|
|
@param lock mutex or rw_lock that protects the global variable
|
|
|
|
*in addition* to LOCK_global_system_variables.
|
|
|
|
@param binlog_status_enum @sa binlog_status_enum
|
|
|
|
@param on_check_func a function to be called at the end of sys_var::check,
|
|
|
|
put your additional checks here
|
|
|
|
@param on_update_func a function to be called at the end of sys_var::update,
|
|
|
|
any post-update activity should happen here
|
2012-08-24 10:17:08 +02:00
|
|
|
@param substitute If non-NULL, this variable is deprecated and the
|
|
|
|
string describes what one should use instead. If an empty string,
|
|
|
|
the variable is deprecated but no replacement is offered.
|
2010-01-06 22:42:07 -07:00
|
|
|
@param parse_flag either PARSE_EARLY or PARSE_NORMAL
|
2009-12-22 10:35:56 +01:00
|
|
|
*/
|
|
|
|
sys_var::sys_var(sys_var_chain *chain, const char *name_arg,
|
|
|
|
const char *comment, int flags_arg, ptrdiff_t off,
|
|
|
|
int getopt_id, enum get_opt_arg_type getopt_arg_type,
|
|
|
|
SHOW_TYPE show_val_type_arg, longlong def_val,
|
|
|
|
PolyLock *lock, enum binlog_status_enum binlog_status_arg,
|
|
|
|
on_check_function on_check_func,
|
|
|
|
on_update_function on_update_func,
|
2012-08-24 10:17:08 +02:00
|
|
|
const char *substitute, int parse_flag) :
|
2009-12-22 10:35:56 +01:00
|
|
|
next(0),
|
|
|
|
binlog_status(binlog_status_arg),
|
2010-01-06 22:42:07 -07:00
|
|
|
flags(flags_arg), m_parse_flag(parse_flag), show_val_type(show_val_type_arg),
|
2009-12-22 10:35:56 +01:00
|
|
|
guard(lock), offset(off), on_check(on_check_func), on_update(on_update_func),
|
2012-08-24 10:17:08 +02:00
|
|
|
deprecation_substitute(substitute),
|
2009-12-22 10:35:56 +01:00
|
|
|
is_os_charset(FALSE)
|
|
|
|
{
|
2010-08-25 18:59:28 -06:00
|
|
|
/*
|
|
|
|
There is a limitation in handle_options() related to short options:
|
|
|
|
- either all short options should be declared when parsing in multiple stages,
|
|
|
|
- or none should be declared.
|
|
|
|
Because a lot of short options are used in the normal parsing phase
|
|
|
|
for mysqld, we enforce here that no short option is present
|
|
|
|
in the first (PARSE_EARLY) stage.
|
|
|
|
See handle_options() for details.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(parse_flag == PARSE_NORMAL || getopt_id <= 0 || getopt_id >= 255);
|
|
|
|
|
2011-05-21 10:21:08 +02:00
|
|
|
name.str= name_arg; // ER_NO_DEFAULT relies on 0-termination of name_arg
|
|
|
|
name.length= strlen(name_arg); // and so does this.
|
2009-12-22 10:35:56 +01:00
|
|
|
DBUG_ASSERT(name.length <= NAME_CHAR_LEN);
|
|
|
|
|
|
|
|
bzero(&option, sizeof(option));
|
|
|
|
option.name= name_arg;
|
|
|
|
option.id= getopt_id;
|
|
|
|
option.comment= comment;
|
|
|
|
option.arg_type= getopt_arg_type;
|
|
|
|
option.value= (uchar **)global_var_ptr();
|
|
|
|
option.def_value= def_val;
|
|
|
|
|
|
|
|
if (chain->last)
|
|
|
|
chain->last->next= this;
|
|
|
|
else
|
|
|
|
chain->first= this;
|
|
|
|
chain->last= this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sys_var::update(THD *thd, set_var *var)
|
|
|
|
{
|
|
|
|
enum_var_type type= var->type;
|
|
|
|
if (type == OPT_GLOBAL || scope() == GLOBAL)
|
2009-10-15 17:23:43 +05:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
/*
|
|
|
|
Yes, both locks need to be taken before an update, just as
|
|
|
|
both are taken to get a value. If we'll take only 'guard' here,
|
|
|
|
then value_ptr() for strings won't be safe in SHOW VARIABLES anymore,
|
|
|
|
to make it safe we'll need value_ptr_unlock().
|
|
|
|
*/
|
|
|
|
AutoWLock lock1(&PLock_global_system_variables);
|
|
|
|
AutoWLock lock2(guard);
|
|
|
|
return global_update(thd, var) ||
|
|
|
|
(on_update && on_update(this, thd, OPT_GLOBAL));
|
2009-10-15 17:23:43 +05:00
|
|
|
}
|
|
|
|
else
|
2009-12-22 10:35:56 +01:00
|
|
|
return session_update(thd, var) ||
|
|
|
|
(on_update && on_update(this, thd, OPT_SESSION));
|
2009-10-15 17:23:43 +05:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
uchar *sys_var::session_value_ptr(THD *thd, LEX_STRING *base)
|
2009-10-15 17:23:43 +05:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
return session_var_ptr(thd);
|
2009-10-15 17:23:43 +05:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
uchar *sys_var::global_value_ptr(THD *thd, LEX_STRING *base)
|
2009-10-15 17:23:43 +05:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
return global_var_ptr();
|
2009-10-15 17:23:43 +05:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
bool sys_var::check(THD *thd, set_var *var)
|
2007-07-30 11:33:50 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
if ((var->value && do_check(thd, var))
|
|
|
|
|| (on_check && on_check(this, thd, var)))
|
2007-07-30 11:33:50 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!thd->is_error())
|
|
|
|
{
|
|
|
|
char buff[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
String str(buff, sizeof(buff), system_charset_info), *res;
|
|
|
|
|
|
|
|
if (!var->value)
|
|
|
|
{
|
|
|
|
str.set(STRING_WITH_LEN("DEFAULT"), &my_charset_latin1);
|
|
|
|
res= &str;
|
|
|
|
}
|
|
|
|
else if (!(res=var->value->val_str(&str)))
|
|
|
|
{
|
|
|
|
str.set(STRING_WITH_LEN("NULL"), &my_charset_latin1);
|
|
|
|
res= &str;
|
|
|
|
}
|
|
|
|
ErrConvString err(res);
|
|
|
|
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr());
|
|
|
|
}
|
|
|
|
return true;
|
2007-07-30 11:33:50 +03:00
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
return false;
|
2007-07-30 11:33:50 +03:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
uchar *sys_var::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
|
2007-07-30 11:33:50 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
if (type == OPT_GLOBAL || scope() == GLOBAL)
|
2007-07-30 11:33:50 +03:00
|
|
|
{
|
2010-01-06 22:42:07 -07:00
|
|
|
mysql_mutex_assert_owner(&LOCK_global_system_variables);
|
2009-12-22 10:35:56 +01:00
|
|
|
AutoRLock lock(guard);
|
|
|
|
return global_value_ptr(thd, base);
|
2007-07-30 11:33:50 +03:00
|
|
|
}
|
|
|
|
else
|
2009-12-22 10:35:56 +01:00
|
|
|
return session_value_ptr(thd, base);
|
2007-07-30 11:33:50 +03:00
|
|
|
}
|
|
|
|
|
2013-02-25 10:28:25 +05:30
|
|
|
bool sys_var::set_default(THD *thd, set_var* var)
|
2007-07-30 11:33:50 +03:00
|
|
|
{
|
2013-02-25 10:28:25 +05:30
|
|
|
if (var->type == OPT_GLOBAL || scope() == GLOBAL)
|
|
|
|
global_save_default(thd, var);
|
2002-07-23 18:31:22 +03:00
|
|
|
else
|
2013-02-25 10:28:25 +05:30
|
|
|
session_save_default(thd, var);
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2013-02-25 10:28:25 +05:30
|
|
|
return check(thd, var) || update(thd, var);
|
2009-03-05 18:39:02 +00:00
|
|
|
}
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
void sys_var::do_deprecated_warning(THD *thd)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2012-08-24 10:17:08 +02:00
|
|
|
if (deprecation_substitute != NULL)
|
Backport of revno ## 2617.31.1, 2617.31.3, 2617.31.4, 2617.31.5,
2617.31.12, 2617.31.15, 2617.31.15, 2617.31.16, 2617.43.1
- initial changeset that introduced the fix for
Bug#989 and follow up fixes for all test suite failures
introduced in the initial changeset.
------------------------------------------------------------
revno: 2617.31.1
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 4284-6.0
timestamp: Fri 2009-03-06 19:17:00 -0300
message:
Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order
WL#4284: Transactional DDL locking
Currently the MySQL server does not keep metadata locks on
schema objects for the duration of a transaction, thus failing
to guarantee the integrity of the schema objects being used
during the transaction and to protect then from concurrent
DDL operations. This also poses a problem for replication as
a DDL operation might be replicated even thought there are
active transactions using the object being modified.
The solution is to defer the release of metadata locks until
a active transaction is either committed or rolled back. This
prevents other statements from modifying the table for the
entire duration of the transaction. This provides commitment
ordering for guaranteeing serializability across multiple
transactions.
- Incompatible change:
If MySQL's metadata locking system encounters a lock conflict,
the usual schema is to use the try and back-off technique to
avoid deadlocks -- this schema consists in releasing all locks
and trying to acquire them all in one go.
But in a transactional context this algorithm can't be utilized
as its not possible to release locks acquired during the course
of the transaction without breaking the transaction commitments.
To avoid deadlocks in this case, the ER_LOCK_DEADLOCK will be
returned if a lock conflict is encountered during a transaction.
Let's consider an example:
A transaction has two statements that modify table t1, then table
t2, and then commits. The first statement of the transaction will
acquire a shared metadata lock on table t1, and it will be kept
utill COMMIT to ensure serializability.
At the moment when the second statement attempts to acquire a
shared metadata lock on t2, a concurrent ALTER or DROP statement
might have locked t2 exclusively. The prescription of the current
locking protocol is that the acquirer of the shared lock backs off
-- gives up all his current locks and retries. This implies that
the entire multi-statement transaction has to be rolled back.
- Incompatible change:
FLUSH commands such as FLUSH PRIVILEGES and FLUSH TABLES WITH READ
LOCK won't cause locked tables to be implicitly unlocked anymore.
2009-12-05 02:02:48 +03:00
|
|
|
{
|
2012-08-24 10:17:08 +02:00
|
|
|
char buf1[NAME_CHAR_LEN + 3];
|
2009-12-22 10:35:56 +01:00
|
|
|
strxnmov(buf1, sizeof(buf1)-1, "@@", name.str, 0);
|
2012-08-24 10:17:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
if deprecation_substitute is an empty string,
|
|
|
|
there is no replacement for the syntax
|
|
|
|
*/
|
|
|
|
uint errmsg= deprecation_substitute[0] == '\0'
|
|
|
|
? ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT
|
|
|
|
: ER_WARN_DEPRECATED_SYNTAX;
|
2009-12-22 10:35:56 +01:00
|
|
|
if (thd)
|
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_WARN_DEPRECATED_SYNTAX, ER(errmsg),
|
2012-08-24 10:17:08 +02:00
|
|
|
buf1, deprecation_substitute);
|
2002-07-23 18:31:22 +03:00
|
|
|
else
|
2012-08-24 10:17:08 +02:00
|
|
|
sql_print_warning(ER_DEFAULT(errmsg), buf1, deprecation_substitute);
|
Backport of revno ## 2617.31.1, 2617.31.3, 2617.31.4, 2617.31.5,
2617.31.12, 2617.31.15, 2617.31.15, 2617.31.16, 2617.43.1
- initial changeset that introduced the fix for
Bug#989 and follow up fixes for all test suite failures
introduced in the initial changeset.
------------------------------------------------------------
revno: 2617.31.1
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 4284-6.0
timestamp: Fri 2009-03-06 19:17:00 -0300
message:
Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order
WL#4284: Transactional DDL locking
Currently the MySQL server does not keep metadata locks on
schema objects for the duration of a transaction, thus failing
to guarantee the integrity of the schema objects being used
during the transaction and to protect then from concurrent
DDL operations. This also poses a problem for replication as
a DDL operation might be replicated even thought there are
active transactions using the object being modified.
The solution is to defer the release of metadata locks until
a active transaction is either committed or rolled back. This
prevents other statements from modifying the table for the
entire duration of the transaction. This provides commitment
ordering for guaranteeing serializability across multiple
transactions.
- Incompatible change:
If MySQL's metadata locking system encounters a lock conflict,
the usual schema is to use the try and back-off technique to
avoid deadlocks -- this schema consists in releasing all locks
and trying to acquire them all in one go.
But in a transactional context this algorithm can't be utilized
as its not possible to release locks acquired during the course
of the transaction without breaking the transaction commitments.
To avoid deadlocks in this case, the ER_LOCK_DEADLOCK will be
returned if a lock conflict is encountered during a transaction.
Let's consider an example:
A transaction has two statements that modify table t1, then table
t2, and then commits. The first statement of the transaction will
acquire a shared metadata lock on table t1, and it will be kept
utill COMMIT to ensure serializability.
At the moment when the second statement attempts to acquire a
shared metadata lock on t2, a concurrent ALTER or DROP statement
might have locked t2 exclusively. The prescription of the current
locking protocol is that the acquirer of the shared lock backs off
-- gives up all his current locks and retries. This implies that
the entire multi-statement transaction has to be rolled back.
- Incompatible change:
FLUSH commands such as FLUSH PRIVILEGES and FLUSH TABLES WITH READ
LOCK won't cause locked tables to be implicitly unlocked anymore.
2009-12-05 02:02:48 +03:00
|
|
|
}
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
2009-09-23 13:20:48 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
/**
|
|
|
|
Throw warning (error in STRICT mode) if value for variable needed bounding.
|
|
|
|
Plug-in interface also uses this.
|
|
|
|
|
|
|
|
@param thd thread handle
|
|
|
|
@param name variable's name
|
|
|
|
@param fixed did we have to correct the value? (throw warn/err if so)
|
|
|
|
@param is_unsigned is value's type unsigned?
|
|
|
|
@param v variable's value
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
@retval true on error, false otherwise (warning or ok)
|
|
|
|
*/
|
|
|
|
bool throw_bounds_warning(THD *thd, const char *name,
|
|
|
|
bool fixed, bool is_unsigned, longlong v)
|
2004-04-28 12:08:54 +02:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
if (fixed || (!is_unsigned && v < 0))
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
char buf[22];
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (is_unsigned)
|
|
|
|
ullstr((ulonglong) v, buf);
|
2002-07-23 18:31:22 +03:00
|
|
|
else
|
2009-12-22 10:35:56 +01:00
|
|
|
llstr(v, buf);
|
2006-03-01 21:36:05 +01:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buf);
|
|
|
|
return true;
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_TRUNCATED_WRONG_VALUE,
|
|
|
|
ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
return false;
|
2004-04-28 12:08:54 +02:00
|
|
|
}
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
bool throw_bounds_warning(THD *thd, const char *name, bool fixed, double v)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
if (fixed)
|
2003-04-02 00:15:20 +02:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
char buf[64];
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-28 15:54:16 +03:00
|
|
|
my_gcvt(v, MY_GCVT_ARG_DOUBLE, sizeof(buf) - 1, buf, NULL);
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
if (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES)
|
|
|
|
{
|
|
|
|
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buf);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_TRUNCATED_WRONG_VALUE,
|
|
|
|
ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
|
2004-04-28 12:08:54 +02:00
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
return false;
|
2004-04-28 12:08:54 +02:00
|
|
|
}
|
2003-04-02 00:15:20 +02:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
CHARSET_INFO *sys_var::charset(THD *thd)
|
2002-10-02 13:33:08 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
return is_os_charset ? thd->variables.character_set_filesystem :
|
|
|
|
system_charset_info;
|
2002-10-02 13:33:08 +03:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
typedef struct old_names_map_st
|
2002-10-02 13:33:08 +03:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
const char *old_name;
|
|
|
|
const char *new_name;
|
|
|
|
} my_old_conv;
|
Bug #1039: tmpdir and datadir not available via @@ system variable syntax
Bug #19606: ssl variables are not displayed in show variables
Bug #19616: log_queries_not_using_indexes is not listed in show variables
Make basedir, datadir, tmpdir, log_queries_not_using_indexes, ssl_ca,
ssl_capath, ssl_cert, ssl_cipher, and ssl_key all available both from
SHOW VARIABLES and as @@variables.
As a side-effect of this change, log_queries_not_using_indexes can
be changed at runtime (but only globally, not per-connection).
2006-05-08 16:38:45 -07:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
static my_old_conv old_conv[]=
|
|
|
|
{
|
|
|
|
{ "cp1251_koi8" , "cp1251" },
|
|
|
|
{ "cp1250_latin2" , "cp1250" },
|
|
|
|
{ "kam_latin2" , "keybcs2" },
|
|
|
|
{ "mac_latin2" , "MacRoman" },
|
|
|
|
{ "macce_latin2" , "MacCE" },
|
|
|
|
{ "pc2_latin2" , "pclatin2" },
|
|
|
|
{ "vga_latin2" , "pclatin1" },
|
|
|
|
{ "koi8_cp1251" , "koi8r" },
|
|
|
|
{ "win1251ukr_koi8_ukr" , "win1251ukr" },
|
|
|
|
{ "koi8_ukr_win1251ukr" , "koi8u" },
|
|
|
|
{ NULL , NULL }
|
|
|
|
};
|
Bug #1039: tmpdir and datadir not available via @@ system variable syntax
Bug #19606: ssl variables are not displayed in show variables
Bug #19616: log_queries_not_using_indexes is not listed in show variables
Make basedir, datadir, tmpdir, log_queries_not_using_indexes, ssl_ca,
ssl_capath, ssl_cert, ssl_cipher, and ssl_key all available both from
SHOW VARIABLES and as @@variables.
As a side-effect of this change, log_queries_not_using_indexes can
be changed at runtime (but only globally, not per-connection).
2006-05-08 16:38:45 -07:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
CHARSET_INFO *get_old_charset_by_name(const char *name)
|
Bug #1039: tmpdir and datadir not available via @@ system variable syntax
Bug #19606: ssl variables are not displayed in show variables
Bug #19616: log_queries_not_using_indexes is not listed in show variables
Make basedir, datadir, tmpdir, log_queries_not_using_indexes, ssl_ca,
ssl_capath, ssl_cert, ssl_cipher, and ssl_key all available both from
SHOW VARIABLES and as @@variables.
As a side-effect of this change, log_queries_not_using_indexes can
be changed at runtime (but only globally, not per-connection).
2006-05-08 16:38:45 -07:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_old_conv *conv;
|
Bug #1039: tmpdir and datadir not available via @@ system variable syntax
Bug #19606: ssl variables are not displayed in show variables
Bug #19616: log_queries_not_using_indexes is not listed in show variables
Make basedir, datadir, tmpdir, log_queries_not_using_indexes, ssl_ca,
ssl_capath, ssl_cert, ssl_cipher, and ssl_key all available both from
SHOW VARIABLES and as @@variables.
As a side-effect of this change, log_queries_not_using_indexes can
be changed at runtime (but only globally, not per-connection).
2006-05-08 16:38:45 -07:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
for (conv= old_conv; conv->old_name; conv++)
|
|
|
|
{
|
|
|
|
if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
|
|
|
|
return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
|
|
|
|
}
|
|
|
|
return NULL;
|
2009-12-17 16:55:50 +05:30
|
|
|
}
|
|
|
|
|
2002-07-23 18:31:22 +03:00
|
|
|
/****************************************************************************
|
|
|
|
Main handling of variables:
|
|
|
|
- Initialisation
|
|
|
|
- Searching during parsing
|
|
|
|
- Update loop
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
/**
|
2009-12-22 10:35:56 +01:00
|
|
|
Add variables to the dynamic hash of system variables
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
@param first Pointer to first system variable to add
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2007-03-02 08:43:45 -08:00
|
|
|
0 SUCCESS
|
2009-12-22 10:35:56 +01:00
|
|
|
@retval
|
2007-03-02 08:43:45 -08:00
|
|
|
otherwise FAILURE
|
2002-07-23 18:31:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
int mysql_add_sys_var_chain(sys_var *first)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2005-11-06 01:36:40 +01:00
|
|
|
sys_var *var;
|
2009-12-22 10:35:56 +01:00
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
/* A write lock should be held on LOCK_system_variables_hash */
|
2009-12-22 10:35:56 +01:00
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
for (var= first; var; var= var->next)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2007-03-02 08:43:45 -08:00
|
|
|
/* this fails if there is a conflicting variable name. see HASH_UNIQUE */
|
2007-05-24 13:24:36 +03:00
|
|
|
if (my_hash_insert(&system_variable_hash, (uchar*) var))
|
2009-12-22 10:35:56 +01:00
|
|
|
{
|
|
|
|
fprintf(stderr, "*** duplicate variable name '%s' ?\n", var->name.str);
|
2007-03-02 08:43:45 -08:00
|
|
|
goto error;
|
2009-12-22 10:35:56 +01:00
|
|
|
}
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
2007-03-02 08:43:45 -08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
for (; first != var; first= first->next)
|
2009-10-14 20:37:38 +04:00
|
|
|
my_hash_delete(&system_variable_hash, (uchar*) first);
|
2007-03-02 08:43:45 -08:00
|
|
|
return 1;
|
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
/*
|
|
|
|
Remove variables to the dynamic hash of system variables
|
2009-12-22 10:35:56 +01:00
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
SYNOPSIS
|
|
|
|
mysql_del_sys_var_chain()
|
|
|
|
first Pointer to first system variable to remove
|
2009-12-22 10:35:56 +01:00
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
RETURN VALUES
|
|
|
|
0 SUCCESS
|
|
|
|
otherwise FAILURE
|
|
|
|
*/
|
2009-12-22 10:35:56 +01:00
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
int mysql_del_sys_var_chain(sys_var *first)
|
|
|
|
{
|
|
|
|
int result= 0;
|
2009-12-22 10:35:56 +01:00
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
/* A write lock should be held on LOCK_system_variables_hash */
|
2009-12-22 10:35:56 +01:00
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
for (sys_var *var= first; var; var= var->next)
|
2009-10-14 20:37:38 +04:00
|
|
|
result|= my_hash_delete(&system_variable_hash, (uchar*) var);
|
2007-03-02 08:43:45 -08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
|
|
|
|
{
|
|
|
|
return strcmp(a->name, b->name);
|
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-03-02 08:43:45 -08:00
|
|
|
Constructs an array of system variables for display to the user.
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
@param thd current thread
|
|
|
|
@param sorted If TRUE, the system variables should be sorted
|
|
|
|
@param type OPT_GLOBAL or OPT_SESSION for SHOW GLOBAL|SESSION VARIABLES
|
|
|
|
|
|
|
|
@retval
|
2007-03-02 08:43:45 -08:00
|
|
|
pointer Array of SHOW_VAR elements for display
|
2009-12-22 10:35:56 +01:00
|
|
|
@retval
|
2007-03-02 08:43:45 -08:00
|
|
|
NULL FAILURE
|
|
|
|
*/
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted, enum enum_var_type type)
|
2007-03-02 08:43:45 -08:00
|
|
|
{
|
|
|
|
int count= system_variable_hash.records, i;
|
2008-11-22 00:22:21 +01:00
|
|
|
int size= sizeof(SHOW_VAR) * (count + 1);
|
2007-03-02 08:43:45 -08:00
|
|
|
SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
2008-11-22 00:22:21 +01:00
|
|
|
SHOW_VAR *show= result;
|
2007-03-02 08:43:45 -08:00
|
|
|
|
|
|
|
for (i= 0; i < count; i++)
|
|
|
|
{
|
2009-10-14 20:37:38 +04:00
|
|
|
sys_var *var= (sys_var*) my_hash_element(&system_variable_hash, i);
|
2009-12-22 10:35:56 +01:00
|
|
|
|
|
|
|
// don't show session-only variables in SHOW GLOBAL VARIABLES
|
|
|
|
if (type == OPT_GLOBAL && var->check_type(type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
show->name= var->name.str;
|
2007-03-02 08:43:45 -08:00
|
|
|
show->value= (char*) var;
|
|
|
|
show->type= SHOW_SYS;
|
|
|
|
show++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort into order */
|
|
|
|
if (sorted)
|
2009-12-22 10:35:56 +01:00
|
|
|
my_qsort(result, show-result, sizeof(SHOW_VAR),
|
2007-10-18 15:17:21 +04:00
|
|
|
(qsort_cmp) show_cmp);
|
2009-12-22 10:35:56 +01:00
|
|
|
|
2007-03-02 08:43:45 -08:00
|
|
|
/* make last element empty */
|
|
|
|
bzero(show, sizeof(SHOW_VAR));
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
2007-03-02 08:43:45 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
/**
|
|
|
|
Find a user set-table variable.
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
@param str Name of system variable to find
|
2007-10-11 14:37:45 -04:00
|
|
|
@param length Length of variable. zero means that we should use strlen()
|
|
|
|
on the variable
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2009-12-22 10:35:56 +01:00
|
|
|
pointer pointer to variable definitions
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2009-12-22 10:35:56 +01:00
|
|
|
0 Unknown variable (error message is given)
|
2002-07-23 18:31:22 +03:00
|
|
|
*/
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
sys_var *intern_find_sys_var(const char *str, uint length)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2007-03-02 08:43:45 -08:00
|
|
|
sys_var *var;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This function is only called from the sql_plugin.cc.
|
|
|
|
A lock on LOCK_system_variable_hash should be held
|
|
|
|
*/
|
2009-10-14 20:37:38 +04:00
|
|
|
var= (sys_var*) my_hash_search(&system_variable_hash,
|
2009-12-22 10:35:56 +01:00
|
|
|
(uchar*) str, length ? length : strlen(str));
|
2002-07-23 18:31:22 +03:00
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
/**
|
|
|
|
Execute update of all variables.
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
First run a check of all variables that all updates will go ok.
|
|
|
|
If yes, then execute all updates, returning an error if any one failed.
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
This should ensure that in all normal cases none all or variables are
|
|
|
|
updated.
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
@param THD Thread id
|
2007-10-11 14:37:45 -04:00
|
|
|
@param var_list List of variables to update
|
2002-07-23 18:31:22 +03:00
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2009-12-22 10:35:56 +01:00
|
|
|
0 ok
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2009-12-22 10:35:56 +01:00
|
|
|
1 ERROR, message sent (normally no variables was updated)
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2002-09-22 18:02:39 +03:00
|
|
|
-1 ERROR, message not sent
|
2002-07-23 18:31:22 +03:00
|
|
|
*/
|
|
|
|
|
2002-09-22 18:02:39 +03:00
|
|
|
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2004-12-02 14:43:51 +02:00
|
|
|
int error;
|
2003-05-27 18:40:37 +03:00
|
|
|
List_iterator_fast<set_var_base> it(*var_list);
|
2003-08-19 00:08:08 +03:00
|
|
|
DBUG_ENTER("sql_set_variables");
|
2002-07-23 18:31:22 +03:00
|
|
|
|
|
|
|
set_var_base *var;
|
|
|
|
while ((var=it++))
|
|
|
|
{
|
2004-12-02 14:43:51 +02:00
|
|
|
if ((error= var->check(thd)))
|
2004-11-22 13:05:10 +03:00
|
|
|
goto err;
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
2009-12-22 10:35:56 +01:00
|
|
|
if (!(error= test(thd->is_error())))
|
2004-06-03 23:17:18 +02:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
it.rewind();
|
|
|
|
while ((var= it++))
|
|
|
|
error|= var->update(thd); // Returns 0, -1 or 1
|
2004-06-03 23:17:18 +02:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
err:
|
|
|
|
free_underlaid_joins(thd, &thd->lex->select_lex);
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
2004-06-03 23:17:18 +02:00
|
|
|
|
2002-07-23 18:31:22 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
Functions to handle SET mysql_internal_variable=const_expr
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2009-10-29 12:19:36 +01:00
|
|
|
/**
|
|
|
|
Verify that the supplied value is correct.
|
|
|
|
|
|
|
|
@param thd Thread handler
|
|
|
|
|
|
|
|
@return status code
|
2009-12-22 10:35:56 +01:00
|
|
|
@retval -1 Failure
|
|
|
|
@retval 0 Success
|
|
|
|
*/
|
2009-10-29 12:19:36 +01:00
|
|
|
|
2002-09-22 18:02:39 +03:00
|
|
|
int set_var::check(THD *thd)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2013-09-05 13:40:27 +05:30
|
|
|
var->do_deprecated_warning(thd);
|
2005-05-13 16:18:27 +05:00
|
|
|
if (var->is_readonly())
|
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name.str, "read only");
|
2005-05-13 16:18:27 +05:00
|
|
|
return -1;
|
|
|
|
}
|
2002-07-23 18:31:22 +03:00
|
|
|
if (var->check_type(type))
|
|
|
|
{
|
2004-11-12 14:34:00 +02:00
|
|
|
int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
|
2009-12-22 10:35:56 +01:00
|
|
|
my_error(err, MYF(0), var->name.str);
|
2002-09-22 18:02:39 +03:00
|
|
|
return -1;
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
|
|
|
if ((type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL)))
|
|
|
|
return 1;
|
|
|
|
/* value is a NULL pointer if we are using SET ... = DEFAULT */
|
|
|
|
if (!value)
|
|
|
|
return 0;
|
|
|
|
|
2005-02-09 02:50:45 +04:00
|
|
|
if ((!value->fixed &&
|
2005-07-01 07:05:42 +03:00
|
|
|
value->fix_fields(thd, &value)) || value->check_cols(1))
|
2002-09-22 18:02:39 +03:00
|
|
|
return -1;
|
2002-07-23 18:31:22 +03:00
|
|
|
if (var->check_update_type(value->result_type()))
|
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name.str);
|
2002-09-22 18:02:39 +03:00
|
|
|
return -1;
|
2003-10-06 14:11:16 +02:00
|
|
|
}
|
2002-09-22 18:02:39 +03:00
|
|
|
return var->check(thd, this) ? -1 : 0;
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
/**
|
|
|
|
Check variable, but without assigning value (used by PS).
|
2004-04-10 01:14:32 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
@param thd thread handler
|
2004-04-10 01:14:32 +03:00
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2009-12-22 10:35:56 +01:00
|
|
|
0 ok
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2009-12-22 10:35:56 +01:00
|
|
|
1 ERROR, message sent (normally no variables was updated)
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
|
|
|
-1 ERROR, message not sent
|
2004-04-10 01:14:32 +03:00
|
|
|
*/
|
2004-04-08 00:16:17 +03:00
|
|
|
int set_var::light_check(THD *thd)
|
|
|
|
{
|
|
|
|
if (var->check_type(type))
|
|
|
|
{
|
2004-11-12 14:34:00 +02:00
|
|
|
int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
|
2004-11-13 19:35:51 +02:00
|
|
|
my_error(err, MYF(0), var->name);
|
2004-04-08 00:16:17 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2004-04-10 01:14:32 +03:00
|
|
|
if (type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL))
|
2004-04-08 00:16:17 +03:00
|
|
|
return 1;
|
|
|
|
|
2005-07-01 07:05:42 +03:00
|
|
|
if (value && ((!value->fixed && value->fix_fields(thd, &value)) ||
|
2004-12-14 03:36:19 +03:00
|
|
|
value->check_cols(1)))
|
2004-04-08 00:16:17 +03:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-12 12:14:59 +02:00
|
|
|
/**
|
|
|
|
Update variable
|
2004-04-08 00:16:17 +03:00
|
|
|
|
2007-12-12 12:14:59 +02:00
|
|
|
@param thd thread handler
|
2009-12-22 10:35:56 +01:00
|
|
|
@returns 0|1 ok or ERROR
|
2007-12-12 12:14:59 +02:00
|
|
|
|
|
|
|
@note ERROR can be only due to abnormal operations involving
|
|
|
|
the server's execution evironment such as
|
|
|
|
out of memory, hard disk failure or the computer blows up.
|
|
|
|
Consider set_var::check() method if there is a need to return
|
|
|
|
an error due to logics.
|
|
|
|
*/
|
2002-09-22 18:02:39 +03:00
|
|
|
int set_var::update(THD *thd)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2013-02-25 10:28:25 +05:30
|
|
|
return value ? var->update(thd, this) : var->set_default(thd, this);
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
Functions to handle SET @user_variable=const_expr
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-09-22 18:02:39 +03:00
|
|
|
int set_var_user::check(THD *thd)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2003-11-02 17:27:35 +02:00
|
|
|
/*
|
|
|
|
Item_func_set_user_var can't substitute something else on its place =>
|
2004-04-28 12:08:54 +02:00
|
|
|
0 can be passed as last argument (reference on item)
|
2003-11-02 17:27:35 +02:00
|
|
|
*/
|
2005-07-01 07:05:42 +03:00
|
|
|
return (user_var_item->fix_fields(thd, (Item**) 0) ||
|
2009-12-22 10:35:56 +01:00
|
|
|
user_var_item->check(0)) ? -1 : 0;
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
/**
|
|
|
|
Check variable, but without assigning value (used by PS).
|
2004-04-10 01:14:32 +03:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
@param thd thread handler
|
2004-04-10 01:14:32 +03:00
|
|
|
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2009-12-22 10:35:56 +01:00
|
|
|
0 ok
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
2009-12-22 10:35:56 +01:00
|
|
|
1 ERROR, message sent (normally no variables was updated)
|
2007-10-11 14:37:45 -04:00
|
|
|
@retval
|
|
|
|
-1 ERROR, message not sent
|
2004-04-10 01:14:32 +03:00
|
|
|
*/
|
2004-04-08 00:16:17 +03:00
|
|
|
int set_var_user::light_check(THD *thd)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Item_func_set_user_var can't substitute something else on its place =>
|
|
|
|
0 can be passed as last argument (reference on item)
|
|
|
|
*/
|
2005-07-01 07:05:42 +03:00
|
|
|
return (user_var_item->fix_fields(thd, (Item**) 0));
|
2004-04-08 00:16:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-22 18:02:39 +03:00
|
|
|
int set_var_user::update(THD *thd)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
|
|
|
if (user_var_item->update())
|
|
|
|
{
|
|
|
|
/* Give an error if it's not given already */
|
2004-11-12 14:34:00 +02:00
|
|
|
my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0));
|
2002-09-22 18:02:39 +03:00
|
|
|
return -1;
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
Functions to handle SET PASSWORD
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-09-22 18:02:39 +03:00
|
|
|
int set_var_password::check(THD *thd)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2003-09-26 15:33:13 +05:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2002-07-23 18:31:22 +03:00
|
|
|
if (!user->host.str)
|
2005-08-22 15:48:50 -07:00
|
|
|
{
|
2008-12-24 19:14:59 +04:00
|
|
|
DBUG_ASSERT(thd->security_ctx->priv_host);
|
2005-09-15 22:29:07 +03:00
|
|
|
if (*thd->security_ctx->priv_host != 0)
|
2005-08-22 15:48:50 -07:00
|
|
|
{
|
2005-09-15 22:29:07 +03:00
|
|
|
user->host.str= (char *) thd->security_ctx->priv_host;
|
|
|
|
user->host.length= strlen(thd->security_ctx->priv_host);
|
2005-08-22 15:48:50 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
user->host.str= (char *)"%";
|
|
|
|
user->host.length= 1;
|
|
|
|
}
|
|
|
|
}
|
2008-12-24 19:14:59 +04:00
|
|
|
if (!user->user.str)
|
|
|
|
{
|
2010-08-09 11:32:50 +03:00
|
|
|
DBUG_ASSERT(thd->security_ctx->user);
|
|
|
|
user->user.str= (char *) thd->security_ctx->user;
|
|
|
|
user->user.length= strlen(thd->security_ctx->user);
|
2008-12-24 19:14:59 +04:00
|
|
|
}
|
2002-09-22 18:02:39 +03:00
|
|
|
/* Returns 1 as the function sends error to client */
|
2005-01-24 15:48:25 +01:00
|
|
|
return check_change_password(thd, user->host.str, user->user.str,
|
|
|
|
password, strlen(password)) ? 1 : 0;
|
2004-07-30 22:05:08 +02:00
|
|
|
#else
|
2003-09-26 15:33:13 +05:00
|
|
|
return 0;
|
|
|
|
#endif
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
|
|
|
|
2002-09-22 18:02:39 +03:00
|
|
|
int set_var_password::update(THD *thd)
|
2002-07-23 18:31:22 +03:00
|
|
|
{
|
2003-09-26 15:33:13 +05:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2002-09-22 18:02:39 +03:00
|
|
|
/* Returns 1 as the function sends error to client */
|
2004-07-30 22:05:08 +02:00
|
|
|
return change_password(thd, user->host.str, user->user.str, password) ?
|
2009-12-22 10:35:56 +01:00
|
|
|
1 : 0;
|
2003-09-26 15:33:13 +05:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2002-07-23 18:31:22 +03:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
Functions to handle SET NAMES and SET CHARACTER SET
|
|
|
|
*****************************************************************************/
|
2003-08-02 02:43:18 -07:00
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
int set_var_collation_client::check(THD *thd)
|
2003-11-18 13:47:27 +02:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
/* Currently, UCS-2 cannot be used as a client character set */
|
2011-02-18 12:46:55 +03:00
|
|
|
if (!is_supported_parser_charset(character_set_client))
|
2003-08-02 02:43:18 -07:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
|
|
|
|
character_set_client->csname);
|
|
|
|
return 1;
|
2003-08-02 02:43:18 -07:00
|
|
|
}
|
|
|
|
return 0;
|
2003-07-06 19:09:57 +03:00
|
|
|
}
|
|
|
|
|
2009-12-22 10:35:56 +01:00
|
|
|
int set_var_collation_client::update(THD *thd)
|
2006-02-14 22:36:11 +01:00
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
thd->variables.character_set_client= character_set_client;
|
|
|
|
thd->variables.character_set_results= character_set_results;
|
|
|
|
thd->variables.collation_connection= collation_connection;
|
|
|
|
thd->update_charset();
|
|
|
|
thd->protocol_text.init(thd);
|
|
|
|
thd->protocol_binary.init(thd);
|
2006-02-14 22:36:11 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|