~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/param.h

move math functions to drizzled/function/math directory

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_ITEM_PARAM_H
 
21
#define DRIZZLED_ITEM_PARAM_H
 
22
 
 
23
/* Item represents one placeholder ('?') of prepared statement */
 
24
 
 
25
class Item_param :public Item
 
26
{
 
27
  char cnvbuf[MAX_FIELD_WIDTH];
 
28
  String cnvstr;
 
29
  Item *cnvitem;
 
30
 
 
31
public:
 
32
  enum enum_item_param_state
 
33
  {
 
34
    NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
 
35
    STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
 
36
    DECIMAL_VALUE
 
37
  } state;
 
38
 
 
39
  /*
 
40
    A buffer for string and long data values. Historically all allocated
 
41
    values returned from val_str() were treated as eligible to
 
42
    modification. I. e. in some cases Item_func_concat can append it's
 
43
    second argument to return value of the first one. Because of that we
 
44
    can't return the original buffer holding string data from val_str(),
 
45
    and have to have one buffer for data and another just pointing to
 
46
    the data. This is the latter one and it's returned from val_str().
 
47
    Can not be declared inside the union as it's not a POD type.
 
48
  */
 
49
  String str_value_ptr;
 
50
  my_decimal decimal_value;
 
51
  union
 
52
  {
 
53
    int64_t integer;
 
54
    double   real;
 
55
    /*
 
56
      Character sets conversion info for string values.
 
57
      Character sets of client and connection defined at bind time are used
 
58
      for all conversions, even if one of them is later changed (i.e.
 
59
      between subsequent calls to mysql_stmt_execute).
 
60
    */
 
61
    struct CONVERSION_INFO
 
62
    {
 
63
      const CHARSET_INFO *character_set_client;
 
64
      const CHARSET_INFO *character_set_of_placeholder;
 
65
      /*
 
66
        This points at character set of connection if conversion
 
67
        to it is required (i. e. if placeholder typecode is not BLOB).
 
68
        Otherwise it's equal to character_set_client (to simplify
 
69
        check in convert_str_value()).
 
70
      */
 
71
      const CHARSET_INFO *final_character_set_of_str_value;
 
72
    } cs_info;
 
73
    DRIZZLE_TIME     time;
 
74
  } value;
 
75
 
 
76
  /* Cached values for virtual methods to save us one switch.  */
 
77
  enum Item_result item_result_type;
 
78
  enum Type item_type;
 
79
 
 
80
  /*
 
81
    Used when this item is used in a temporary table.
 
82
    This is NOT placeholder metadata sent to client, as this value
 
83
    is assigned after sending metadata (in setup_one_conversion_function).
 
84
    For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
 
85
    in result set and placeholders metadata, no matter what type you will
 
86
    supply for this placeholder in mysql_stmt_execute.
 
87
  */
 
88
  enum enum_field_types param_type;
 
89
  /*
 
90
    Offset of placeholder inside statement text. Used to create
 
91
    no-placeholders version of this statement for the binary log.
 
92
  */
 
93
  uint32_t pos_in_query;
 
94
 
 
95
  Item_param(uint32_t pos_in_query_arg);
 
96
 
 
97
  enum Item_result result_type () const { return item_result_type; }
 
98
  enum Type type() const { return item_type; }
 
99
  enum_field_types field_type() const { return param_type; }
 
100
 
 
101
  double val_real();
 
102
  int64_t val_int();
 
103
  my_decimal *val_decimal(my_decimal*);
 
104
  String *val_str(String*);
 
105
  bool get_time(DRIZZLE_TIME *tm);
 
106
  bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
 
107
  int  save_in_field(Field *field, bool no_conversions);
 
108
 
 
109
  void set_null();
 
110
  void set_int(int64_t i, uint32_t max_length_arg);
 
111
  void set_double(double i);
 
112
  void set_decimal(char *str, ulong length);
 
113
  bool set_str(const char *str, ulong length);
 
114
  bool set_longdata(const char *str, ulong length);
 
115
  void set_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type type,
 
116
                uint32_t max_length_arg);
 
117
  bool set_from_user_var(Session *session, const user_var_entry *entry);
 
118
  void reset();
 
119
  /*
 
120
    Assign placeholder value from bind data.
 
121
    Note, that 'len' has different semantics in embedded library (as we
 
122
    don't need to check that packet is not broken there). See
 
123
    sql_prepare.cc for details.
 
124
  */
 
125
  void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
 
126
 
 
127
  const String *query_val_str(String *str) const;
 
128
 
 
129
  bool convert_str_value(Session *session);
 
130
 
 
131
  /*
 
132
    If value for parameter was not set we treat it as non-const
 
133
    so noone will use parameters value in fix_fields still
 
134
    parameter is constant during execution.
 
135
  */
 
136
  virtual table_map used_tables() const
 
137
  { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
 
138
  virtual void print(String *str, enum_query_type query_type);
 
139
  bool is_null()
 
140
  { assert(state != NO_VALUE); return state == NULL_VALUE; }
 
141
  bool basic_const_item() const;
 
142
  /*
 
143
    This method is used to make a copy of a basic constant item when
 
144
    propagating constants in the optimizer. The reason to create a new
 
145
    item and not use the existing one is not precisely known (2005/04/16).
 
146
    Probably we are trying to preserve tree structure of items, in other
 
147
    words, avoid pointing at one item from two different nodes of the tree.
 
148
    Return a new basic constant item if parameter value is a basic
 
149
    constant, assert otherwise. This method is called only if
 
150
    basic_const_item returned true.
 
151
  */
 
152
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
 
153
  Item *clone_item();
 
154
  /*
 
155
    Implement by-value equality evaluation if parameter value
 
156
    is set and is a basic constant (integer, real or string).
 
157
    Otherwise return false.
 
158
  */
 
159
  bool eq(const Item *item, bool binary_cmp) const;
 
160
  /** Item is a argument to a limit clause. */
 
161
  bool limit_clause_param;
 
162
};
 
163
 
 
164
#endif /* DRIZZLED_ITEM_PARAM_H */