~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/mysql_protocol.cc

  • Committer: Prafulla Tekawade
  • Date: 2010-08-06 11:21:12 UTC
  • mto: (1711.1.21 build) (1725.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1714.
  • Revision ID: prafulla_t@users.sourceforge.net-20100806112112-7w5u0s3nx9u67nzt
Fix for Bug 586051

1. test_if_ref method which checks whether predicate is already evaluated
   due to ref/eq_ref access or not was incorrectly removing a predicate 
   that was not implicitly evaluated due to ref access (due to presence of filesort ?)
   It was field=NULL predicate.
   Such predicate should be kept and execution engine will filter out rows
   correctly. Removal of such predicate led to returning of rows which had
   NULL for join/predicate columns.
2. field COMP_OP NULL will always false for all fields except when COMP_OP
   is NULL-safe equality operator. Modified range optimizer to return zero
   row count in such cases.
   Query now does not even run. It returns zero result. As such Fix(1) is not
   required but we might hit that case in some other query (I have not tried it
   yet)
3. Fixed Field::val_str to print "NULL" for literal NULL instead of "0". It
   added lot of confusion while debugging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
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
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 */
19
19
 
20
20
#include "config.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"
31
30
#include "errmsg.h"
32
31
#include "mysql_protocol.h"
33
32
#include "mysql_password.h"
34
33
#include "options.h"
35
 
#include "table_function.h"
36
 
 
37
 
#define PROTOCOL_VERSION 10
38
34
 
39
35
namespace po= boost::program_options;
40
36
using namespace std;
41
37
using namespace drizzled;
42
38
 
43
 
namespace drizzle_plugin
 
39
#define PROTOCOL_VERSION 10
 
40
 
 
41
namespace drizzled
44
42
{
 
43
extern uint32_t global_thread_id;
 
44
}
45
45
 
46
 
std::vector<std::string> ClientMySQLProtocol::mysql_admin_ip_addresses;
47
46
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
48
 
 
49
 
static port_constraint port;
50
 
static timeout_constraint connect_timeout;
51
 
static timeout_constraint read_timeout;
52
 
static timeout_constraint write_timeout;
53
 
static retry_constraint retry_count;
54
 
static buffer_constraint buffer_length;
55
 
 
 
47
static uint32_t port;
 
48
static uint32_t connect_timeout;
 
49
static uint32_t read_timeout;
 
50
static uint32_t write_timeout;
 
51
static uint32_t retry_count;
 
52
static uint32_t buffer_length;
 
53
static char* bind_address;
56
54
static uint32_t random_seed1;
57
55
static uint32_t random_seed2;
58
56
static const uint32_t random_max= 0x3FFFFFFF;
59
57
static const double random_max_double= (double)0x3FFFFFFF;
60
58
 
61
 
 
62
 
ProtocolCounters *ListenMySQLProtocol::mysql_counters= new ProtocolCounters();
63
 
 
64
 
ListenMySQLProtocol::~ListenMySQLProtocol()
65
 
{ }
66
 
 
67
 
const std::string ListenMySQLProtocol::getHost(void) const
 
59
const char* ListenMySQLProtocol::getHost(void) const
68
60
{
69
 
  return _hostname;
 
61
  return bind_address;
70
62
}
71
63
 
72
64
in_port_t ListenMySQLProtocol::getPort(void) const
73
65
{
74
 
  return port.get();
 
66
  return (in_port_t) port;
75
67
}
76
68
 
77
69
plugin::Client *ListenMySQLProtocol::getClient(int fd)
81
73
  if (new_fd == -1)
82
74
    return NULL;
83
75
 
84
 
  return new ClientMySQLProtocol(new_fd, _using_mysql41_protocol, getCounters());
 
76
  return new (nothrow) ClientMySQLProtocol(new_fd, using_mysql41_protocol);
85
77
}
86
78
 
87
 
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol, ProtocolCounters *set_counters):
88
 
  is_admin_connection(false),
89
 
  _using_mysql41_protocol(using_mysql41_protocol),
90
 
  counters(set_counters)
 
79
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol_arg):
 
80
  using_mysql41_protocol(using_mysql41_protocol_arg)
