protocol.h 5.82 KB
Newer Older
unknown's avatar
unknown committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

17
#ifdef USE_PRAGMA_INTERFACE
unknown's avatar
unknown committed
18 19 20 21 22 23
#pragma interface			/* gcc class implementation */
#endif


class i_string;
class THD;
unknown's avatar
SCRUM  
unknown committed
24
typedef struct st_mysql_field MYSQL_FIELD;
unknown's avatar
SCRUM  
unknown committed
25 26
typedef struct st_mysql_rows MYSQL_ROWS;

unknown's avatar
unknown committed
27 28 29 30 31
class Protocol
{
protected:
  THD	 *thd;
  String *packet;
32
  String *convert;
unknown's avatar
unknown committed
33
  uint field_pos;
34
#ifndef DBUG_OFF
unknown's avatar
unknown committed
35 36
  enum enum_field_types *field_types;
#endif
unknown's avatar
SCRUM  
unknown committed
37
  uint field_count;
38
#ifndef EMBEDDED_LIBRARY
unknown's avatar
SCRUM  
unknown committed
39
  bool net_store_data(const char *from, uint length);
40 41
#else
  virtual bool net_store_data(const char *from, uint length);
unknown's avatar
SCRUM  
unknown committed
42
  char **next_field;
unknown's avatar
SCRUM  
unknown committed
43
  MYSQL_FIELD *next_mysql_field;
unknown's avatar
SCRUM  
unknown committed
44
  MEM_ROOT *alloc;
unknown's avatar
unknown committed
45
#endif
46 47
  bool store_string_aux(const char *from, uint length,
                        CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
unknown's avatar
unknown committed
48 49
public:
  Protocol() {}
50
  Protocol(THD *thd_arg) { init(thd_arg); }
51
  virtual ~Protocol() {}
52
  void init(THD* thd_arg);
53

54
  enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
unknown's avatar
unknown committed
55
  virtual bool send_fields(List<Item> *list, uint flags);
56

unknown's avatar
unknown committed
57
  bool store(I_List<i_string> *str_list);
58
  bool store(const char *from, CHARSET_INFO *cs);
unknown's avatar
unknown committed
59 60
  String *storage_packet() { return packet; }
  inline void free() { packet->free(); }
unknown's avatar
SCRUM:  
unknown committed
61
  virtual bool write();
unknown's avatar
unknown committed
62 63 64 65 66 67
  inline  bool store(uint32 from)
  { return store_long((longlong) from); }
  inline  bool store(longlong from)
  { return store_longlong((longlong) from, 0); }
  inline  bool store(ulonglong from)
  { return store_longlong((longlong) from, 1); }
unknown's avatar
unknown committed
68
  inline bool store(String *str)
69
  { return store((char*) str->ptr(), str->length(), str->charset()); }
unknown's avatar
unknown committed
70

unknown's avatar
SCRUM  
unknown committed
71 72 73 74 75
  virtual bool prepare_for_send(List<Item> *item_list) 
  {
    field_count=item_list->elements;
    return 0;
  }
unknown's avatar
unknown committed
76
  virtual bool flush();
unknown's avatar
unknown committed
77 78 79 80 81 82 83
  virtual void prepare_for_resend()=0;

  virtual bool store_null()=0;
  virtual bool store_tiny(longlong from)=0;
  virtual bool store_short(longlong from)=0;
  virtual bool store_long(longlong from)=0;
  virtual bool store_longlong(longlong from, bool unsigned_flag)=0;
unknown's avatar
unknown committed
84
  virtual bool store_decimal(const my_decimal *)=0;
85
  virtual bool store(const char *from, uint length, CHARSET_INFO *cs)=0;
86 87
  virtual bool store(const char *from, uint length, 
  		     CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0;
unknown's avatar
unknown committed
88 89 90 91 92 93
  virtual bool store(float from, uint32 decimals, String *buffer)=0;
  virtual bool store(double from, uint32 decimals, String *buffer)=0;
  virtual bool store(TIME *time)=0;
  virtual bool store_date(TIME *time)=0;
  virtual bool store_time(TIME *time)=0;
  virtual bool store(Field *field)=0;
94 95 96 97 98 99
#ifdef EMBEDDED_LIBRARY
  int begin_dataset();
  virtual void remove_last_row() {}
#else
  void remove_last_row() {}
#endif
unknown's avatar
unknown committed
100 101 102 103 104 105 106 107 108
};


/* Class used for the old (MySQL 4.0 protocol) */

class Protocol_simple :public Protocol
{
public:
  Protocol_simple() {}
109
  Protocol_simple(THD *thd_arg) :Protocol(thd_arg) {}
unknown's avatar
unknown committed
110 111 112 113 114 115
  virtual void prepare_for_resend();
  virtual bool store_null();
  virtual bool store_tiny(longlong from);
  virtual bool store_short(longlong from);
  virtual bool store_long(longlong from);
  virtual bool store_longlong(longlong from, bool unsigned_flag);
unknown's avatar
unknown committed
116
  virtual bool store_decimal(const my_decimal *);
117
  virtual bool store(const char *from, uint length, CHARSET_INFO *cs);
118 119
  virtual bool store(const char *from, uint length,
  		     CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
unknown's avatar
unknown committed
120 121 122 123 124 125
  virtual bool store(TIME *time);
  virtual bool store_date(TIME *time);
  virtual bool store_time(TIME *time);
  virtual bool store(float nr, uint32 decimals, String *buffer);
  virtual bool store(double from, uint32 decimals, String *buffer);
  virtual bool store(Field *field);
126 127 128
#ifdef EMBEDDED_LIBRARY
  void remove_last_row();
#endif
unknown's avatar
unknown committed
129 130 131 132 133 134
};


class Protocol_prep :public Protocol
{
private:
unknown's avatar
SCRUM  
unknown committed
135
  uint bit_fields;
unknown's avatar
unknown committed
136 137
public:
  Protocol_prep() {}
138
  Protocol_prep(THD *thd_arg) :Protocol(thd_arg) {}
unknown's avatar
unknown committed
139 140
  virtual bool prepare_for_send(List<Item> *item_list);
  virtual void prepare_for_resend();
unknown's avatar
SCRUM:  
unknown committed
141 142
#ifdef EMBEDDED_LIBRARY
  virtual bool write();
unknown's avatar
SCRUM  
unknown committed
143
  bool net_store_data(const char *from, uint length);
unknown's avatar
SCRUM:  
unknown committed
144
#endif
unknown's avatar
unknown committed
145 146 147 148 149
  virtual bool store_null();
  virtual bool store_tiny(longlong from);
  virtual bool store_short(longlong from);
  virtual bool store_long(longlong from);
  virtual bool store_longlong(longlong from, bool unsigned_flag);
unknown's avatar
unknown committed
150
  virtual bool store_decimal(const my_decimal *);
151
  virtual bool store(const char *from,uint length, CHARSET_INFO *cs);
152 153
  virtual bool store(const char *from, uint length,
  		     CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
unknown's avatar
unknown committed
154 155 156 157 158 159 160 161 162
  virtual bool store(TIME *time);
  virtual bool store_date(TIME *time);
  virtual bool store_time(TIME *time);
  virtual bool store(float nr, uint32 decimals, String *buffer);
  virtual bool store(double from, uint32 decimals, String *buffer);
  virtual bool store(Field *field);
};

void send_warning(THD *thd, uint sql_errno, const char *err=0);
163 164
void net_printf_error(THD *thd, uint sql_errno, ...);
void net_send_error(THD *thd, uint sql_errno=0, const char *err=0);
unknown's avatar
unknown committed
165 166
void send_ok(THD *thd, ha_rows affected_rows=0L, ulonglong id=0L,
	     const char *info=0);
167
void send_eof(THD *thd);
168
bool send_old_password_request(THD *thd);
unknown's avatar
unknown committed
169 170 171
char *net_store_data(char *to,const char *from, uint length);
char *net_store_data(char *to,int32 from);
char *net_store_data(char *to,longlong from);
unknown's avatar
SCRUM:  
unknown committed
172