~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

  • Committer: Monty Taylor
  • Date: 2010-10-25 18:26:50 UTC
  • mto: (1879.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 1880.
  • Revision ID: mordred@inaugust.com-20101025182650-7k11plnoi78sy1gl
Split set_var.* into sys_var.* and set_var.*

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
#ifndef DRIZZLED_SET_VAR_H
 
21
#define DRIZZLED_SET_VAR_H
 
22
 
 
23
#include "drizzled/function/func.h"
 
24
#include "drizzled/function/set_user_var.h"
 
25
#include "drizzled/item/string.h"
 
26
#include "drizzled/item/field.h"
 
27
 
 
28
namespace drizzled
 
29
{
 
30
 
 
31
class Time_zone;
 
32
typedef struct my_locale_st MY_LOCALE;
 
33
 
 
34
/* Classes to support the SET command */
 
35
 
 
36
 
 
37
/****************************************************************************
 
38
  Variables that are changable runtime are declared using the
 
39
  following classes
 
40
****************************************************************************/
 
41
 
 
42
/****************************************************************************
 
43
  Classes for parsing of the SET command
 
44
****************************************************************************/
 
45
 
 
46
class set_var_base :public memory::SqlAlloc
 
47
{
 
48
public:
 
49
  set_var_base() {}
 
50
  virtual ~set_var_base() {}
 
51
  virtual int check(Session *session)=0;        /* To check privileges etc. */
 
52
  virtual int update(Session *session)=0;       /* To set the value */
 
53
  /* light check for PS */
 
54
};
 
55
 
 
56
/* MySQL internal variables */
 
57
class set_var :public set_var_base
 
58
{
 
59
public:
 
60
  sys_var *var;
 
61
  Item *value;
 
62
  sql_var_t type;
 
63
  union
 
64
  {
 
65
    const CHARSET_INFO *charset;
 
66
    uint32_t uint32_t_value;
 
67
    uint64_t uint64_t_value;
 
68
    size_t size_t_value;
 
69
    plugin::StorageEngine *storage_engine;
 
70
    Time_zone *time_zone;
 
71
    MY_LOCALE *locale_value;
 
72
  } save_result;
 
73
  LEX_STRING base;                      /* for structs */
 
74
 
 
75
  set_var(sql_var_t type_arg, sys_var *var_arg,
 
76
          const LEX_STRING *base_name_arg, Item *value_arg)
 
77
    :var(var_arg), type(type_arg), base(*base_name_arg)
 
78
  {
 
79
    /*
 
80
      If the set value is a field, change it to a string to allow things like
 
81
      SET table_type=MYISAM;
 
82
    */
 
83
    if (value_arg && value_arg->type() == Item::FIELD_ITEM)
 
84
    {
 
85
      Item_field *item= (Item_field*) value_arg;
 
86
      if (!(value=new Item_string(item->field_name,
 
87
                  (uint32_t) strlen(item->field_name),
 
88
                                  item->collation.collation)))
 
89
        value=value_arg;                        /* Give error message later */
 
90
    }
 
91
    else
 
92
      value=value_arg;
 
93
  }
 
94
  int check(Session *session);
 
95
  int update(Session *session);
 
96
};
 
97
 
 
98
/* User variables like @my_own_variable */
 
99
 
 
100
class set_var_user: public set_var_base
 
101
{
 
102
  Item_func_set_user_var *user_var_item;
 
103
public:
 
104
  set_var_user(Item_func_set_user_var *item)
 
105
    :user_var_item(item)
 
106
  {}
 
107
  int check(Session *session);
 
108
  int update(Session *session);
 
109
};
 
110
 
 
111
int sql_set_variables(Session *session, List<set_var_base> *var_list);
 
112
 
 
113
} /* namespace drizzled */
 
114
 
 
115
#endif /* DRIZZLED_SET_VAR_H */