91
81
{
92
 
  
93
82
  net.vio= 0;
94
83
 
95
84
  if (fd == -1)
96
85
    return;
97
86
 
98
 
  if (drizzleclient_net_init_sock(&net, fd, buffer_length.get()))
 
87
  if (drizzleclient_net_init_sock(&net, fd, buffer_length))
99
88
    throw bad_alloc();
100
89
 
101
 
  drizzleclient_net_set_read_timeout(&net, read_timeout.get());
102
 
  drizzleclient_net_set_write_timeout(&net, write_timeout.get());
103
 
  net.retry_count=retry_count.get();
 
90
  drizzleclient_net_set_read_timeout(&net, read_timeout);
 
91
  drizzleclient_net_set_write_timeout(&net, write_timeout);
 
92
  net.retry_count=retry_count;
104
93
}
105
94
 
106
95
ClientMySQLProtocol::~ClientMySQLProtocol()
107
96
{
108
97
  if (net.vio)
109
 
    net.vio->close();
 
98
    vio_close(net.vio);
110
99
}
111
100
 
112
101
int ClientMySQLProtocol::getFileDescriptor(void)
145
134
  { 
146
135
    drizzleclient_net_close(&net);
147
136
    drizzleclient_net_end(&net);
148
 
    if (is_admin_connection)
149
 
      counters->adminConnected.decrement();
150
 
    else
151
 
      counters->connected.decrement();
152
137
  }
153
138
}
154
139
 
155
140
bool ClientMySQLProtocol::authenticate()
156
141
{
157
142
  bool connection_is_valid;
158
 
  if (is_admin_connection)
159
 
  {
160
 
    counters->adminConnectionCount.increment();
161
 
    counters->adminConnected.increment();
162
 
  }
163
 
  else
164
 
  {
165
 
    counters->connectionCount.increment();
166
 
    counters->connected.increment();
167
 
  }
168
143
 
169
144
  /* Use "connect_timeout" value during connection phase */
170
 
  drizzleclient_net_set_read_timeout(&net, connect_timeout.get());
171
 
  drizzleclient_net_set_write_timeout(&net, connect_timeout.get());
 
145
  drizzleclient_net_set_read_timeout(&net, connect_timeout);
 
146
  drizzleclient_net_set_write_timeout(&net, connect_timeout);
172
147
 
173
148
  connection_is_valid= checkConnection();
174
149
 
175
150
  if (connection_is_valid)
176
 
  {
177
 
    if (not is_admin_connection and (counters->connected > counters->max_connections))
178
 
    {
179
 
      std::string errmsg(ER(ER_CON_COUNT_ERROR));
180
 
      sendError(ER_CON_COUNT_ERROR, errmsg.c_str());
181
 
      counters->failedConnections.increment();
182
 
    }
183
 
    else
184
 
    {
185
 
      sendOK();
186
 
    }
187
 
  }
 
151
    sendOK();
188
152
  else
189
153
  {
190
154
    sendError(session->main_da.sql_errno(), session->main_da.message());
191
 
    counters->failedConnections.increment();
192
155
    return false;
193
156
  }
194
157
 
195
158
  /* Connect completed, set read/write timeouts back to default */
196
 
  drizzleclient_net_set_read_timeout(&net, read_timeout.get());
197
 
  drizzleclient_net_set_write_timeout(&net, write_timeout.get());
 
159
  drizzleclient_net_set_read_timeout(&net, read_timeout);
 
160
  drizzleclient_net_set_write_timeout(&net, write_timeout);
198
161
  return true;
199
162
}
200
163
 
231
194
      return false;                       // We have to close it.
232
195
 
233
196
    net.error= 0;
 
197
    *packet_length= 0;
 
198
    return true;
234
199
  }
235
200
 
236
201
  *l_packet= (char*) net.read_pos;
250
215
    (*l_packet)[0]= (unsigned char) COM_SLEEP;
251
216
    *packet_length= 1;
252
217
  }
253
 
  else if (_using_mysql41_protocol)
 
218
  else if (using_mysql41_protocol)
254
219
  {
255
220
    /* Map from MySQL commands to Drizzle commands. */
256
221
    switch ((int)(*l_packet)[0])
390
355
    drizzleclient_net_flush(&net);
391
356
    session->main_da.can_overwrite_status= false;
392
357
  }
393
 
  packet.shrink(buffer_length.get());
 
358
  packet.shrink(buffer_length);
394
359
}
395
360
 
