17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
21
#include <drizzled/gettext.h>
22
22
#include <drizzled/error.h>
23
23
#include <drizzled/query_id.h>
24
#include <drizzled/sql_state.h>
24
#include <drizzled/error/sql_state.h>
25
25
#include <drizzled/session.h>
26
#include "drizzled/internal/m_string.h"
26
#include <drizzled/internal/m_string.h>
27
27
#include <algorithm>
28
28
#include <boost/program_options.hpp>
29
29
#include <drizzled/module/option_map.h>
30
#include "drizzled/util/tokenize.h"
30
#include <drizzled/util/tokenize.h>
31
31
#include "errmsg.h"
32
32
#include "mysql_protocol.h"
33
33
#include "mysql_password.h"
34
34
#include "options.h"
35
#include "table_function.h"
37
#include "drizzled/identifier.h"
35
#include <drizzled/identifier.h>
36
#include <drizzled/plugin/function.h>
37
#include <drizzled/diagnostics_area.h>
38
#include <drizzled/system_variables.h>
39
#include <libdrizzle/constants.h>
41
#define MIN_HANDSHAKE_SIZE 6
39
42
#define PROTOCOL_VERSION 10
41
44
namespace po= boost::program_options;
328
347
buff[0]=0; // No fields
329
if (session->main_da.status() == Diagnostics_area::DA_OK)
348
if (session->main_da().status() == Diagnostics_area::DA_OK)
331
if (client_capabilities & CLIENT_FOUND_ROWS && session->main_da.found_rows())
332
pos=storeLength(buff+1,session->main_da.found_rows());
350
if (client_capabilities & CLIENT_FOUND_ROWS && session->main_da().found_rows())
351
pos=storeLength(buff+1,session->main_da().found_rows());
334
pos=storeLength(buff+1,session->main_da.affected_rows());
335
pos=storeLength(pos, session->main_da.last_insert_id());
336
int2store(pos, session->main_da.server_status());
353
pos=storeLength(buff+1,session->main_da().affected_rows());
354
pos=storeLength(pos, session->main_da().last_insert_id());
355
int2store(pos, session->main_da().server_status());
338
tmp= min(session->main_da.total_warn_count(), (uint32_t)65535);
339
message= session->main_da.message();
357
tmp= min(session->main_da().total_warn_count(), (uint32_t)65535);
358
message= session->main_da().message();
386
405
/* Set to true if no active vio, to work well in case of --init-file */
387
406
if (net.vio != 0)
389
session->main_da.can_overwrite_status= true;
390
writeEOFPacket(session->main_da.server_status(),
391
session->main_da.total_warn_count());
408
session->main_da().can_overwrite_status= true;
409
writeEOFPacket(session->main_da().server_status(),
410
session->main_da().total_warn_count());
392
411
drizzleclient_net_flush(&net);
393
session->main_da.can_overwrite_status= false;
412
session->main_da().can_overwrite_status= false;
395
414
packet.shrink(buffer_length.get());
399
void ClientMySQLProtocol::sendError(uint32_t sql_errno, const char *err)
418
void ClientMySQLProtocol::sendError(drizzled::error_t sql_errno, const char *err)
432
int2store(buff,sql_errno);
451
int2store(buff, static_cast<uint16_t>(sql_errno));
435
454
/* The first # is to make the client backward compatible */
437
pos= (unsigned char*) strcpy((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
438
pos+= strlen(drizzle_errno_to_sqlstate(sql_errno));
456
pos= (unsigned char*) strcpy((char*) buff+3, error::convert_to_sqlstate(sql_errno));
457
pos+= strlen(error::convert_to_sqlstate(sql_errno));
440
459
char *tmp= strncpy((char*)pos, err, DRIZZLE_ERRMSG_SIZE-1);
441
460
tmp+= strlen((char*)pos);
508
527
switch (field.type)
510
529
case DRIZZLE_TYPE_LONG:
530
pos[6]= DRIZZLE_COLUMN_TYPE_LONG;
514
533
case DRIZZLE_TYPE_DOUBLE:
534
pos[6]= DRIZZLE_COLUMN_TYPE_DOUBLE;
518
537
case DRIZZLE_TYPE_NULL:
538
pos[6]= DRIZZLE_COLUMN_TYPE_NULL;
522
541
case DRIZZLE_TYPE_TIMESTAMP:
542
pos[6]= DRIZZLE_COLUMN_TYPE_TIMESTAMP;
526
545
case DRIZZLE_TYPE_LONGLONG:
546
pos[6]= DRIZZLE_COLUMN_TYPE_LONGLONG;
530
549
case DRIZZLE_TYPE_DATETIME:
550
pos[6]= DRIZZLE_COLUMN_TYPE_DATETIME;
553
case DRIZZLE_TYPE_TIME:
554
pos[6]= DRIZZLE_COLUMN_TYPE_TIME;
534
557
case DRIZZLE_TYPE_DATE:
558
pos[6]= DRIZZLE_COLUMN_TYPE_DATE;
538
561
case DRIZZLE_TYPE_VARCHAR:
562
pos[6]= DRIZZLE_COLUMN_TYPE_VARCHAR;
565
case DRIZZLE_TYPE_MICROTIME:
566
pos[6]= DRIZZLE_COLUMN_TYPE_VARCHAR;
542
569
case DRIZZLE_TYPE_UUID:
570
pos[6]= DRIZZLE_COLUMN_TYPE_VARCHAR;
573
case DRIZZLE_TYPE_BOOLEAN:
574
pos[6]= DRIZZLE_COLUMN_TYPE_TINY;
546
577
case DRIZZLE_TYPE_DECIMAL:
578
pos[6]= (char)DRIZZLE_COLUMN_TYPE_NEWDECIMAL;
550
581
case DRIZZLE_TYPE_ENUM:
582
pos[6]= (char)DRIZZLE_COLUMN_TYPE_ENUM;
554
585
case DRIZZLE_TYPE_BLOB:
586
pos[6]= (char)DRIZZLE_COLUMN_TYPE_BLOB;
1000
1051
context("port",
1001
1052
po::value<port_constraint>(&port)->default_value(3306),
1002
N_("Port number to use for connection or 0 for default to with MySQL "
1053
_("Port number to use for connection or 0 for default to with MySQL "
1004
1055
context("connect-timeout",
1005
1056
po::value<timeout_constraint>(&connect_timeout)->default_value(10),
1006
N_("Connect Timeout."));
1057
_("Connect Timeout."));
1007
1058
context("read-timeout",
1008
1059
po::value<timeout_constraint>(&read_timeout)->default_value(30),
1009
N_("Read Timeout."));
1060
_("Read Timeout."));
1010
1061
context("write-timeout",
1011
1062
po::value<timeout_constraint>(&write_timeout)->default_value(60),
1012
N_("Write Timeout."));
1063
_("Write Timeout."));
1013
1064
context("retry-count",
1014
1065
po::value<retry_constraint>(&retry_count)->default_value(10),
1015
N_("Retry Count."));
1016
1067
context("buffer-length",
1017
1068
po::value<buffer_constraint>(&buffer_length)->default_value(16384),
1018
N_("Buffer length."));
1069
_("Buffer length."));
1019
1070
context("bind-address",
1020
po::value<string>()->default_value(""),
1021
N_("Address to bind to."));
1071
po::value<string>()->default_value("localhost"),
1072
_("Address to bind to."));
1022
1073
context("max-connections",
1023
1074
po::value<uint32_t>(&ListenMySQLProtocol::mysql_counters->max_connections)->default_value(1000),
1024
N_("Maximum simultaneous connections."));
1075
_("Maximum simultaneous connections."));
1025
1076
context("admin-ip-addresses",
1026
1077
po::value<vector<string> >()->composing()->notifier(&ClientMySQLProtocol::mysql_compose_ip_addresses),
1027
N_("A restrictive IP address list for incoming admin connections."));
1030
static int mysql_protocol_connection_count_func(drizzle_show_var *var, char *buff)
1032
var->type= SHOW_LONGLONG;
1034
*((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->connectionCount;
1038
static int mysql_protocol_connected_count_func(drizzle_show_var *var, char *buff)
1040
var->type= SHOW_LONGLONG;
1042
*((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->connected;
1046
static int mysql_protocol_failed_count_func(drizzle_show_var *var, char *buff)
1048
var->type= SHOW_LONGLONG;
1050
*((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->failedConnections;
1054
static st_show_var_func_container mysql_protocol_connection_count=
1055
{ &mysql_protocol_connection_count_func };
1057
static st_show_var_func_container mysql_protocol_connected_count=
1058
{ &mysql_protocol_connected_count_func };
1060
static st_show_var_func_container mysql_protocol_failed_count=
1061
{ &mysql_protocol_failed_count_func };
1063
static drizzle_show_var mysql_protocol_status_variables[]= {
1065
(char*) &mysql_protocol_connection_count, SHOW_FUNC},
1067
(char*) &mysql_protocol_connected_count, SHOW_FUNC},
1068
{"Failed_connections",
1069
(char*) &mysql_protocol_failed_count, SHOW_FUNC},
1070
{NULL, NULL, SHOW_LONGLONG}
1073
MysqlProtocolStatus::Generator::Generator(drizzled::Field **fields) :
1074
plugin::TableFunction::Generator(fields)
1076
status_var_ptr= mysql_protocol_status_variables;
1079
bool MysqlProtocolStatus::Generator::populate()
1081
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1082
char * const buff= (char *) &buff_data;
1083
drizzle_show_var tmp;
1085
if (status_var_ptr->name)
1087
std::ostringstream oss;
1088
string return_value;
1092
push(status_var_ptr->name);
1094
if (status_var_ptr->type == SHOW_FUNC)
1096
((drizzle_show_var_func)((st_show_var_func_container *)status_var_ptr->value)->func)(&tmp, buff);
1102
value= status_var_ptr->value;
1103
type= status_var_ptr->type;
1109
oss << *(uint64_t*) value;
1110
return_value= oss.str();
1115
if (return_value.length())
1078
_("A restrictive IP address list for incoming admin connections."));
1127
1081
} /* namespace drizzle_plugin */