drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
plugin/client/concurrent.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 * Copyright (C) 2011 Vijay Samuel, [email protected]
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#pragma once
22
23#include <drizzled/plugin/client.h>
24#include <drizzled/execute/context.h>
25#include <drizzled/execute/parser.h>
26#include <drizzled/util/string.h>
27#include <vector>
28#include <queue>
29#include <string>
30#include <cstdio>
31
32using namespace std;
33
34namespace drizzled {
35namespace plugin {
36namespace client {
37
41class Concurrent: public Client
42{
43 typedef std::queue < drizzled::util::String > Queue;
44 Queue to_execute;
45 bool is_dead;
46 drizzled::util::String packet_buffer;
47
48public:
49
50 Concurrent() :
51 is_dead(false)
52 {
53 }
54
55 virtual int getFileDescriptor(void) { return -1; }
56 virtual bool isConnected(void) { return true; }
57 virtual bool flush(void) { return false; }
58 virtual void close(void) {}
59 virtual bool authenticate(void) { return true; }
60
61 virtual bool readCommand(char **packet, uint32_t& packet_length)
62 {
63 while(not to_execute.empty())
64 {
65 Queue::value_type next= to_execute.front();
66 packet_buffer= next;
67
68 *packet= packet_buffer.data();
69 packet_length= next.size();
70
71 to_execute.pop();
72
73 return true;
74 }
75
76 if (not is_dead)
77 {
78 packet_buffer.clear();
79 packet_length= 1;
80 *packet= packet_buffer.data();
81 is_dead= true;
82
83 return true;
84 }
85
86 packet_length= 0;
87 return false;
88 }
89
90 virtual void sendOK(void) {}
91 virtual void sendEOF(void) {}
92 virtual void sendError(const drizzled::error_t, const char*) {}
93 virtual void sendFields(List<Item>&) {}
94 virtual void store(Field*) {}
95 virtual void store() {}
96 virtual void store(int32_t) {}
97 virtual void store(uint32_t) {}
98 virtual void store(int64_t) {}
99 virtual void store(uint64_t) {}
100 virtual void store(double, uint32_t, String*) {}
101 virtual void store(const type::Time*) {}
102 virtual void store(const char*) {}
103 virtual void store(const char*, size_t) {}
104 virtual void store(str_ref) {}
105 virtual bool haveError(void) { return false; }
106 virtual bool wasAborted(void) { return false; }
107
108 void pushSQL(str_ref arg)
109 {
110 ::drizzled::error_t err_msg;
111 ::drizzled::execute::Context context(arg.data(), arg.size(), err_msg);
112 std::vector<std::string> parsed_tokens= context.start();
113
114 {
115 drizzled::util::String byte;
116 byte.assign(1, COM_QUERY); // Insert our COM_QUERY
117 byte.append(drizzle_literal_parameter("START TRANSACTION")); // +1 for the COM_QUERY, provided by null count from sizeof()
118 to_execute.push(byte);
119 }
120
121 for (const string& iter : parsed_tokens)
122 {
123 drizzled::util::String byte;
124 byte.assign(1, COM_QUERY); // Insert our COM_QUERY
125 byte.append(iter.data(), iter.size());
126 to_execute.push(byte);
127 }
128
129 {
130 drizzled::util::String byte;
131 byte.assign(1, COM_QUERY); // Insert our COM_QUERY
132 byte.append(drizzle_literal_parameter("COMMIT")); // +1 for the COM_QUERY, provided by null count from sizeof()
133 to_execute.push(byte);
134 }
135 }
136};
137
138} /* namespace client */
139} /* namespace plugin */
140} /* namespace drizzled */
141
virtual bool readCommand(char **packet, uint32_t &packet_length)
TODO: Rename this file - func.h is stupid.
STL namespace.