396
361
 
443
408
 
444
409
  drizzleclient_net_write_command(&net,(unsigned char) 255, (unsigned char*) "", 0, (unsigned char*) err, length);
445
410
 
446
 
  drizzleclient_net_flush(&net);
447
 
 
448
411
  session->main_da.can_overwrite_status= false;
449
412
}
450
413
 
500
463
    int2store(pos, field.charsetnr);
501
464
    int4store(pos+2, field.length);
502
465
 
503
 
    if (_using_mysql41_protocol)
 
466
    if (using_mysql41_protocol)
504
467
    {
505
468
      /* Switch to MySQL field numbering. */
506
469
      switch (field.type)
537
500
        pos[6]= 15;
538
501
        break;
539
502
 
540
 
      case DRIZZLE_TYPE_UUID:
541
 
        pos[6]= 15;
542
 
        break;
543
 
 
544
503
      case DRIZZLE_TYPE_DECIMAL:
545
504
        pos[6]= (char)246;
546
505
        break;
592
551
  char buff[MAX_FIELD_WIDTH];
593
552
  String str(buff,sizeof(buff), &my_charset_bin);
594
553
 
595
 
  from->val_str_internal(&str);
 
554
  from->val_str(&str);
596
555
 
597
556
  return netStoreData((const unsigned char *)str.ptr(), str.length());
598
557
}
688
647
 
689
648
    server_capabilites= CLIENT_BASIC_FLAGS;
690
649
 
691
 
    if (_using_mysql41_protocol)
 
650
    if (using_mysql41_protocol)
692
651
      server_capabilites|= CLIENT_PROTOCOL_MYSQL41;
693
652
 
694
653
#ifdef HAVE_COMPRESS
702
661
    *end= 0;
703
662
    end++;
704
663
 
705
 
    int4store((unsigned char*) end, session->variables.pseudo_thread_id);
 
664
    int4store((unsigned char*) end, global_thread_id);
706
665
    end+= 4;
707
666
 
708
667
    /* We don't use scramble anymore. */
736
695
      return false;
737
696
    }
738
697
  }
739
 
  if (packet.alloc(buffer_length.get()))
 
698
  if (packet.alloc(buffer_length))
740
699
    return false; /* The error is set by alloc(). */
741
700
 
742
701
  client_capabilities= uint2korr(net.read_pos);
814
773
    user_len-= 2;
815
774
  }
816
775
 
817
 
  if (client_capabilities & CLIENT_ADMIN)
818
 
  {
819
 
    if ((strncmp(user, "root", 4) == 0) and isAdminAllowed())
820
 
    {
821
 
      is_admin_connection= true;
822
 
    }
823
 
    else
824
 
    {
825
 
      my_error(ER_ADMIN_ACCESS, MYF(0));
826
 
      return false;
827
 
    }
828
 
  }
829
 
 
830
776
  session->getSecurityContext().setUser(user);
831
777
 
832
 
  return session->checkUser(string(passwd, passwd_len),
833
 
                            string(l_db ? l_db : ""));
834
 
 
835
 
}
836
 
 
837
 
bool ClientMySQLProtocol::isAdminAllowed(void)
838
 
{
839
 
  if (std::find(mysql_admin_ip_addresses.begin(), mysql_admin_ip_addresses.end(), session->getSecurityContext().getIp()) != mysql_admin_ip_addresses.end())
840
 
    return true;
841
 
  else
842
 
    return false;
 
778
  return session->checkUser(passwd, passwd_len, l_db);
843
779
}
844
780
 
845
781
bool ClientMySQLProtocol::netStoreData(const unsigned char *from, size_t length)
934
870
  uint32_t pointer_seed;
935
871
  memcpy(&pointer_seed, &pointer, 4);
936
872
  uint32_t random1= (seed + pointer_seed) % random_max;
937
 
  uint32_t random2= (seed + session->variables.pseudo_thread_id + net.vio->get_fd()) % random_max;
 
873
  uint32_t random2= (seed + global_thread_id + net.vio->sd) % random_max;
938
874
 
939
875
  for (char *end= scramble + SCRAMBLE_LENGTH; scramble != end; scramble++)
940
876
  {
944
880
  }
945
881
}
946
882
 
947
 
void ClientMySQLProtocol::mysql_compose_ip_addresses(vector<string> options)
948
 
