summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-10-18 06:55:26 -0700
committerSergei Golubchik <sergii@pisem.net>2013-10-18 06:55:26 -0700
commit8122996a599fcb6dc600f27fddbed47a2579c6b8 (patch)
treed27476e2a6491b2b7ffa5247df617a14b6bfd4c0 /sql
parent1ac0b920d572ec393a2b482b6fa0686a6708abdd (diff)
downloadmariadb-git-8122996a599fcb6dc600f27fddbed47a2579c6b8.tar.gz
CURRENT_ROLE() function
Diffstat (limited to 'sql')
-rw-r--r--sql/item_strfunc.cc26
-rw-r--r--sql/item_strfunc.h22
-rw-r--r--sql/sql_yacc.yy8
3 files changed, 49 insertions, 7 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 02d64952459..66fae0bed10 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -2332,16 +2332,28 @@ bool Item_func_current_user::fix_fields(THD *thd, Item **ref)
if (Item_func_sysconst::fix_fields(thd, ref))
return TRUE;
- Security_context *ctx=
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- (context->security_ctx
- ? context->security_ctx : thd->security_ctx);
-#else
- thd->security_ctx;
-#endif /*NO_EMBEDDED_ACCESS_CHECKS*/
+ Security_context *ctx= context->security_ctx
+ ? context->security_ctx : thd->security_ctx;
return init(ctx->priv_user, ctx->priv_host);
}
+bool Item_func_current_role::fix_fields(THD *thd, Item **ref)
+{
+ if (Item_func_sysconst::fix_fields(thd, ref))
+ return 1;
+
+ Security_context *ctx= context->security_ctx
+ ? context->security_ctx : thd->security_ctx;
+
+ const char *role= ctx->priv_role[0] ? ctx->priv_role : NONE_ROLE;
+
+ if (str_value.copy(role, strlen(role), system_charset_info))
+ return 1;
+
+ str_value.mark_as_const();
+ return 0;
+}
+
void Item_func_soundex::fix_length_and_dec()
{
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index e09dee18d4f..8d9bda4902e 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -580,6 +580,28 @@ public:
};
+class Item_func_current_role :public Item_func_sysconst
+{
+ Name_resolution_context *context;
+
+public:
+ Item_func_current_role(Name_resolution_context *context_arg)
+ : context(context_arg) {}
+ bool fix_fields(THD *thd, Item **ref);
+ void fix_length_and_dec()
+ { max_length= username_char_length * SYSTEM_CHARSET_MBMAXLEN; }
+ int save_in_field(Field *field, bool no_conversions)
+ { return save_str_value_in_field(field, &str_value); }
+ const char *func_name() const { return "current_role"; }
+ const char *fully_qualified_func_name() const { return "current_role()"; }
+ String *val_str(String *)
+ {
+ DBUG_ASSERT(fixed == 1);
+ return (null_value ? 0 : &str_value);
+ }
+};
+
+
class Item_func_soundex :public Item_str_func
{
String tmp_value;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 38f9709f180..9ed7e8e8173 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -8648,6 +8648,14 @@ function_call_keyword:
Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
Lex->safe_to_cache_query= 0;
}
+ | CURRENT_ROLE optional_braces
+ {
+ $$= new (thd->mem_root) Item_func_current_role(Lex->current_context());
+ if ($$ == NULL)
+ MYSQL_YYABORT;
+ Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
+ Lex->safe_to_cache_query= 0;
+ }
| DATE_SYM '(' expr ')'
{
$$= new (thd->mem_root) Item_date_typecast($3);