~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
21
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>
2148.7.12 by Brian Aker
Merge in header fixes.
25
#include <drizzled/sys_var.h>
2234.1.3 by Olaf van der Spek
Refactor includes
26
#include <drizzled/sql_lex.h>
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
27
2234.1.3 by Olaf van der Spek
Refactor includes
28
namespace drizzled {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
29
2445.1.14 by Olaf van der Spek
Refactor
30
Item_func_get_system_var::Item_func_get_system_var(sys_var *var_arg, sql_var_t var_type_arg,
2445.1.21 by Olaf van der Spek
Use union instead of struct for YYSTYPE
31
                       str_ref component_arg, const char *name_arg, size_t name_len_arg)
32
  : var(var_arg), var_type(var_type_arg), component(component_arg)
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
33
{
34
  /* set_name() will allocate the name */
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
35
  set_name(name_arg, name_len_arg);
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
36
}
37
38
2445.1.14 by Olaf van der Spek
Refactor
39
bool Item_func_get_system_var::fix_fields(Session *session, Item **ref)
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
40
{
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
  */
2445.1.17 by Olaf van der Spek
Refactor
47
  Item *item= var->item(session, var_type);
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
48
  if (not item)
2318.6.77 by Olaf van der Spek
Refactor
49
    return 1;                             // Impossible
2148.7.12 by Brian Aker
Merge in header fixes.
50
2318.9.1 by Olaf van der Spek
Refactor Item::set_name() calls
51
  item->set_name(name, 0); // don't allocate a new name
2197.3.1 by Olaf van der Spek
Remove Session::change_item_tree
52
  *ref= item;
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
53
2318.6.58 by Olaf van der Spek
Refactor
54
  return 0;
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
55
}
56
2445.1.21 by Olaf van der Spek
Use union instead of struct for YYSTYPE
57
Item *get_system_var(Session *session, sql_var_t var_type, str_ref name, str_ref component)
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
58
{
2445.1.21 by Olaf van der Spek
Use union instead of struct for YYSTYPE
59
  str_ref *base_name, *component_name;
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
60
2430.1.1 by Olaf van der Spek
Use lex_string assign(), data() and size()
61
  if (component.data())
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
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
2445.1.14 by Olaf van der Spek
Refactor
72
  sys_var *var= find_sys_var(base_name->data());
73
  if (not var)
74
    return NULL;
2430.1.1 by Olaf van der Spek
Use lex_string assign(), data() and size()
75
  if (component.data())
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
76
  {
2430.1.1 by Olaf van der Spek
Use lex_string assign(), data() and size()
77
    my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), base_name->data());
2445.1.14 by Olaf van der Spek
Refactor
78
    return NULL;
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
79
  }
2227.4.8 by Olaf van der Spek
Session::lex()
80
  session->lex().setCacheable(false);
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
81
2433.1.6 by Olaf van der Spek
USe data() and size()
82
  if (component_name->size() > MAX_SYS_VAR_LENGTH)
83
    component_name->assign(component_name->data(), MAX_SYS_VAR_LENGTH);
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
84
2445.1.21 by Olaf van der Spek
Use union instead of struct for YYSTYPE
85
  return new Item_func_get_system_var(var, var_type, *component_name, NULL, 0);
492.3.24 by Lee
more changes to move functions from item_func.cc/h to the functions directory
86
}
87
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
88
89
} /* namespace drizzled */