{
949
 
  for (vector<string>::iterator it= options.begin();
950
 
       it != options.end();
951
 
       ++it)
952
 
  {
953
 
    tokenize(*it, mysql_admin_ip_addresses, ",", true);
954
 
  }
955
 
}
956
 
 
957
883
static ListenMySQLProtocol *listen_obj= NULL;
958
884
plugin::Create_function<MySQLPassword> *mysql_password= NULL;
959
885
 
960
886
static int init(drizzled::module::Context &context)
961
887
{  
962
 
  context.add(new MysqlProtocolStatus);
963
888
 
964
889
  /* Initialize random seeds for the MySQL algorithm with minimal changes. */
965
890
  time_t seed_time= time(NULL);
967
892
  random_seed2= (seed_time / 2) % random_max;
968
893
 
969
894
  const module::option_map &vm= context.getOptions();
 
895
  if (vm.count("port"))
 
896
  { 
 
897
    if (port > 65535)
 
898
    {
 
899
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of port\n"));
 
900
      exit(-1);
 
901
    }
 
902
  }
 
903
 
 
904
  if (vm.count("connect-timeout"))
 
905
  {
 
906
    if (connect_timeout < 1 || connect_timeout > 300)
 
907
    {
 
908
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for connect_timeout\n"));
 
909
      exit(-1);
 
910
    }
 
911
  }
 
912
 
 
913
  if (vm.count("read-timeout"))
 
914
  {
 
915
    if (read_timeout < 1 || read_timeout > 300)
 
916
    {
 
917
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for read_timeout\n"));
 
918
      exit(-1);
 
919
    }
 
920
  }
 
921
 
 
922
  if (vm.count("write-timeout"))
 
923
  {
 
924
    if (write_timeout < 1 || write_timeout > 300)
 
925
    {
 
926
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for write_timeout\n"));
 
927
      exit(-1);
 
928
    }
 
929
  }
 
930
 
 
931
  if (vm.count("retry-count"))
 
932
  {
 
933
    if (retry_count < 1 || retry_count > 100)
 
934
    {
 
935
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count"));
 
936
      exit(-1);
 
937
    }
 
938
  }
 
939
 
 
940
  if (vm.count("buffer-length"))
 
941
  {
 
942
    if (buffer_length < 1024 || buffer_length > 1024*1024)
 
943
    {
 
944
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for buffer_length\n"));
 
945
      exit(-1);
 
946
    }
 
947
  }
 
948
 
 
949
  if (vm.count("bind-address"))
 
950
  {
 
951
    bind_address= strdup(vm["bind-address"].as<string>().c_str());
 
952
  }
 
953
 
 
954
  else
 
955
  {
 
956
    bind_address= NULL;
 
957
  }
970
958
 
971
959
  mysql_password= new plugin::Create_function<MySQLPassword>(MySQLPasswordName);
972
960
  context.add(mysql_password);
973
961
 
974
 
  listen_obj= new ListenMySQLProtocol("mysql_protocol", vm["bind-address"].as<std::string>(), true);
 
962
  listen_obj= new ListenMySQLProtocol("mysql_protocol", true);
975
963
  context.add(listen_obj); 
976
 
  context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
977
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("connect_timeout", connect_timeout));
978
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("read_timeout", read_timeout));
979
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("write_timeout", write_timeout));
980
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("retry_count", retry_count));
981
 
  context.registerVariable(new sys_var_constrained_value<uint32_t>("buffer_length", buffer_length));
982
 
  context.registerVariable(new sys_var_const_string_val("bind_address",
983
 
                                                        vm["bind-address"].as<std::string>()));
984
 
 
985
 
  context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenMySQLProtocol::mysql_counters->max_connections));
986
964
 
987
965
  return 0;
988
966
}
989
967
 
 
968
static DRIZZLE_SYSVAR_UINT(port, port, PLUGIN_VAR_RQCMDARG,
 
969
                           N_("Port number to use for connection or 0 for default to with MySQL "
 
970
                              "protocol."),
 
971
                           NULL, NULL, 3306, 0, 65535, 0);
 
972
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
 
973
                           PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
 
974
                           NULL, NULL, 10, 1, 300, 0);
 
