~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/mysql_protocol.cc

  • Committer: Lee Bieber
  • Date: 2011-03-18 04:10:25 UTC
  • mfrom: (2241.1.2 build)
  • Revision ID: kalebral@gmail.com-20110318041025-1xoj1azy6zobhnbm
Merge Stewart - refactoring of default values
Merge Olaf - more refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <config.h>
21
21
#include <drizzled/gettext.h>
22
22
#include <drizzled/error.h>
23
23
#include <drizzled/query_id.h>
24
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
 
 
36
 
#include "drizzled/identifier.h"
 
35
#include <drizzled/identifier.h>
 
36
#include <drizzled/plugin/function.h>
 
37
#include <drizzled/diagnostics_area.h>
 
38
#include <libdrizzle/constants.h>
37
39
 
38
40
#define PROTOCOL_VERSION 10
39
41
 
95
97
ClientMySQLProtocol::ClientMySQLProtocol(int fd, bool using_mysql41_protocol, ProtocolCounters *set_counters):
96
98
  is_admin_connection(false),
97
99
  _using_mysql41_protocol(using_mysql41_protocol),
 
100
  _is_interactive(false),
98
101
  counters(set_counters)
99
102
{
100
103
  
154
157
    drizzleclient_net_close(&net);
155
158
    drizzleclient_net_end(&net);
156
159
    if (is_admin_connection)
 
160
    {
157
161
      counters->adminConnected.decrement();
 
162
    }
158
163
    else
 
164
    {
159
165
      counters->connected.decrement();
 
166
    }
160
167
  }
161
168
}
162
169
 
195
202
  }
196
203
  else
197
204
  {
198
 
    sendError(session->main_da.sql_errno(), session->main_da.message());
 
205
    sendError(session->main_da().sql_errno(), session->main_da().message());
199
206
    counters->failedConnections.increment();
200
207
    return false;
201
208
  }
230
237
 
231
238
    if(net.last_errno== ER_NET_PACKET_TOO_LARGE)
232
239
      my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
233
 
    if (session->main_da.status() == Diagnostics_area::DA_ERROR)
234
 
      sendError(session->main_da.sql_errno(), session->main_da.message());
 
240
    if (session->main_da().status() == Diagnostics_area::DA_ERROR)
 
241
      sendError(session->main_da().sql_errno(), session->main_da().message());
235
242
    else
236
243
      sendOK();
237
244
 
273
280
      (*l_packet)[0]= (unsigned char) COM_SHUTDOWN;
274
281
      break;
275
282
 
 
283
    case 12: /* KILL */
 
284
      (*l_packet)[0]= (unsigned char) COM_KILL;
 
285
      break;
 
286
 
276
287
    case 14: /* PING */
277
288
      (*l_packet)[0]= (unsigned char) COM_PING;
278
289
      break;
332
343
  }
333
344
 
334
345
  buff[0]=0;                    // No fields
335
 
  if (session->main_da.status() == Diagnostics_area::DA_OK)
 
346
  if (session->main_da().status() == Diagnostics_area::DA_OK)
336
347
  {
337
 
    if (client_capabilities & CLIENT_FOUND_ROWS && session->main_da.found_rows())
338
 
      pos=storeLength(buff+1,session->main_da.found_rows());
 
348
    if (client_capabilities & CLIENT_FOUND_ROWS && session->main_da().found_rows())
 
349
      pos=storeLength(buff+1,session->main_da().found_rows());
339
350
    else
340
 
      pos=storeLength(buff+1,session->main_da.affected_rows());
341
 
    pos=storeLength(pos, session->main_da.last_insert_id());
342
 
    int2store(pos, session->main_da.server_status());
 
351
      pos=storeLength(buff+1,session->main_da().affected_rows());
 
352
    pos=storeLength(pos, session->main_da().last_insert_id());
 
353
    int2store(pos, session->main_da().server_status());
343
354
    pos+=2;
344
 
    tmp= min(session->main_da.total_warn_count(), (uint32_t)65535);
345
 
    message= session->main_da.message();
 
355
    tmp= min(session->main_da().total_warn_count(), (uint32_t)65535);
 
356
    message= session->main_da().message();
346
357
  }
347
358
  else
