1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
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.
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.
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
20
#ifndef DRIZZLED_PLUGIN_CLIENT_CONCURRENT_H
21
#define DRIZZLED_PLUGIN_CLIENT_CONCURRENT_H
23
#include <drizzled/plugin/client.h>
24
#include <boost/tokenizer.hpp>
37
* This class is an empty client implementation for internal used.
39
class Concurrent: public Client
41
typedef std::vector<char> Bytes;
42
typedef std::queue <Bytes> Queue;
54
virtual int getFileDescriptor(void) { return -1; }
55
virtual bool isConnected(void) { return true; }
56
virtual bool isReading(void) { return false; }
57
virtual bool isWriting(void) { return false; }
58
virtual bool flush(void) { return false; }
59
virtual void close(void) {}
60
virtual bool authenticate(void) { return true; }
62
virtual bool readCommand(char **packet, uint32_t *packet_length)
64
while(not to_execute.empty())
66
Queue::value_type next= to_execute.front();
67
packet_buffer.resize(next.size());
68
memcpy(&packet_buffer[0], &next[0], next.size());
70
*packet= &packet_buffer[0];
72
*packet_length= next.size();
81
packet_buffer.resize(1);
83
*packet= &packet_buffer[0];
93
virtual void sendOK(void) {}
94
virtual void sendEOF(void) {}
95
virtual void sendError(const drizzled::error_t, const char*) {}
96
virtual bool sendFields(List<Item>*) { return false; }
97
virtual bool store(Field *) { return false; }
98
virtual bool store(void) { return false; }
99
virtual bool store(int32_t) { return false; }
100
virtual bool store(uint32_t) { return false; }
101
virtual bool store(int64_t) { return false; }
102
virtual bool store(uint64_t) { return false; }
103
virtual bool store(double, uint32_t, String*) { return false; }
104
virtual bool store(const type::Time*) { return false; }
105
virtual bool store(const char*) { return false; }
106
virtual bool store(const char*, size_t) { return false; }
107
virtual bool store(const std::string &) { return false; }
108
virtual bool haveMoreData(void) { return false;}
109
virtual bool haveError(void) { return false; }
110
virtual bool wasAborted(void) { return false; }
112
void pushSQL(const std::string &arg)
115
typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;
116
Tokenizer tok(arg, boost::escaped_list_separator<char>("\\", ";", "\""));
119
byte.resize(sizeof("START TRANSACTION")); // +1 for the COM_QUERY, provided by null count from sizeof()
121
memcpy(&byte[1], "START TRANSACTION", sizeof("START TRANSACTION") -1);
122
to_execute.push(byte);
125
for (Tokenizer::iterator iter= tok.begin(); iter != tok.end(); ++iter)
127
byte.resize((*iter).size() +1); // +1 for the COM_QUERY
129
memcpy(&byte[1], (*iter).c_str(), (*iter).size());
130
to_execute.push(byte);
134
byte.resize(sizeof("COMMIT")); // +1 for the COM_QUERY, provided by null count from sizeof()
136
memcpy(&byte[1], "COMMIT", sizeof("COMMIT") -1);
137
to_execute.push(byte);
142
} /* namespace client */
143
} /* namespace plugin */
144
} /* namespace drizzled */
146
#endif /* DRIZZLED_PLUGIN_CLIENT_CONCURRENT_H */