~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to sql/protocol.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2002-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifdef USE_PRAGMA_INTERFACE
 
17
#pragma interface                       /* gcc class implementation */
 
18
#endif
 
19
 
 
20
 
 
21
class i_string;
 
22
class THD;
 
23
typedef struct st_mysql_field MYSQL_FIELD;
 
24
typedef struct st_mysql_rows MYSQL_ROWS;
 
25
 
 
26
class Protocol
 
27
{
 
28
protected:
 
29
  THD    *thd;
 
30
  String *packet;
 
31
  String *convert;
 
32
  uint field_pos;
 
33
#ifndef DBUG_OFF
 
34
  enum enum_field_types *field_types;
 
35
#endif
 
36
  uint field_count;
 
37
#ifndef EMBEDDED_LIBRARY
 
38
  bool net_store_data(const uchar *from, size_t length);
 
39
#else
 
40
  virtual bool net_store_data(const uchar *from, size_t length);
 
41
  char **next_field;
 
42
  MYSQL_FIELD *next_mysql_field;
 
43
  MEM_ROOT *alloc;
 
44
#endif
 
45
  bool store_string_aux(const char *from, size_t length,
 
46
                        CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
 
47
public:
 
48
  Protocol() {}
 
49
  Protocol(THD *thd_arg) { init(thd_arg); }
 
50
  virtual ~Protocol() {}
 
51
  void init(THD* thd_arg);
 
52
 
 
53
  enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
 
54
  virtual bool send_fields(List<Item> *list, uint flags);
 
55
 
 
56
  bool store(I_List<i_string> *str_list);
 
57
  bool store(const char *from, CHARSET_INFO *cs);
 
58
  String *storage_packet() { return packet; }
 
59
  inline void free() { packet->free(); }
 
60
  virtual bool write();
 
61
  inline  bool store(int from)
 
62
  { return store_long((longlong) from); }
 
63
  inline  bool store(uint32 from)
 
64
  { return store_long((longlong) from); }
 
65
  inline  bool store(longlong from)
 
66
  { return store_longlong((longlong) from, 0); }
 
67
  inline  bool store(ulonglong from)
 
68
  { return store_longlong((longlong) from, 1); }
 
69
  inline bool store(String *str)
 
70
  { return store((char*) str->ptr(), str->length(), str->charset()); }
 
71
 
 
72
  virtual bool prepare_for_send(List<Item> *item_list) 
 
73
  {
 
74
    field_count=item_list->elements;
 
75
    return 0;
 
76
  }
 
77
  virtual bool flush();
 
78
  virtual void end_partial_result_set(THD *thd);
 
79
  virtual void prepare_for_resend()=0;
 
80
 
 
81
  virtual bool store_null()=0;
 
82
  virtual bool store_tiny(longlong from)=0;
 
83
  virtual bool store_short(longlong from)=0;
 
84
  virtual bool store_long(longlong from)=0;
 
85
  virtual bool store_longlong(longlong from, bool unsigned_flag)=0;
 
86
  virtual bool store_decimal(const my_decimal *)=0;
 
87
  virtual bool store(const char *from, size_t length, CHARSET_INFO *cs)=0;
 
88
  virtual bool store(const char *from, size_t length, 
 
89
                     CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0;
 
90
  virtual bool store(float from, uint32 decimals, String *buffer)=0;
 
91
  virtual bool store(double from, uint32 decimals, String *buffer)=0;
 
92
  virtual bool store(MYSQL_TIME *time)=0;
 
93
  virtual bool store_date(MYSQL_TIME *time)=0;
 
94
  virtual bool store_time(MYSQL_TIME *time)=0;
 
95
  virtual bool store(Field *field)=0;
 
96
#ifdef EMBEDDED_LIBRARY
 
97
  int begin_dataset();
 
98
  virtual void remove_last_row() {}
 
99
#else
 
100
  void remove_last_row() {}
 
101
#endif
 
102
  enum enum_protocol_type
 
103
  {
 
104
    PROTOCOL_TEXT= 0, PROTOCOL_BINARY= 1
 
105
    /*
 
106
      before adding here or change the values, consider that it is cast to a
 
107
      bit in sql_cache.cc.
 
108
    */
 
109
  };
 
110
  virtual enum enum_protocol_type type()= 0;
 
111
};
 
112
 
 
113
 
 
114
/** Class used for the old (MySQL 4.0 protocol). */
 
115
 
 
116
class Protocol_text :public Protocol
 
117
{
 
118
public:
 
119
  Protocol_text() {}
 
120
  Protocol_text(THD *thd_arg) :Protocol(thd_arg) {}
 
121
  virtual void prepare_for_resend();
 
122
  virtual bool store_null();
 
123
  virtual bool store_tiny(longlong from);
 
124
  virtual bool store_short(longlong from);
 
125
  virtual bool store_long(longlong from);
 
126
  virtual bool store_longlong(longlong from, bool unsigned_flag);
 
127
  virtual bool store_decimal(const my_decimal *);
 
128
  virtual bool store(const char *from, size_t length, CHARSET_INFO *cs);
 
129
  virtual bool store(const char *from, size_t length,
 
130
                     CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
 
131
  virtual bool store(MYSQL_TIME *time);
 
132
  virtual bool store_date(MYSQL_TIME *time);
 
133
  virtual bool store_time(MYSQL_TIME *time);
 
134
  virtual bool store(float nr, uint32 decimals, String *buffer);
 
135
  virtual bool store(double from, uint32 decimals, String *buffer);
 
136
  virtual bool store(Field *field);
 
137
#ifdef EMBEDDED_LIBRARY
 
138
  void remove_last_row();
 
139
#endif
 
140
  virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; };
 
141
};
 
142
 
 
143
 
 
144
class Protocol_binary :public Protocol
 
145
{
 
146
private:
 
147
  uint bit_fields;
 
148
public:
 
149
  Protocol_binary() {}
 
150
  Protocol_binary(THD *thd_arg) :Protocol(thd_arg) {}
 
151
  virtual bool prepare_for_send(List<Item> *item_list);
 
152
  virtual void prepare_for_resend();
 
153
#ifdef EMBEDDED_LIBRARY
 
154
  virtual bool write();
 
155
  bool net_store_data(const uchar *from, size_t length);
 
156
#endif
 
157
  virtual bool store_null();
 
158
  virtual bool store_tiny(longlong from);
 
159
  virtual bool store_short(longlong from);
 
160
  virtual bool store_long(longlong from);
 
161
  virtual bool store_longlong(longlong from, bool unsigned_flag);
 
162
  virtual bool store_decimal(const my_decimal *);
 
163
  virtual bool store(const char *from, size_t length, CHARSET_INFO *cs);
 
164
  virtual bool store(const char *from, size_t length,
 
165
                     CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
 
166
  virtual bool store(MYSQL_TIME *time);
 
167
  virtual bool store_date(MYSQL_TIME *time);
 
168
  virtual bool store_time(MYSQL_TIME *time);
 
169
  virtual bool store(float nr, uint32 decimals, String *buffer);
 
170
  virtual bool store(double from, uint32 decimals, String *buffer);
 
171
  virtual bool store(Field *field);
 
172
  virtual enum enum_protocol_type type() { return PROTOCOL_BINARY; };
 
173
};
 
174
 
 
175
void send_warning(THD *thd, uint sql_errno, const char *err=0);
 
176
bool net_send_error(THD *thd, uint sql_errno=0, const char *err=0);
 
177
void net_end_statement(THD *thd);
 
178
bool send_old_password_request(THD *thd);
 
179
uchar *net_store_data(uchar *to,const uchar *from, size_t length);
 
180
uchar *net_store_data(uchar *to,int32 from);
 
181
uchar *net_store_data(uchar *to,longlong from);
 
182