1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
22
#include <drizzled/function/str/user.h>
23
#include <drizzled/session.h>
30
make USER() replicate properly (currently it is replicated to "")
32
bool Item_func_user::init(const char *user, const char *host)
36
// For system threads (e.g. replication SQL thread) user may be empty
39
const CHARSET_INFO * const cs= str_value.charset();
40
uint32_t res_length= (strlen(user)+strlen(host)+2) * cs->mbmaxlen;
42
if (str_value.alloc(res_length))
48
res_length=cs->cset->snprintf(cs, (char*)str_value.ptr(), res_length,
50
str_value.length(res_length);
51
str_value.mark_as_const();
57
bool Item_func_user::fix_fields(Session *session, Item **ref)
59
return (Item_str_func::fix_fields(session, ref) ||
60
init(session->getSecurityContext().getUser().c_str(),
61
session->getSecurityContext().getIp().c_str()));
65
bool Item_func_current_user::fix_fields(Session *session, Item **ref)
67
if (Item_str_func::fix_fields(session, ref))
70
const SecurityContext *ctx= &session->getSecurityContext();
71
return init(ctx->getUser().c_str(), ctx->getIp().c_str());
74
} /* namespace drizzled */