My Project
|
00001 #ifndef PROCEDURE_INCLUDED 00002 #define PROCEDURE_INCLUDED 00003 00004 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; version 2 of the License. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00018 00019 00020 /* When using sql procedures */ 00021 00022 /* 00023 It is necessary to include set_var.h instead of item.h because there 00024 are dependencies on include order for set_var.h and item.h. This 00025 will be resolved later. 00026 */ 00027 #include "sql_class.h" /* select_result, set_var.h: THD */ 00028 #include "set_var.h" /* Item */ 00029 00030 /* Procedure items used by procedures to store values for send_result_set_metadata */ 00031 00032 class Item_proc :public Item 00033 { 00034 public: 00035 Item_proc(const char *name_par): Item() 00036 { 00037 this->item_name.set(name_par); 00038 } 00039 enum Type type() const { return Item::PROC_ITEM; } 00040 virtual void set(const char *str,uint length, const CHARSET_INFO *cs)=0; 00041 virtual void set(longlong nr)=0; 00042 virtual enum_field_types field_type() const=0; 00043 void set(const char *str) { set(str,(uint) strlen(str), default_charset()); } 00044 unsigned int size_of() { return sizeof(*this);} 00045 }; 00046 00047 00048 class Item_proc_int :public Item_proc 00049 { 00050 longlong value; 00051 public: 00052 Item_proc_int(const char *name_par) :Item_proc(name_par) 00053 { max_length=11; } 00054 enum Item_result result_type () const { return INT_RESULT; } 00055 enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; } 00056 void set(longlong nr) { value=nr; } 00057 void set(const char *str,uint length, const CHARSET_INFO *cs) 00058 { int err; value=my_strntoll(cs,str,length,10,NULL,&err); } 00059 double val_real() { return (double) value; } 00060 longlong val_int() { return value; } 00061 String *val_str(String *s) { s->set(value, default_charset()); return s; } 00062 my_decimal *val_decimal(my_decimal *); 00063 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00064 { 00065 return get_date_from_int(ltime, fuzzydate); 00066 } 00067 bool get_time(MYSQL_TIME *ltime) 00068 { 00069 return get_time_from_int(ltime); 00070 } 00071 unsigned int size_of() { return sizeof(*this);} 00072 }; 00073 00074 00075 class Item_proc_string :public Item_proc 00076 { 00077 public: 00078 Item_proc_string(const char *name_par,uint length) :Item_proc(name_par) 00079 { this->max_length=length; } 00080 enum Item_result result_type () const { return STRING_RESULT; } 00081 enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } 00082 void set(longlong nr) { str_value.set(nr, default_charset()); } 00083 void set(const char *str, uint length, const CHARSET_INFO *cs) 00084 { str_value.copy(str,length,cs); } 00085 double val_real() 00086 { 00087 int err_not_used; 00088 char *end_not_used; 00089 const CHARSET_INFO *cs= str_value.charset(); 00090 return my_strntod(cs, (char*) str_value.ptr(), str_value.length(), 00091 &end_not_used, &err_not_used); 00092 } 00093 longlong val_int() 00094 { 00095 int err; 00096 const CHARSET_INFO *cs=str_value.charset(); 00097 return my_strntoll(cs,str_value.ptr(),str_value.length(),10,NULL,&err); 00098 } 00099 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 00100 { 00101 return get_date_from_string(ltime, fuzzydate); 00102 } 00103 bool get_time(MYSQL_TIME *ltime) 00104 { 00105 return get_time_from_string(ltime); 00106 } 00107 String *val_str(String*) 00108 { 00109 return null_value ? (String*) 0 : (String*) &str_value; 00110 } 00111 my_decimal *val_decimal(my_decimal *); 00112 unsigned int size_of() { return sizeof(*this);} 00113 }; 00114 00115 /* The procedure class definitions */ 00116 00117 #endif /* PROCEDURE_INCLUDED */