The world's most popular open source database
00001 /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #ifdef USE_PRAGMA_INTERFACE 00018 #pragma interface /* gcc class implementation */ 00019 #endif 00020 00021 00022 class i_string; 00023 class THD; 00024 typedef struct st_mysql_field MYSQL_FIELD; 00025 typedef struct st_mysql_rows MYSQL_ROWS; 00026 00027 class Protocol 00028 { 00029 protected: 00030 THD *thd; 00031 String *packet; 00032 String *convert; 00033 uint field_pos; 00034 #ifndef DBUG_OFF 00035 enum enum_field_types *field_types; 00036 #endif 00037 uint field_count; 00038 #ifndef EMBEDDED_LIBRARY 00039 bool net_store_data(const char *from, uint length); 00040 #else 00041 virtual bool net_store_data(const char *from, uint length); 00042 char **next_field; 00043 MYSQL_FIELD *next_mysql_field; 00044 MEM_ROOT *alloc; 00045 #endif 00046 bool store_string_aux(const char *from, uint length, 00047 CHARSET_INFO *fromcs, CHARSET_INFO *tocs); 00048 public: 00049 Protocol() {} 00050 Protocol(THD *thd_arg) { init(thd_arg); } 00051 virtual ~Protocol() {} 00052 void init(THD* thd_arg); 00053 00054 enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 }; 00055 virtual bool send_fields(List<Item> *list, uint flags); 00056 00057 bool store(I_List<i_string> *str_list); 00058 bool store(const char *from, CHARSET_INFO *cs); 00059 String *storage_packet() { return packet; } 00060 inline void free() { packet->free(); } 00061 virtual bool write(); 00062 inline bool store(uint32 from) 00063 { return store_long((longlong) from); } 00064 inline bool store(longlong from) 00065 { return store_longlong((longlong) from, 0); } 00066 inline bool store(ulonglong from) 00067 { return store_longlong((longlong) from, 1); } 00068 inline bool store(String *str) 00069 { return store((char*) str->ptr(), str->length(), str->charset()); } 00070 00071 virtual bool prepare_for_send(List<Item> *item_list) 00072 { 00073 field_count=item_list->elements; 00074 return 0; 00075 } 00076 virtual bool flush(); 00077 virtual void prepare_for_resend()=0; 00078 00079 virtual bool store_null()=0; 00080 virtual bool store_tiny(longlong from)=0; 00081 virtual bool store_short(longlong from)=0; 00082 virtual bool store_long(longlong from)=0; 00083 virtual bool store_longlong(longlong from, bool unsigned_flag)=0; 00084 virtual bool store_decimal(const my_decimal *)=0; 00085 virtual bool store(const char *from, uint length, CHARSET_INFO *cs)=0; 00086 virtual bool store(const char *from, uint length, 00087 CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0; 00088 virtual bool store(float from, uint32 decimals, String *buffer)=0; 00089 virtual bool store(double from, uint32 decimals, String *buffer)=0; 00090 virtual bool store(TIME *time)=0; 00091 virtual bool store_date(TIME *time)=0; 00092 virtual bool store_time(TIME *time)=0; 00093 virtual bool store(Field *field)=0; 00094 #ifdef EMBEDDED_LIBRARY 00095 int begin_dataset(); 00096 virtual void remove_last_row() {} 00097 #else 00098 void remove_last_row() {} 00099 #endif 00100 }; 00101 00102 00103 /* Class used for the old (MySQL 4.0 protocol) */ 00104 00105 class Protocol_simple :public Protocol 00106 { 00107 public: 00108 Protocol_simple() {} 00109 Protocol_simple(THD *thd_arg) :Protocol(thd_arg) {} 00110 virtual void prepare_for_resend(); 00111 virtual bool store_null(); 00112 virtual bool store_tiny(longlong from); 00113 virtual bool store_short(longlong from); 00114 virtual bool store_long(longlong from); 00115 virtual bool store_longlong(longlong from, bool unsigned_flag); 00116 virtual bool store_decimal(const my_decimal *); 00117 virtual bool store(const char *from, uint length, CHARSET_INFO *cs); 00118 virtual bool store(const char *from, uint length, 00119 CHARSET_INFO *fromcs, CHARSET_INFO *tocs); 00120 virtual bool store(TIME *time); 00121 virtual bool store_date(TIME *time); 00122 virtual bool store_time(TIME *time); 00123 virtual bool store(float nr, uint32 decimals, String *buffer); 00124 virtual bool store(double from, uint32 decimals, String *buffer); 00125 virtual bool store(Field *field); 00126 #ifdef EMBEDDED_LIBRARY 00127 void remove_last_row(); 00128 #endif 00129 }; 00130 00131 00132 class Protocol_prep :public Protocol 00133 { 00134 private: 00135 uint bit_fields; 00136 public: 00137 Protocol_prep() {} 00138 Protocol_prep(THD *thd_arg) :Protocol(thd_arg) {} 00139 virtual bool prepare_for_send(List<Item> *item_list); 00140 virtual void prepare_for_resend(); 00141 #ifdef EMBEDDED_LIBRARY 00142 virtual bool write(); 00143 bool net_store_data(const char *from, uint length); 00144 #endif 00145 virtual bool store_null(); 00146 virtual bool store_tiny(longlong from); 00147 virtual bool store_short(longlong from); 00148 virtual bool store_long(longlong from); 00149 virtual bool store_longlong(longlong from, bool unsigned_flag); 00150 virtual bool store_decimal(const my_decimal *); 00151 virtual bool store(const char *from,uint length, CHARSET_INFO *cs); 00152 virtual bool store(const char *from, uint length, 00153 CHARSET_INFO *fromcs, CHARSET_INFO *tocs); 00154 virtual bool store(TIME *time); 00155 virtual bool store_date(TIME *time); 00156 virtual bool store_time(TIME *time); 00157 virtual bool store(float nr, uint32 decimals, String *buffer); 00158 virtual bool store(double from, uint32 decimals, String *buffer); 00159 virtual bool store(Field *field); 00160 }; 00161 00162 void send_warning(THD *thd, uint sql_errno, const char *err=0); 00163 void net_printf_error(THD *thd, uint sql_errno, ...); 00164 void net_send_error(THD *thd, uint sql_errno=0, const char *err=0); 00165 void send_ok(THD *thd, ha_rows affected_rows=0L, ulonglong id=0L, 00166 const char *info=0); 00167 void send_eof(THD *thd); 00168 bool send_old_password_request(THD *thd); 00169 char *net_store_length(char *packet,uint length); 00170 char *net_store_data(char *to,const char *from, uint length); 00171 char *net_store_data(char *to,int32 from); 00172 char *net_store_data(char *to,longlong from); 00173
1.4.7

