~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/null_client.h

  • Committer: Patrick Galbraith
  • Date: 2009-10-08 22:42:05 UTC
  • mto: (1166.5.3 memcached_functions)
  • mto: This revision was merged to the branch mainline in revision 1189.
  • Revision ID: patg@patrick-galbraiths-macbook-pro.local-20091008224205-gq1pehjsivvx0qo9
Starting over with a fresh tree, moved in memcached functions.

Memcached Functions for Drizzle. 

All tests pass.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#define DRIZZLED_PLUGIN_NULL_CLIENT_H
22
22
 
23
23
#include <drizzled/plugin/client.h>
24
 
#include<boost/tokenizer.hpp>
25
 
#include <vector>
26
 
#include <queue>
27
 
#include <string>
28
24
 
29
25
namespace drizzled
30
26
{
36
32
 */
37
33
class NullClient: public Client
38
34
{
39
 
  typedef std::vector<char> Bytes;
40
 
  typedef std::queue <Bytes> Queue;
41
 
  Queue to_execute;
42
 
  bool is_dead;
43
 
  Bytes packet_buffer;
44
 
 
45
35
public:
46
 
 
47
 
  NullClient() :
48
 
    is_dead(false)
49
 
  {
50
 
  }
51
 
 
52
36
  virtual int getFileDescriptor(void) { return -1; }
53
37
  virtual bool isConnected(void) { return true; }
54
38
  virtual bool isReading(void) { return false; }
56
40
  virtual bool flush(void) { return false; }
57
41
  virtual void close(void) {}
58
42
  virtual bool authenticate(void) { return true; }
59
 
 
60
43
  virtual bool readCommand(char **packet, uint32_t *packet_length)
61
44
  {
62
 
    while(not to_execute.empty())
63
 
    {
64
 
      Queue::value_type next= to_execute.front();
65
 
      packet_buffer.resize(next.size());
66
 
      memcpy(&packet_buffer[0], &next[0], next.size());
67
 
 
68
 
      *packet= &packet_buffer[0];
69
 
 
70
 
      *packet_length= next.size();
71
 
 
72
 
      to_execute.pop();
73
 
 
74
 
      return true;
75
 
    }
76
 
 
77
 
    if (not is_dead)
78
 
    {
79
 
      packet_buffer.resize(1);
80
 
      *packet_length= 1;
81
 
      *packet= &packet_buffer[0];
82
 
      is_dead= true;
83
 
 
84
 
      return true;
85
 
    }
86
 
 
87
 
    *packet_length= 0;
 
45
    (void) packet;
 
46
    (void) packet_length;
88
47
    return false;
89
48
  }
90
 
 
91
49
  virtual void sendOK(void) {}
92
50
  virtual void sendEOF(void) {}
93
 
  virtual void sendError(uint32_t, const char*) {}
94
 
  virtual bool sendFields(List<Item>*) { return false; }
95
 
  virtual bool store(Field *) { return false; }
 
51
  virtual void sendError(uint32_t sql_errno, const char *err)
 
52
  {
 
53
    (void) sql_errno;
 
54
    (void) err;
 
55
  }
 
56
  virtual bool sendFields(List<Item> *list)
 
57
  {
 
58
    (void) list;
 
59
    return false;
 
60
  }
 
61
  using Client::store;
 
62
  virtual bool store(Field *from)
 
63
  {
 
64
    (void) from;
 
65
    return false;
 
66
  }
96
67
  virtual bool store(void) { return false; }
97
 
  virtual bool store(int32_t) { return false; }
98
 
  virtual bool store(uint32_t) { return false; }
99
 
  virtual bool store(int64_t) { return false; }
100
 
  virtual bool store(uint64_t) { return false; }
101
 
  virtual bool store(double, uint32_t, String*) { return false; }
102
 
  virtual bool store(const DRIZZLE_TIME*) { return false; }
103
 
  virtual bool store(const char*) { return false; }
104
 
  virtual bool store(const char*, size_t) { return false; }
105
 
  virtual bool store(const std::string &) { return false; }
106
 
  virtual bool haveMoreData(void) { return false;}
 
68
  virtual bool store(int32_t from)
 
69
  {
 
70
    (void) from;
 
71
    return false;
 
72
  }
 
73
  virtual bool store(uint32_t from)
 
74
  {
 
75
    (void) from;
 
76
    return false;
 
77
  }
 
78
  virtual bool store(int64_t from)
 
79
  {
 
80
    (void) from;
 
81
    return false;
 
82
  }
 
83
  virtual bool store(uint64_t from)
 
84
  {
 
85
    (void) from;
 
86
    return false;
 
87
  }
 
88
  virtual bool store(double from, uint32_t decimals, String *buffer)
 
89
  {
 
90
    (void) from;
 
91
    (void) decimals;
 
92
    (void) buffer;
 
93
    return false;
 
94
  }
 
95
  virtual bool store(const DRIZZLE_TIME *from)
 
96
  {
 
97
    (void) from;
 
98
    return false;
 
99
  }
 
100
  virtual bool store(const char *from, size_t length)
 
101
  {
 
102
    (void) from;
 
103
    (void) length;
 
104
    return false;
 
105
  }
 
106
  virtual bool haveMoreData(void) { return false; }
107
107
  virtual bool haveError(void) { return false; }
108
108
  virtual bool wasAborted(void) { return false; }
109
 
 
110
 
  void pushSQL(const std::string &arg)
111
 
  {
112
 
    Bytes byte;
113
 
    typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;
114
 
    Tokenizer tok(arg, boost::escaped_list_separator<char>("\\", ";", "\""));
115
 
 
116
 
    for (Tokenizer::iterator iter= tok.begin(); iter != tok.end(); ++iter)
117
 
    {
118
 
      byte.resize((*iter).size() +1); // +1 for the COM_QUERY
119
 
      byte[0]= COM_QUERY;
120
 
      memcpy(&byte[1], (*iter).c_str(), (*iter).size());
121
 
      to_execute.push(byte);
122
 
    }
123
 
  }
124
109
};
125
110
 
126
 
} /* namespace plugin */
127
 
} /* namespace drizzled */
 
111
} /* end namespace drizzled::plugin */
 
112
} /* end namespace drizzled */
128
113
 
129
114
#endif /* DRIZZLED_PLUGIN_NULL_CLIENT_H */