MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
procedure.h
1 #ifndef PROCEDURE_INCLUDED
2 #define PROCEDURE_INCLUDED
3 
4 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
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 /* When using sql procedures */
21 
22 /*
23  It is necessary to include set_var.h instead of item.h because there
24  are dependencies on include order for set_var.h and item.h. This
25  will be resolved later.
26 */
27 #include "sql_class.h" /* select_result, set_var.h: THD */
28 #include "set_var.h" /* Item */
29 
30 /* Procedure items used by procedures to store values for send_result_set_metadata */
31 
32 class Item_proc :public Item
33 {
34 public:
35  Item_proc(const char *name_par): Item()
36  {
37  this->item_name.set(name_par);
38  }
39  enum Type type() const { return Item::PROC_ITEM; }
40  virtual void set(const char *str,uint length, const CHARSET_INFO *cs)=0;
41  virtual void set(longlong nr)=0;
42  virtual enum_field_types field_type() const=0;
43  void set(const char *str) { set(str,(uint) strlen(str), default_charset()); }
44  unsigned int size_of() { return sizeof(*this);}
45 };
46 
47 
48 class Item_proc_int :public Item_proc
49 {
50  longlong value;
51 public:
52  Item_proc_int(const char *name_par) :Item_proc(name_par)
53  { max_length=11; }
54  enum Item_result result_type () const { return INT_RESULT; }
55  enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
56  void set(longlong nr) { value=nr; }
57  void set(const char *str,uint length, const CHARSET_INFO *cs)
58  { int err; value=my_strntoll(cs,str,length,10,NULL,&err); }
59  double val_real() { return (double) value; }
60  longlong val_int() { return value; }
61  String *val_str(String *s) { s->set(value, default_charset()); return s; }
62  my_decimal *val_decimal(my_decimal *);
63  bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
64  {
65  return get_date_from_int(ltime, fuzzydate);
66  }
67  bool get_time(MYSQL_TIME *ltime)
68  {
69  return get_time_from_int(ltime);
70  }
71  unsigned int size_of() { return sizeof(*this);}
72 };
73 
74 
76 {
77 public:
78  Item_proc_string(const char *name_par,uint length) :Item_proc(name_par)
79  { this->max_length=length; }
80  enum Item_result result_type () const { return STRING_RESULT; }
81  enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
82  void set(longlong nr) { str_value.set(nr, default_charset()); }
83  void set(const char *str, uint length, const CHARSET_INFO *cs)
84  { str_value.copy(str,length,cs); }
85  double val_real()
86  {
87  int err_not_used;
88  char *end_not_used;
89  const CHARSET_INFO *cs= str_value.charset();
90  return my_strntod(cs, (char*) str_value.ptr(), str_value.length(),
91  &end_not_used, &err_not_used);
92  }
93  longlong val_int()
94  {
95  int err;
96  const CHARSET_INFO *cs=str_value.charset();
97  return my_strntoll(cs,str_value.ptr(),str_value.length(),10,NULL,&err);
98  }
99  bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
100  {
101  return get_date_from_string(ltime, fuzzydate);
102  }
103  bool get_time(MYSQL_TIME *ltime)
104  {
105  return get_time_from_string(ltime);
106  }
107  String *val_str(String*)
108  {
109  return null_value ? (String*) 0 : (String*) &str_value;
110  }
111  my_decimal *val_decimal(my_decimal *);
112  unsigned int size_of() { return sizeof(*this);}
113 };
114 
115 /* The procedure class definitions */
116 
117 #endif /* PROCEDURE_INCLUDED */