~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/get_system_var.cc

  • Committer: Brian Aker
  • Date: 2008-07-02 21:16:23 UTC
  • Revision ID: brian@tangent.org-20080702211623-lix7xclpnm217nov
Remaining major pieces of PS removed

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 "config.h"
21
 
 
22
 
#include <drizzled/error.h>
23
 
#include <drizzled/function/get_system_var.h>
24
 
#include <drizzled/session.h>
25
 
 
26
 
namespace drizzled
27
 
{
28
 
 
29
 
Item_func_get_system_var::
30
 
Item_func_get_system_var(sys_var *var_arg, sql_var_t var_type_arg,
31
 
                       LEX_STRING *component_arg, const char *name_arg,
32
 
                       size_t name_len_arg)
33
 
  :var(var_arg), var_type(var_type_arg), component(*component_arg)
34
 
{
35
 
  /* set_name() will allocate the name */
36
 
  set_name(name_arg, name_len_arg, system_charset_info);
37
 
}
38
 
 
39
 
 
40
 
bool
41
 
Item_func_get_system_var::fix_fields(Session *session, Item **ref)
42
 
{
43
 
  Item *item;
44
 
 
45
 
  /*
46
 
    Evaluate the system variable and substitute the result (a basic constant)
47
 
    instead of this item. If the variable can not be evaluated,
48
 
    the error is reported in sys_var::item().
49
 
  */
50
 
  if (!(item= var->item(session, var_type, &component)))
51
 
    return(1);                             // Impossible
52
 
  item->set_name(name, 0, system_charset_info); // don't allocate a new name
53
 
  session->change_item_tree(ref, item);
54
 
 
55
 
  return(0);
56
 
}
57
 
 
58
 
Item *get_system_var(Session *session, sql_var_t var_type, LEX_STRING name,
59
 
                     LEX_STRING component)
60
 
{
61
 
  sys_var *var;
62
 
  LEX_STRING *base_name, *component_name;
63
 
 
64
 
  if (component.str)
65
 
  {
66
 
    base_name= &component;
67
 
    component_name= &name;
68
 
  }
69
 
  else
70
 
  {
71
 
    base_name= &name;
72
 
    component_name= &component;                 // Empty string
73
 
  }
74
 
 
75
 
  if (!(var= find_sys_var(session, base_name->str, base_name->length)))
76
 
    return 0;
77
 
  if (component.str)
78
 
  {
79
 
    my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), base_name->str);
80
 
    return 0;
81
 
  }
82
 
  session->lex->setCacheable(false);
83
 
 
84
 
  set_if_smaller(component_name->length, (size_t)MAX_SYS_VAR_LENGTH);
85
 
 
86
 
  return new Item_func_get_system_var(var, var_type, component_name,
87
 
                                      NULL, 0);
88
 
}
89
 
 
90
 
 
91
 
} /* namespace drizzled */