00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include <drizzled/plugin/client.h>
00023 #include <boost/tokenizer.hpp>
00024 #include <vector>
00025 #include <queue>
00026 #include <string>
00027
00028 namespace drizzled
00029 {
00030 namespace plugin
00031 {
00032 namespace client
00033 {
00034
00038 class Concurrent: public Client
00039 {
00040 typedef std::vector<char> Bytes;
00041 typedef std::queue <Bytes> Queue;
00042 Queue to_execute;
00043 bool is_dead;
00044 Bytes packet_buffer;
00045
00046 public:
00047
00048 Concurrent() :
00049 is_dead(false)
00050 {
00051 }
00052
00053 virtual int getFileDescriptor(void) { return -1; }
00054 virtual bool isConnected(void) { return true; }
00055 virtual bool isReading(void) { return false; }
00056 virtual bool isWriting(void) { return false; }
00057 virtual bool flush(void) { return false; }
00058 virtual void close(void) {}
00059 virtual bool authenticate(void) { return true; }
00060
00061 virtual bool readCommand(char **packet, uint32_t *packet_length)
00062 {
00063 while(not to_execute.empty())
00064 {
00065 Queue::value_type next= to_execute.front();
00066 packet_buffer.resize(next.size());
00067 memcpy(&packet_buffer[0], &next[0], next.size());
00068
00069 *packet= &packet_buffer[0];
00070
00071 *packet_length= next.size();
00072
00073 to_execute.pop();
00074
00075 return true;
00076 }
00077
00078 if (not is_dead)
00079 {
00080 packet_buffer.resize(1);
00081 *packet_length= 1;
00082 *packet= &packet_buffer[0];
00083 is_dead= true;
00084
00085 return true;
00086 }
00087
00088 *packet_length= 0;
00089 return false;
00090 }
00091
00092 virtual void sendOK(void) {}
00093 virtual void sendEOF(void) {}
00094 virtual void sendError(const drizzled::error_t, const char*) {}
00095 virtual bool sendFields(List<Item>*) { return false; }
00096 virtual bool store(Field *) { return false; }
00097 virtual bool store(void) { return false; }
00098 virtual bool store(int32_t) { return false; }
00099 virtual bool store(uint32_t) { return false; }
00100 virtual bool store(int64_t) { return false; }
00101 virtual bool store(uint64_t) { return false; }
00102 virtual bool store(double, uint32_t, String*) { return false; }
00103 virtual bool store(const type::Time*) { return false; }
00104 virtual bool store(const char*) { return false; }
00105 virtual bool store(const char*, size_t) { return false; }
00106 virtual bool store(const std::string &) { return false; }
00107 virtual bool haveMoreData(void) { return false;}
00108 virtual bool haveError(void) { return false; }
00109 virtual bool wasAborted(void) { return false; }
00110
00111 void pushSQL(const std::string &arg)
00112 {
00113 Bytes byte;
00114 typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;
00115 Tokenizer tok(arg, boost::escaped_list_separator<char>("\\", ";", "\""));
00116
00117 {
00118 byte.resize(sizeof("START TRANSACTION"));
00119 byte[0]= COM_QUERY;
00120 memcpy(&byte[1], "START TRANSACTION", sizeof("START TRANSACTION") -1);
00121 to_execute.push(byte);
00122 }
00123
00124 for (Tokenizer::iterator iter= tok.begin(); iter != tok.end(); ++iter)
00125 {
00126 byte.resize(iter->size() +1);
00127 byte[0]= COM_QUERY;
00128 memcpy(&byte[1], iter->c_str(), iter->size());
00129 to_execute.push(byte);
00130 }
00131
00132 {
00133 byte.resize(sizeof("COMMIT"));
00134 byte[0]= COM_QUERY;
00135 memcpy(&byte[1], "COMMIT", sizeof("COMMIT") -1);
00136 to_execute.push(byte);
00137 }
00138 }
00139 };
00140
00141 }
00142 }
00143 }
00144