~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/protocol.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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
  bool net_store_data(const uchar *from, size_t length);
 
38
  bool net_store_data(const uchar *from, size_t length,
 
39
                      CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
 
40
  bool store_string_aux(const char *from, size_t length,
 
41
                        CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
 
42
public:
 
43
  Protocol() {}
 
44
  Protocol(THD *thd_arg) { init(thd_arg); }
 
45
  virtual ~Protocol() {}
 
46
  void init(THD* thd_arg);
 
47
 
 
48
  enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
 
49
  virtual bool send_fields(List<Item> *list, uint flags);
 
50
 
 
51
  bool store(I_List<i_string> *str_list);
 
52
  bool store(const char *from, CHARSET_INFO *cs);
 
53
  String *storage_packet() { return packet; }
 
54
  inline void free() { packet->free(); }
 
55
  virtual bool write();
 
56
  inline  bool store(int from)
 
57
  { return store_long((longlong) from); }
 
58
  inline  bool store(uint32 from)
 
59
  { return store_long((longlong) from); }
 
60
  inline  bool store(longlong from)
 
61
  { return store_longlong((longlong) from, 0); }
 
62
  inline  bool store(ulonglong from)
 
63
  { return store_longlong((longlong) from, 1); }
 
64
  inline bool store(String *str)
 
65
  { return store((char*) str->ptr(), str->length(), str->charset()); }
 
66
 
 
67
  virtual bool prepare_for_send(List<Item> *item_list) 
 
68
  {
 
69
    field_count=item_list->elements;
 
70
    return 0;
 
71
  }
 
72
  virtual bool flush();
 
73
  virtual void end_partial_result_set(THD *thd);
 
74
  virtual void prepare_for_resend()=0;
 
75
 
 
76
  virtual bool store_null()=0;
 
77
  virtual bool store_tiny(longlong from)=0;
 
78
  virtual bool store_short(longlong from)=0;
 
79
  virtual bool store_long(longlong from)=0;
 
80
  virtual bool store_longlong(longlong from, bool unsigned_flag)=0;
 
81
  virtual bool store_decimal(const my_decimal *)=0;
 
82
  virtual bool store(const char *from, size_t length, CHARSET_INFO *cs)=0;
 
83
  virtual bool store(const char *from, size_t length, 
 
84
                     CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0;
 
85
  virtual bool store(float from, uint32 decimals, String *buffer)=0;
 
86
  virtual bool store(double from, uint32 decimals, String *buffer)=0;
 
87
  virtual bool store(MYSQL_TIME *time)=0;
 
88
  virtual bool store_date(MYSQL_TIME *time)=0;
 
89
  virtual bool store_time(MYSQL_TIME *time)=0;
 
90
  virtual bool store(Field *field)=0;
 
91
  void remove_last_row() {}
 
92
  enum enum_protocol_type
 
93
  {
 
94
    PROTOCOL_TEXT= 0, PROTOCOL_BINARY= 1
 
95
    /*
 
96
      before adding here or change the values, consider that it is cast to a
 
97
      bit in sql_cache.cc.
 
98
    */
 
99
  };
 
100
  virtual enum enum_protocol_type type()= 0;
 
101
};
 
102
 
 
103
 
 
104
/** Class used for the old (MySQL 4.0 protocol). */
 
105
 
 
106
class Protocol_text :public Protocol
 
107
{
 
108
public:
 
109
  Protocol_text() {}
 
110
  Protocol_text(THD *thd_arg) :Protocol(thd_arg) {}
 
111
  virtual void prepare_for_resend();
 
112
  virtual bool store_null();
 
113
  virtual bool store_tiny(longlong from);
 
114
  virtual bool store_short(longlong from);
 
115
  virtual bool store_long(longlong from);
 
116
  virtual bool store_longlong(longlong from, bool unsigned_flag);
 
117
  virtual bool store_decimal(const my_decimal *);
 
118
  virtual bool store(const char *from, size_t length, CHARSET_INFO *cs);
 
119
  virtual bool store(const char *from, size_t length,
 
120
                     CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
 
121
  virtual bool store(MYSQL_TIME *time);
 
122
  virtual bool store_date(MYSQL_TIME *time);
 
123
  virtual bool store_time(MYSQL_TIME *time);
 
124
  virtual bool store(float nr, uint32 decimals, String *buffer);
 
125
  virtual bool store(double from, uint32 decimals, String *buffer);
 
126
  virtual bool store(Field *field);
 
127
  virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; };
 
128
};
 
129
 
 
130
void send_warning(THD *thd, uint sql_errno, const char *err=0);
 
131
void net_send_error(THD *thd, uint sql_errno=0, const char *err=0);
 
132
void net_end_statement(THD *thd);
 
133
bool send_old_password_request(THD *thd);
 
134
uchar *net_store_data(uchar *to,const uchar *from, size_t length);
 
135
uchar *net_store_data(uchar *to,int32 from);
 
136
uchar *net_store_data(uchar *to,longlong from);
 
137