21
21
#include "config.h"
23
#include <drizzled/plugin/function.h>
24
23
#include <drizzled/session.h>
27
using namespace drizzled;
29
#include <drizzled/function/str/strfunc.h>
31
class UserFunction :public Item_str_func
34
bool init (const char *user, const char *host);
39
str_value.set("", 0, system_charset_info);
41
String *val_str(String *)
44
return (null_value ? 0 : &str_value);
46
bool fix_fields(Session *session, Item **ref);
47
void fix_length_and_dec()
49
max_length= (USERNAME_CHAR_LENGTH + HOSTNAME_LENGTH + 1) *
50
system_charset_info->mbmaxlen;
52
const char *func_name() const { return "user"; }
53
const char *fully_qualified_func_name() const { return "user()"; }
54
int save_in_field(Field *field,
57
return save_str_value_in_field(field, &str_value);
63
make USER() replicate properly (currently it is replicated to "")
65
bool UserFunction::init(const char *user, const char *host)
24
#include "plugin/utility_functions/functions.h"
29
namespace utility_functions
33
String *User::val_str(String *str)
67
35
assert(fixed == 1);
69
// For system threads (e.g. replication SQL thread) user may be empty
72
const CHARSET_INFO * const cs= str_value.charset();
73
uint32_t res_length= (strlen(user)+strlen(host)+2) * cs->mbmaxlen;
75
if (str_value.alloc(res_length))
81
res_length=cs->cset->snprintf(cs, (char*)str_value.ptr(), res_length,
83
str_value.length(res_length);
84
str_value.mark_as_const();
90
bool UserFunction::fix_fields(Session *session, Item **ref)
92
return (Item_str_func::fix_fields(session, ref) ||
93
init(session->getSecurityContext().getUser().c_str(),
94
session->getSecurityContext().getIp().c_str()));
98
plugin::Create_function<UserFunction> *user_function= NULL;
100
static int initialize(drizzled::module::Context &context)
102
user_function= new plugin::Create_function<UserFunction>("user");
103
context.add(user_function);
107
DRIZZLE_DECLARE_PLUGIN
113
"USER() and CURRENT_USER()",
115
initialize, /* Plugin Init */
116
NULL, /* system variables */
117
NULL /* config options */
119
DRIZZLE_DECLARE_PLUGIN_END;
36
Session *session= current_session;
37
if (session->getSecurityContext().getUser().empty())
44
str->copy(session->getSecurityContext().getUser().c_str(), session->getSecurityContext().getUser().length(), system_charset_info);
49
} /* namespace utility_functions */
50
} /* namespace drizzled */