~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/param.h

Merged trunk.

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.
69
 
      */
70
 
      const CHARSET_INFO *final_character_set_of_str_value;
71
 
    } cs_info;
72
 
    DRIZZLE_TIME     time;
73
 
  } value;
74
 
 
75
 
  /* Cached values for virtual methods to save us one switch.  */
76
 
  enum Item_result item_result_type;
77
 
  enum Type item_type;
78
 
 
79
 
  /*
80
 
    Used when this item is used in a temporary table.
81
 
    This is NOT placeholder metadata sent to client, as this value
82
 
    is assigned after sending metadata (in setup_one_conversion_function).
83
 
    For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
84
 
    in result set and placeholders metadata, no matter what type you will
85
 
    supply for this placeholder in mysql_stmt_execute.
86
 
  */
87
 
  enum enum_field_types param_type;
88
 
  /*
89
 
    Offset of placeholder inside statement text. Used to create
90
 
    no-placeholders version of this statement for the binary log.
91
 
  */
92
 
  uint32_t pos_in_query;
93
 
 
94
 
  Item_param(uint32_t pos_in_query_arg);
95
 
 
96
 
  enum Item_result result_type () const { return item_result_type; }
97
 
  enum Type type() const { return item_type; }
98
 
  enum_field_types field_type() const { return param_type; }
99
 
 
100
 
  double val_real();
101
 
  int64_t val_int();
102
 
  my_decimal *val_decimal(my_decimal*);
103
 
  String *val_str(String*);
104
 
  bool get_time(DRIZZLE_TIME *tm);
105
 
  bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
106
 
  int  save_in_field(Field *field, bool no_conversions);
107
 
 
108
 
  void set_null();
109
 
  void set_int(int64_t i, uint32_t max_length_arg);
110
 
  void set_double(double i);
111
 
  void set_decimal(char *str, ulong length);
112
 
  bool set_str(const char *str, ulong length);
113
 
  bool set_longdata(const char *str, ulong length);
114
 
  void set_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type type,
115
 
                uint32_t max_length_arg);
116
 
  bool set_from_user_var(Session *session, const user_var_entry *entry);
117
 
  void reset();
118
 
  /*
119
 
    Assign placeholder value from bind data.
120
 
    Note, that 'len' has different semantics in embedded library (as we
121
 
    don't need to check that packet is not broken there). See
122
 
    sql_prepare.cc for details.
123
 
  */
124
 
  void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
125
 
 
126
 
  const String *query_val_str(String *str) const;
127
 
 
128
 
  /*
129
 
    If value for parameter was not set we treat it as non-const
130
 
    so noone will use parameters value in fix_fields still
131
 
    parameter is constant during execution.
132
 
  */
133
 
  virtual table_map used_tables() const
134
 
  { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
135
 
  virtual void print(String *str, enum_query_type query_type);
136
 
  bool is_null()
137
 
  { assert(state != NO_VALUE); return state == NULL_VALUE; }
138
 
  bool basic_const_item() const;
139
 
  /*
140
 
    This method is used to make a copy of a basic constant item when
141
 
    propagating constants in the optimizer. The reason to create a new
142
 
    item and not use the existing one is not precisely known (2005/04/16).
143
 
    Probably we are trying to preserve tree structure of items, in other
144
 
    words, avoid pointing at one item from two different nodes of the tree.
145
 
    Return a new basic constant item if parameter value is a basic
146
 
    constant, assert otherwise. This method is called only if
147
 
    basic_const_item returned true.
148
 
  */
149
 
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
150
 
  Item *clone_item();
151
 
  /*
152
 
    Implement by-value equality evaluation if parameter value
153
 
    is set and is a basic constant (integer, real or string).
154
 
    Otherwise return false.
155
 
  */
156
 
  bool eq(const Item *item, bool binary_cmp) const;
157
 
  /** Item is a argument to a limit clause. */
158
 
  bool limit_clause_param;
159
 
};
160
 
 
161
 
#endif /* DRIZZLED_ITEM_PARAM_H */