Drizzled Public API Documentation

null_client.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #pragma once
21 
22 #include <drizzled/plugin/client.h>
23 #include <boost/tokenizer.hpp>
24 #include <vector>
25 #include <queue>
26 #include <string>
27 
28 namespace drizzled {
29 namespace plugin {
30 
34 class NullClient: public Client
35 {
36  typedef std::vector<char> Bytes;
37  typedef std::queue<Bytes> Queue;
38  Queue to_execute;
39  bool is_dead;
40  Bytes packet_buffer;
41 
42 public:
43 
44  NullClient() :
45  is_dead(false)
46  {
47  }
48 
49  virtual int getFileDescriptor(void) { return -1; }
50  virtual bool isConnected(void) { return true; }
51  virtual bool flush(void) { return false; }
52  virtual void close(void) {}
53  virtual bool authenticate(void) { return true; }
54 
55  virtual bool readCommand(char **packet, uint32_t& packet_length)
56  {
57  while (not to_execute.empty())
58  {
59  Queue::value_type next= to_execute.front();
60  packet_buffer.assign(next.begin(), next.end());
61  *packet= &packet_buffer[0];
62  packet_length= next.size();
63  to_execute.pop();
64  return true;
65  }
66 
67  if (not is_dead)
68  {
69  packet_buffer.resize(1);
70  packet_length= 1;
71  *packet= &packet_buffer[0];
72  is_dead= true;
73  return true;
74  }
75 
76  packet_length= 0;
77  return false;
78  }
79 
80  virtual void sendOK() {}
81  virtual void sendEOF() {}
82  virtual void sendError(const drizzled::error_t, const char*) {}
83  virtual void sendFields(List<Item>&) {}
84  virtual void store(Field *) {}
85  virtual void store(void) {}
86  virtual void store(int32_t) {}
87  virtual void store(uint32_t) {}
88  virtual void store(int64_t) {}
89  virtual void store(uint64_t) {}
90  virtual void store(double, uint32_t, String*) {}
91  virtual void store(const type::Time*) {}
92  virtual void store(const char*) {}
93  virtual void store(const char*, size_t) {}
94  virtual void store(str_ref) {}
95  virtual bool haveError() { return false; }
96  virtual bool wasAborted() { return false; }
97 
98  void pushSQL(str_ref arg)
99  {
100  Bytes byte;
101  typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;
102  Tokenizer tok(arg, boost::escaped_list_separator<char>("\\", ";", "\""));
103 
104  for (Tokenizer::iterator iter= tok.begin(); iter != tok.end(); ++iter)
105  {
106  byte.resize(iter->size() +1); // +1 for the COM_QUERY
107  byte[0]= COM_QUERY;
108  memcpy(&byte[1], iter->data(), iter->size());
109  to_execute.push(byte);
110  }
111  }
112 };
113 
114 } /* namespace plugin */
115 } /* namespace drizzled */
116 
virtual bool flush(void)
Definition: null_client.h:51
virtual bool readCommand(char **packet, uint32_t &packet_length)
Definition: null_client.h:55
virtual bool authenticate(void)
Definition: null_client.h:53
virtual void sendFields(List< Item > &)
Definition: null_client.h:83
virtual bool isConnected(void)
Definition: null_client.h:50
virtual void close(void)
Definition: null_client.h:52
virtual int getFileDescriptor(void)
Definition: null_client.h:49