~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/protocol.h

  • Committer: Brian Aker
  • Date: 2009-02-12 22:45:08 UTC
  • Revision ID: brian@tangent.org-20090212224508-mrd9jwgn1zjdpqdk
Minor refactoring (we will need to disconnect the code from the include
file).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifdef USE_PRAGMA_INTERFACE
21
 
#pragma interface                       /* gcc class implementation */
22
 
#endif
23
 
 
24
 
 
 
20
#ifndef DRIZZLED_PROTOCOL_H
 
21
#define DRIZZLED_PROTOCOL_H
 
22
 
 
23
#include <drizzled/sql_list.h>
 
24
#include <drizzled/item.h>
 
25
 
 
26
class Field;
 
27
class String;
25
28
class i_string;
26
 
class THD;
 
29
class Session;
 
30
class my_decimal;
27
31
typedef struct st_drizzle_field DRIZZLE_FIELD;
28
32
typedef struct st_drizzle_rows DRIZZLE_ROWS;
 
33
typedef struct st_drizzle_time DRIZZLE_TIME;
29
34
 
30
35
class Protocol
31
36
{
32
37
protected:
33
 
  THD    *thd;
 
38
  Session        *session;
34
39
  String *packet;
35
40
  String *convert;
36
41
  uint32_t field_pos;
42
47
                        const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs);
43
48
public:
44
49
  Protocol() {}
45
 
  Protocol(THD *thd_arg) { init(thd_arg); }
 
50
  Protocol(Session *session_arg) { init(session_arg); }
46
51
  virtual ~Protocol() {}
47
 
  void init(THD* thd_arg);
 
52
  void init(Session* session_arg);
48
53
 
49
54
  enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
50
55
  virtual bool send_fields(List<Item> *list, uint32_t flags);
51
56
 
52
 
  bool store(I_List<i_string> *str_list);
53
 
  bool store(const char *from, const CHARSET_INFO * const cs);
 
57
  virtual bool store(I_List<i_string> *str_list);
 
58
  virtual bool store(const char *from, const CHARSET_INFO * const cs);
54
59
  String *storage_packet() { return packet; }
55
 
  inline void free() { packet->free(); }
 
60
  void free();
56
61
  virtual bool write();
57
 
  inline  bool store(int from)
58
 
  { return store_long((int64_t) from); }
59
 
  inline  bool store(uint32_t from)
60
 
  { return store_long((int64_t) from); }
61
 
  inline  bool store(int64_t from)
 
62
  virtual bool store(int from)
 
63
  { return store_long((int64_t) from); }
 
64
  virtual  bool store(uint32_t from)
 
65
  { return store_long((int64_t) from); }
 
66
  virtual bool store(int64_t from)
62
67
  { return store_int64_t((int64_t) from, 0); }
63
 
  inline  bool store(uint64_t from)
 
68
  virtual bool store(uint64_t from)
64
69
  { return store_int64_t((int64_t) from, 1); }
65
 
  inline bool store(String *str)
66
 
  { return store((char*) str->ptr(), str->length(), str->charset()); }
 
70
  virtual bool store(String *str);
67
71
 
68
 
  virtual bool prepare_for_send(List<Item> *item_list) 
 
72
  virtual bool prepare_for_send(List<Item> *item_list)
69
73
  {
70
74
    field_count=item_list->elements;
71
75
    return 0;
72
76
  }
73
77
  virtual bool flush();
74
 
  virtual void end_partial_result_set(THD *thd);
75
78
  virtual void prepare_for_resend()=0;
76
79
 
77
80
  virtual bool store_null()=0;
79
82
  virtual bool store_short(int64_t from)=0;
80
83
  virtual bool store_long(int64_t from)=0;
81
84
  virtual bool store_int64_t(int64_t from, bool unsigned_flag)=0;
82
 
  virtual bool store_decimal(const my_decimal *)=0;
 
85
  virtual bool store_decimal(const my_decimal * dec_value)=0;
83
86
  virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs)=0;
84
 
  virtual bool store(const char *from, size_t length, 
 
87
  virtual bool store(const char *from, size_t length,
85
88
                     const CHARSET_INFO * const fromcs, const CHARSET_INFO * const tocs)=0;
86
89
  virtual bool store(float from, uint32_t decimals, String *buffer)=0;
87
90
  virtual bool store(double from, uint32_t decimals, String *buffer)=0;
108
111
{
109
112
public:
110
113
  Protocol_text() {}
111
 
  Protocol_text(THD *thd_arg) :Protocol(thd_arg) {}
 
114
  Protocol_text(Session *session_arg) :Protocol(session_arg) {}
112
115
  virtual void prepare_for_resend();
 
116
  virtual bool store(I_List<i_string> *str_list)
 
117
  {
 
118
    return Protocol::store(str_list);
 
119
  }
 
120
  virtual bool store(const char *from, const CHARSET_INFO * const cs)
 
121
  {
 
122
    return Protocol::store(from, cs);
 
123
  }
113
124
  virtual bool store_null();
114
125
  virtual bool store_tiny(int64_t from);
115
126
  virtual bool store_short(int64_t from);
116
127
  virtual bool store_long(int64_t from);
117
128
  virtual bool store_int64_t(int64_t from, bool unsigned_flag);
118
129
  virtual bool store_decimal(const my_decimal *);
 
130
  virtual bool store(int from)
 
131
  { return store_long((int64_t) from); }
 
132
  virtual  bool store(uint32_t from)
 
133
  { return store_long((int64_t) from); }
 
134
  virtual bool store(int64_t from)
 
135
  { return store_int64_t((int64_t) from, 0); }
 
136
  virtual bool store(uint64_t from)
 
137
  { return store_int64_t((int64_t) from, 1); }
 
138
  virtual bool store(String *str)
 
139
  {
 
140
    return Protocol::store(str);
 
141
  }
119
142
  virtual bool store(const char *from, size_t length, const CHARSET_INFO * const cs);
120
143
  virtual bool store(const char *from, size_t length,
121
144
                     const CHARSET_INFO * const fromcs,  const CHARSET_INFO * const tocs);
128
151
  virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; };
129
152
};
130
153
 
131
 
void send_warning(THD *thd, uint32_t sql_errno, const char *err=0);
132
 
void net_send_error(THD *thd, uint32_t sql_errno=0, const char *err=0);
133
 
void net_end_statement(THD *thd);
 
154
void send_warning(Session *session, uint32_t sql_errno, const char *err=0);
 
155
void net_send_error(Session *session, uint32_t sql_errno=0, const char *err=0);
 
156
void drizzleclient_net_end_statement(Session *session);
134
157
unsigned char *net_store_data(unsigned char *to,const unsigned char *from, size_t length);
135
158
unsigned char *net_store_data(unsigned char *to,int32_t from);
136
159
unsigned char *net_store_data(unsigned char *to,int64_t from);
137
160
 
 
161
#endif /* DRIZZLED_PROTOCOL_H */