975
static DRIZZLE_SYSVAR_UINT(read_timeout, read_timeout, PLUGIN_VAR_RQCMDARG,
 
976
                           N_("Read Timeout."), NULL, NULL, 30, 1, 300, 0);
 
977
static DRIZZLE_SYSVAR_UINT(write_timeout, write_timeout, PLUGIN_VAR_RQCMDARG,
 
978
                           N_("Write Timeout."), NULL, NULL, 60, 1, 300, 0);
 
979
static DRIZZLE_SYSVAR_UINT(retry_count, retry_count, PLUGIN_VAR_RQCMDARG,
 
980
                           N_("Retry Count."), NULL, NULL, 10, 1, 100, 0);
 
981
static DRIZZLE_SYSVAR_UINT(buffer_length, buffer_length, PLUGIN_VAR_RQCMDARG,
 
982
                           N_("Buffer length."), NULL, NULL, 16384, 1024,
 
983
                           1024*1024, 0);
 
984
static DRIZZLE_SYSVAR_STR(bind_address, bind_address, PLUGIN_VAR_READONLY,
 
985
                          N_("Address to bind to."), NULL, NULL, NULL);
 
986
 
990
987
static void init_options(drizzled::module::option_context &context)
991
988
{
992
989
  context("port",
993
 
          po::value<port_constraint>(&port)->default_value(3306),
 
990
          po::value<uint32_t>(&port)->default_value(3306),
994
991
          N_("Port number to use for connection or 0 for default to with MySQL "
995
992
                              "protocol."));
996
993
  context("connect-timeout",
997
 
          po::value<timeout_constraint>(&connect_timeout)->default_value(10),
 
994
          po::value<uint32_t>(&connect_timeout)->default_value(10),
998
995
          N_("Connect Timeout."));
999
996
  context("read-timeout",
1000
 
          po::value<timeout_constraint>(&read_timeout)->default_value(30),
 
997
          po::value<uint32_t>(&read_timeout)->default_value(30),
1001
998
          N_("Read Timeout."));
1002
999
  context("write-timeout",
1003
 
          po::value<timeout_constraint>(&write_timeout)->default_value(60),
 
1000
          po::value<uint32_t>(&write_timeout)->default_value(60),
1004
1001
          N_("Write Timeout."));
1005
1002
  context("retry-count",
1006
 
          po::value<retry_constraint>(&retry_count)->default_value(10),
 
1003
          po::value<uint32_t>(&retry_count)->default_value(10),
1007
1004
          N_("Retry Count."));
1008
1005
  context("buffer-length",
1009
 
          po::value<buffer_constraint>(&buffer_length)->default_value(16384),
 
1006
          po::value<uint32_t>(&buffer_length)->default_value(16384),
1010
1007
          N_("Buffer length."));
1011
1008
  context("bind-address",
1012
 
          po::value<string>()->default_value(""),
 
1009
          po::value<string>(),
1013
1010
          N_("Address to bind to."));
1014
 
  context("max-connections",
1015
 
          po::value<uint32_t>(&ListenMySQLProtocol::mysql_counters->max_connections)->default_value(1000),
1016
 
          N_("Maximum simultaneous connections."));
1017
 
  context("admin-ip-addresses",
1018
 
          po::value<vector<string> >()->composing()->notifier(&ClientMySQLProtocol::mysql_compose_ip_addresses),
1019
 
          N_("A restrictive IP address list for incoming admin connections."));
1020
 
}
1021
 
 
1022
 
static int mysql_protocol_connection_count_func(drizzle_show_var *var, char *buff)
1023
 
{
1024
 
  var->type= SHOW_LONGLONG;
1025
 
  var->value= buff;
1026
 
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->connectionCount;
1027
 
  return 0;
1028
 
}
1029
 
 
1030
 
static int mysql_protocol_connected_count_func(drizzle_show_var *var, char *buff)
1031
 
{
1032
 
  var->type= SHOW_LONGLONG;
1033
 
  var->value= buff;
1034
 
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->connected;
1035
 
  return 0;
1036
 
}
1037
 
 
1038
 
static int mysql_protocol_failed_count_func(drizzle_show_var *var, char *buff)
1039
 
{
1040
 
  var->type= SHOW_LONGLONG;
1041
 
  var->value= buff;
1042
 
  *((uint64_t *)buff)= ListenMySQLProtocol::mysql_counters->failedConnections;
1043
 
  return 0;
1044
 
}
1045
 
 
1046
 