348
359
  {
357
368
  int2store(pos, tmp);
358
369
  pos+= 2;
359
370
 
360
 
  session->main_da.can_overwrite_status= true;
 
371
  session->main_da().can_overwrite_status= true;
361
372
 
362
373
  if (message && message[0])
363
374
  {
369
380
  drizzleclient_net_write(&net, buff, (size_t) (pos-buff));
370
381
  drizzleclient_net_flush(&net);
371
382
 
372
 
  session->main_da.can_overwrite_status= false;
 
383
  session->main_da().can_overwrite_status= false;
373
384
}
374
385
 
375
386
/**
392
403
  /* Set to true if no active vio, to work well in case of --init-file */
393
404
  if (net.vio != 0)
394
405
  {
395
 
    session->main_da.can_overwrite_status= true;
396
 
    writeEOFPacket(session->main_da.server_status(),
397
 
                   session->main_da.total_warn_count());
 
406
    session->main_da().can_overwrite_status= true;
 
407
    writeEOFPacket(session->main_da().server_status(),
 
408
                   session->main_da().total_warn_count());
398
409
    drizzleclient_net_flush(&net);
399
 
    session->main_da.can_overwrite_status= false;
 
410
    session->main_da().can_overwrite_status= false;
400
411
  }
401
412
  packet.shrink(buffer_length.get());
402
413
}
417
428
    It's one case when we can push an error even though there
418
429
    is an OK or EOF already.
419
430
  */
420
 
  session->main_da.can_overwrite_status= true;
 
431
  session->main_da().can_overwrite_status= true;
421
432
 
422
433
  /* Abort multi-result sets */
423
434
  session->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
453
464
 
454
465
  drizzleclient_net_flush(&net);
455
466
 
456
 
  session->main_da.can_overwrite_status= false;
 
467
  session->main_da().can_overwrite_status= false;
457
468
}
458
469
 
459
470
/**
476
487
*/
477
488
bool ClientMySQLProtocol::sendFields(List<Item> *list)
478
489
{
479
 
  List_iterator_fast<Item> it(*list);
 
490
  List<Item>::iterator it(list->begin());
480
491
  Item *item;
481
492
  unsigned char buff[80];
482
493
  String tmp((char*) buff,sizeof(buff),&my_charset_bin);
483
494
 
484
 
  unsigned char *row_pos= storeLength(buff, list->elements);
 
495
  unsigned char *row_pos= storeLength(buff, list->size());
485
496
  (void) drizzleclient_net_write(&net, buff, (size_t) (row_pos-buff));
486
497
 
487
498
  while ((item=it++))
514
525
      switch (field.type)
515
526
      {
516
527
      case DRIZZLE_TYPE_LONG:
517
 
        pos[6]= 3;
 
528
        pos[6]= DRIZZLE_COLUMN_TYPE_LONG;
518
529
        break;
519
530
 
520
531
      case DRIZZLE_TYPE_DOUBLE:
521
 
        pos[6]= 5;
 
532
        pos[6]= DRIZZLE_COLUMN_TYPE_DOUBLE;
522
533
        break;
523
534
 
524
535
      case DRIZZLE_TYPE_NULL:
525
 
        pos[6]= 6;
 
536
        pos[6]= DRIZZLE_COLUMN_TYPE_NULL;
526
537
        break;
527
538
 
528
539
      case DRIZZLE_TYPE_TIMESTAMP:
529
 
        pos[6]= 7;
 
540
        pos[6]= DRIZZLE_COLUMN_TYPE_TIMESTAMP;
530
541
        break;
531
542
 
532
543
      case DRIZZLE_TYPE_LONGLONG:
533
 
        pos[6]= 8;
 
544
        pos[6]= DRIZZLE_COLUMN_TYPE_LONGLONG;
534
545
        break;
535
546
 
536
547
      case DRIZZLE_TYPE_DATETIME:
537
 
        pos[6]= 12;
 
548
        pos[6]= DRIZZLE_COLUMN_TYPE_DATETIME;
538
549
        break;
539
550
 
540
551
      case DRIZZLE_TYPE_TIME:
541
 
        pos[6]= 13;
 
552
        pos[6]= DRIZZLE_COLUMN_TYPE_TIME;
542
553
        break;
543
554
 
544
555
      case DRIZZLE_TYPE_DATE:
545
 
        pos[6]= 14;
 
556
        pos[6]= DRIZZLE_COLUMN_TYPE_DATE;
546
557
        break;
547
558
 
548
559
      case DRIZZLE_TYPE_VARCHAR:
549
 
        pos[6]= 15;
 
560
        pos[6]= DRIZZLE_COLUMN_TYPE_VARCHAR;
550
561
        break;
551
562
 
552
563
      case DRIZZLE_TYPE_MICROTIME:
553
 
        pos[6]= 15;
 
564
        pos[6]= DRIZZLE_COLUMN_TYPE_VARCHAR;
554
565
        break;
555
566
 
556
567
      case DRIZZLE_TYPE_UUID:
557
 
        pos[6]= 15;
 
568
        pos[6]= DRIZZLE_COLUMN_TYPE_VARCHAR;
558
569
        break;
559
570
 
560
571
      case DRIZZLE_TYPE_BOOLEAN:
561
 
        pos[6]= 15;
 
572
        pos[6]= DRIZZLE_COLUMN_TYPE_TINY;
562
573
        break;
563
574
 
564
575
      case DRIZZLE_TYPE_DECIMAL:
565
 
        pos[6]= (char)246;
 
576
        pos[6]= (char)DRIZZLE_COLUMN_TYPE_NEWDECIMAL;
566
577
        break;
567
578
 
568
579
      case DRIZZLE_TYPE_ENUM:
569
 
        pos[6]= (char)247;
 
580
        pos[6]= (char)DRIZZLE_COLUMN_TYPE_ENUM;
570
581
        break;
571
582
 
572
583
      case DRIZZLE_TYPE_BLOB:
573
 
        pos[6]= (char)252;
 
584
        pos[6]= (char)DRIZZLE_COLUMN_TYPE_BLOB;
574
585
        break;
575
586
      }
576
587
    }
