~drizzle-trunk/drizzle/development

492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
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
492.3.27 by Lee
merge latest changes from the trunk and changes to get drizzle building on Soalris 10 (SPARC)
22
#include <drizzled/error.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
23
#include <drizzled/function/get_system_var.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
24
#include <drizzled/session.h>
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
25
26
Item_func_get_system_var::
27
Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg,
28
                       LEX_STRING *component_arg, const char *name_arg,
29
                       size_t name_len_arg)
30
  :var(var_arg), var_type(var_type_arg), component(*component_arg)
31
{
32
  /* set_name() will allocate the name */
33
  set_name(name_arg, name_len_arg, system_charset_info);
34
}
35
36
37
bool
38
Item_func_get_system_var::fix_fields(Session *session, Item **ref)
39
{
40
  Item *item;
41
42
  /*
43
    Evaluate the system variable and substitute the result (a basic constant)
44
    instead of this item. If the variable can not be evaluated,
45
    the error is reported in sys_var::item().
46
  */
47
  if (!(item= var->item(session, var_type, &component)))
48
    return(1);                             // Impossible
49
  item->set_name(name, 0, system_charset_info); // don't allocate a new name
50
  session->change_item_tree(ref, item);
51
52
  return(0);
53
}
54
55
Item *get_system_var(Session *session, enum_var_type var_type, LEX_STRING name,
56
                     LEX_STRING component)
57
{
58
  sys_var *var;
59
  LEX_STRING *base_name, *component_name;
60
61
  if (component.str)
62
  {
63
    base_name= &component;
64
    component_name= &name;
65
  }
66
  else
67
  {
68
    base_name= &name;
69
    component_name= &component;                 // Empty string
70
  }
71
72
  if (!(var= find_sys_var(session, base_name->str, base_name->length)))
73
    return 0;
74
  if (component.str)
75
  {
1106.4.2 by Brian Aker
Remove multi key cache
76
    my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), base_name->str);
77
    return 0;
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
78
  }
79
937.2.6 by Stewart Smith
make set_if_bigger typesafe for C and C++. Fix up everywhere.
80
  set_if_smaller(component_name->length, (size_t)MAX_SYS_VAR_LENGTH);
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
81
82
  return new Item_func_get_system_var(var, var_type, component_name,
83
                                      NULL, 0);
84
}
85