static st_show_var_func_container mysql_protocol_connection_count=
1047
 
  { &mysql_protocol_connection_count_func };
1048
 
 
1049
 
static st_show_var_func_container mysql_protocol_connected_count=
1050
 
  { &mysql_protocol_connected_count_func };
1051
 
 
1052
 
static st_show_var_func_container mysql_protocol_failed_count=
1053
 
  { &mysql_protocol_failed_count_func };
1054
 
 
1055
 
static drizzle_show_var mysql_protocol_status_variables[]= {
1056
 
  {"Connections",
1057
 
  (char*) &mysql_protocol_connection_count, SHOW_FUNC},
1058
 
  {"Connected",
1059
 
  (char*) &mysql_protocol_connected_count, SHOW_FUNC},
1060
 
  {"Failed_connections",
1061
 
  (char*) &mysql_protocol_failed_count, SHOW_FUNC},
1062
 
  {NULL, NULL, SHOW_LONGLONG}
 
1011
}
 
1012
 
 
1013
static drizzle_sys_var* sys_variables[]= {
 
1014
  DRIZZLE_SYSVAR(port),
 
1015
  DRIZZLE_SYSVAR(connect_timeout),
 
1016
  DRIZZLE_SYSVAR(read_timeout),
 
1017
  DRIZZLE_SYSVAR(write_timeout),
 
1018
  DRIZZLE_SYSVAR(retry_count),
 
1019
  DRIZZLE_SYSVAR(buffer_length),
 
1020
  DRIZZLE_SYSVAR(bind_address),
 
1021
  NULL
1063
1022
};
1064
1023
 
1065
 
MysqlProtocolStatus::Generator::Generator(drizzled::Field **fields) :
1066
 
  plugin::TableFunction::Generator(fields)
1067
 
{
1068
 
  status_var_ptr= mysql_protocol_status_variables;
1069
 
}
1070
 
 
1071
 
bool MysqlProtocolStatus::Generator::populate()
1072
 
{
1073
 
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1074
 
  char * const buff= (char *) &buff_data;
1075
 
  drizzle_show_var tmp;
1076
 
 
1077
 
  if (status_var_ptr->name)
1078
 
  {
1079
 
    std::ostringstream oss;
1080
 
    string return_value;
1081
 
    const char *value;
1082
 
    int type;
1083
 
 
1084
 
    push(status_var_ptr->name);
1085
 
 
1086
 
    if (status_var_ptr->type == SHOW_FUNC)
1087
 
    {
1088
 
      ((drizzle_show_var_func)((st_show_var_func_container *)status_var_ptr->value)->func)(&tmp, buff);
1089
 
      value= buff;
1090
 
      type= tmp.type;
1091
 
    }
1092
 
    else
1093
 
    {
1094
 
      value= status_var_ptr->value;
1095
 
      type= status_var_ptr->type;
1096
 
    }
1097
 
 
1098
 
    switch(type)
1099
 
    {
1100
 
    case SHOW_LONGLONG:
1101
 
      oss << *(uint64_t*) value;
1102
 
      return_value= oss.str();
1103
 
      break;
1104
 
    default:
1105
 
      assert(0);
1106
 
    }
1107
 
    if (return_value.length())
1108
 
      push(return_value);
1109
 
    else
1110
 
      push(" ");
1111
 
 
1112
 
    status_var_ptr++;
1113
 
 
1114
 
    return true;
1115
 
  }
1116
 
  return false;
1117
 
}
1118
 
 
1119
 
} /* namespace drizzle_plugin */
1120
 
 
1121
1024
DRIZZLE_DECLARE_PLUGIN
1122
1025
{
1123
1026
  DRIZZLE_VERSION_ID,
1126
1029
  "Eric Day",
1127
1030
  "MySQL Protocol Module",
1128
1031
  PLUGIN_LICENSE_GPL,
1129
 
  drizzle_plugin::init,             /* Plugin Init */
1130
 
  NULL, /* system variables */
1131
 
  drizzle_plugin::init_options    /* config options */
 
1032
  init,             /* Plugin Init */
 
1033
  sys_variables, /* system variables */
 
1034
  init_options    /* config options */
1132
1035
}
1133
1036
DRIZZLE_DECLARE_PLUGIN_END;