609
620
{
610
621
  if (from->is_null())
611
622
    return store();
 
623
  if (from->type() == DRIZZLE_TYPE_BOOLEAN)
 
624
  {
 
625
    return store(from->val_int());
 
626
  }
 
627
 
612
628
  char buff[MAX_FIELD_WIDTH];
613
629
  String str(buff,sizeof(buff), &my_charset_bin);
614
630
 
710
726
    server_capabilites= CLIENT_BASIC_FLAGS;
711
727
 
712
728
    if (_using_mysql41_protocol)
 
729
    {
713
730
      server_capabilites|= CLIENT_PROTOCOL_MYSQL41;
 
731
    }
714
732
 
715
733
#ifdef HAVE_COMPRESS
716
734
    server_capabilites|= CLIENT_COMPRESS;
801
819
      passwd < (char *) net.read_pos + pkt_len)
802
820
  {
803
821
    passwd_len= (unsigned char)(*passwd++);
804
 
    if (passwd_len > 0)
 
822
    if (passwd_len > 0 and client_capabilities & CLIENT_CAPABILITIES_PLUGIN_AUTH)
 
823
    {
 
824
      user_identifier->setPasswordType(identifier::User::PLAIN_TEXT);
 
825
    }
 
826
    else if (passwd_len > 0)
805
827
    {
806
828
      user_identifier->setPasswordType(identifier::User::MYSQL_HASH);
807
829
      user_identifier->setPasswordContext(scramble, SCRAMBLE_LENGTH);
852
874
    }
853
875
  }
854
876
 
 
877
  if (client_capabilities & CLIENT_INTERACTIVE)
 
878
  {
 
879
    _is_interactive= true;
 
880
  }
 
881
 
 
882
  if (client_capabilities & CLIENT_CAPABILITIES_PLUGIN_AUTH)
 
883
  {
 
884
    passwd_len= strlen(passwd);
 
885
  }
 
886
 
855
887
  user_identifier->setUser(user);
856
888
  session->setUser(user_identifier);
857
889
 
1034
1066
          po::value<buffer_constraint>(&buffer_length)->default_value(16384),
1035
1067
          _("Buffer length."));
1036
1068
  context("bind-address",
1037
 
          po::value<string>()->default_value(""),
 
1069
          po::value<string>()->default_value("localhost"),
1038
1070
          _("Address to bind to."));
1039
1071
  context("max-connections",
1040
1072
          po::value<uint32_t>(&ListenMySQLProtocol::mysql_counters->max_connections)->default_value(1000),