~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/functions/str/user.cc

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
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
 
 
20
 
#include <drizzled/server_includes.h>
21
 
#include CSTDINT_H
22
 
#include <drizzled/functions/str/user.h>
23
 
#include <drizzled/session.h>
24
 
 
25
 
/**
26
 
  @todo
27
 
  make USER() replicate properly (currently it is replicated to "")
28
 
*/
29
 
bool Item_func_user::init(const char *user, const char *host)
30
 
{
31
 
  assert(fixed == 1);
32
 
 
33
 
  // For system threads (e.g. replication SQL thread) user may be empty
34
 
  if (user)
35
 
  {
36
 
    const CHARSET_INFO * const cs= str_value.charset();
37
 
    uint32_t res_length= (strlen(user)+strlen(host)+2) * cs->mbmaxlen;
38
 
 
39
 
    if (str_value.alloc(res_length))
40
 
    {
41
 
      null_value=1;
42
 
      return true;
43
 
    }
44
 
 
45
 
    res_length=cs->cset->snprintf(cs, (char*)str_value.ptr(), res_length,
46
 
                                  "%s@%s", user, host);
47
 
    str_value.length(res_length);
48
 
    str_value.mark_as_const();
49
 
  }
50
 
  return false;
51
 
}
52
 
 
53
 
 
54
 
bool Item_func_user::fix_fields(Session *session, Item **ref)
55
 
{
56
 
  return (Item_func_sysconst::fix_fields(session, ref) ||
57
 
          init(session->main_security_ctx.user,
58
 
               session->main_security_ctx.ip));
59
 
}
60
 
 
61
 
 
62
 
bool Item_func_current_user::fix_fields(Session *session, Item **ref)
63
 
{
64
 
  if (Item_func_sysconst::fix_fields(session, ref))
65
 
    return true;
66
 
 
67
 
  Security_context *ctx=
68
 
                         session->security_ctx;
69
 
  return init(ctx->user, ctx->ip);
70
 
}
71
 
 
72