13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
#include <drizzled/field.h>
17
18
#include <drizzled/gettext.h>
18
19
#include <drizzled/plugin/listen_tcp.h>
19
20
#include <drizzled/plugin/client.h>
20
21
#include <drizzled/session.h>
21
22
#include <drizzled/module/option_map.h>
23
23
#include <drizzled/plugin/catalog.h>
24
#include <drizzled/plugin.h>
25
26
#include <iostream>
27
28
#include <boost/program_options.hpp>
30
#include <client/user_detect.h>
29
32
using namespace std;
30
33
using namespace drizzled;
115
106
virtual bool authenticate(void)
117
108
printDebug("authenticate");
118
identifier::User::shared_ptr user= identifier::User::make_shared();
109
identifier::user::mptr user= identifier::User::make_shared();
119
110
user->setUser(username);
120
111
session->setUser(user);
122
113
return session->checkUser(password, schema);
125
virtual bool readCommand(char **packet, uint32_t *packet_length)
116
virtual bool readCommand(char **packet, uint32_t& packet_length)
147
cin.getline(*packet + *packet_length, length - *packet_length, ';');
148
*packet_length+= cin.gcount();
138
cin.getline(*packet + packet_length, length - packet_length, ';');
139
packet_length+= cin.gcount();
151
142
while (cin.eof() == false && cin.fail() == true);
153
if ((*packet_length == 1 && cin.eof() == true) or
144
if ((packet_length == 1 && cin.eof() == true) or
154
145
not strncasecmp(*packet + 1, "quit", 4) or
155
146
not strncasecmp(*packet + 1, "exit", 4) or
156
147
not strncasecmp(*packet + 1, "shutdown", sizeof("shutdown") -1))
160
151
(*packet)[0]= COM_SHUTDOWN;
185
176
cout << "Error: " << static_cast<long>(sql_errno) << " " << err << endl;
188
virtual bool sendFields(List<Item> *list)
179
virtual void sendFields(List<Item>& list)
190
List_iterator_fast<Item> it(*list);
181
List<Item>::iterator it(list.begin());
186
while (Item* item=it++)
199
189
item->make_field(&field);
200
190
cout << field.col_name << "\t";
209
196
virtual void checkRowEnd(void)
225
212
return store(str.ptr(), str.length());
228
virtual bool store(void)
215
virtual void store(void)
230
217
cout << "NULL" << "\t";
235
virtual bool store(int32_t from)
237
cout << from << "\t";
242
virtual bool store(uint32_t from)
244
cout << from << "\t";
249
virtual bool store(int64_t from)
251
cout << from << "\t";
256
virtual bool store(uint64_t from)
258
cout << from << "\t";
263
virtual bool store(double from, uint32_t decimals, String *buffer)
221
virtual void store(int32_t from)
223
cout << from << "\t";
227
virtual void store(uint32_t from)
229
cout << from << "\t";
233
virtual void store(int64_t from)
235
cout << from << "\t";
239
virtual void store(uint64_t from)
241
cout << from << "\t";
245
virtual void store(double from, uint32_t decimals, String *buffer)
265
247
buffer->set_real(from, decimals, &my_charset_bin);
266
return store(buffer->ptr(), buffer->length());
248
store(buffer->ptr(), buffer->length());
269
virtual bool store(const char *from, size_t length)
251
virtual void store(const char *from, size_t length)
271
253
cout.write(from, length);
277
virtual bool haveMoreData(void)
279
printDebug("haveMoreData");
283
virtual bool haveError(void)
258
virtual bool haveError()
285
260
printDebug("haveError");
289
virtual bool wasAborted(void)
264
virtual bool wasAborted()
291
266
printDebug("wasAborted");
270
bool isConsole() const
275
bool isInteractive() const
361
341
static int init(drizzled::module::Context &context)
363
343
const module::option_map &vm= context.getOptions();
364
const string username(vm.count("username") ? vm["username"].as<string>() : "");
365
const string password(vm.count("password") ? vm["password"].as<string>() : "");
366
const string schema(vm.count("schema") ? vm["schema"].as<string>() : "");
368
const std::string catalog(vm.count("catalog") ? vm["catalog"].as<string>() : "LOCAL");
370
context.add(new ListenConsole("console", username, password, schema, catalog));
344
context.add(new ListenConsole("console", vm["username"].as<string>(),
345
vm["password"].as<string>(), vm["schema"].as<string>(), vm["catalog"].as<string>()));
381
355
po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
382
356
N_("Turn on extra debugging."));
357
UserDetect detected_user;
358
const char* shell_user= detected_user.getUser();
383
359
context("username",
360
po::value<string>()->default_value(shell_user ? shell_user : ""),
385
361
N_("User to use for auth."));
386
362
context("password",
363
po::value<string>()->default_value(""),
388
364
N_("Password to use for auth."));
389
365
context("catalog",
366
po::value<string>()->default_value("LOCAL"),
391
367
N_("Default catalog to use."));
392
368
context("schema",
369
po::value<string>()->default_value(""),
394
370
N_("Default schema to use."));