~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/protocol.cc

Started abstracting Protocol, removed init_connect, init_file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
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
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 */
15
19
 
16
20
/**
17
21
  @file
19
23
  Low level functions for storing data to be send to the MySQL client.
20
24
  The actual communction is handled by the net_xxx functions in net_serv.cc
21
25
*/
 
26
 
22
27
#include <drizzled/server_includes.h>
23
28
#include <drizzled/error.h>
24
29
#include <drizzled/sql_state.h>
53
58
static void write_eof_packet(Session *session, NET *net,
54
59
                             uint32_t server_status, uint32_t total_warn_count);
55
60
 
56
 
bool Protocol::io_ok()
 
61
bool Protocol_libdrizzleclient::isConnected()
57
62
{
58
63
  return net.vio != 0;
59
64
}
60
65
 
61
 
void Protocol::set_read_timeout(uint32_t timeout)
 
66
void Protocol_libdrizzleclient::set_read_timeout(uint32_t timeout)
62
67
{
63
68
  drizzleclient_net_set_read_timeout(&net, timeout);
64
69
}
65
70
 
66
 
void Protocol::set_write_timeout(uint32_t timeout)
 
71
void Protocol_libdrizzleclient::set_write_timeout(uint32_t timeout)
67
72
{
68
73
  drizzleclient_net_set_write_timeout(&net, timeout);
69
74
}
70
75
 
71
 
void Protocol::set_retry_count(uint32_t count)
 
76
void Protocol_libdrizzleclient::set_retry_count(uint32_t count)
72
77
{
73
78
  net.retry_count=count;
74
79
}
75
80
 
76
 
void Protocol::set_error(char error)
 
81
void Protocol_libdrizzleclient::set_error(char error)
77
82
{
78
83
  net.error= error;
79
84
}
80
85
 
81
 
bool Protocol::have_error(void)
 
86
bool Protocol_libdrizzleclient::have_error(void)
82
87
{
83
88
  return net.error || net.vio == 0;
84
89
}
85
90
 
86
 
bool Protocol::was_aborted(void)
 
91
bool Protocol_libdrizzleclient::was_aborted(void)
87
92
{
88
93
  return net.error && net.vio != 0;
89
94
}
90
95
 
91
 
bool Protocol::have_more_data(void)
 
96
bool Protocol_libdrizzleclient::have_more_data(void)
92
97
{
93
98
  return drizzleclient_net_more_data(&net);
94
99
}
95
100
 
96
 
bool Protocol::have_compression(void)
 
101
bool Protocol_libdrizzleclient::have_compression(void)
97
102
{
98
103
  return net.compress;
99
104
}
100
105
 
101
 
void Protocol::enable_compression(void)
 
106
void Protocol_libdrizzleclient::enable_compression(void)
102
107
{
103
108
  net.compress= true;
104
109
}
105
110
 
106
 
bool Protocol::is_reading(void)
 
111
bool Protocol_libdrizzleclient::is_reading(void)
107
112
{
108
113
  return net.reading_or_writing == 1;
109
114
}
110
115
 
111
 
bool Protocol::is_writing(void)
 
116
bool Protocol_libdrizzleclient::is_writing(void)
112
117
{
113
118
  return net.reading_or_writing == 2;
114
119
}
115
120
 
116
 
/*
117
 
 * To disable results we set net.vio to 0.
118
 
 */
119
 
 
120
 
void Protocol::disable_results(void)
121
 
{
122
 
  save_vio= net.vio;
123
 
  net.vio= 0;
124
 
}
125
 
 
126
 
void Protocol::enable_results(void)
127
 
{
128
 
  net.vio= save_vio;
129
 
}
130
 
 
131
 
 
132
 
bool Protocol::net_store_data(const unsigned char *from, size_t length)
 
121
bool Protocol_libdrizzleclient::netStoreData(const unsigned char *from, size_t length)
133
122
{
134
123
  size_t packet_length= packet->length();
135
124
  /*
149
138
 
150
139
 
151
140
/*
152
 
  net_store_data() - extended version with character set conversion.
 
141
  netStoreData() - extended version with character set conversion.
153
142
 
154
143
  It is optimized for short strings whose length after
155
144
  conversion is garanteed to be less than 251, which accupies
160
149
  because column, table, database names fit into this limit.
161
150
*/
162
151
 
163
 
bool Protocol::net_store_data(const unsigned char *from, size_t length,
 
152
bool Protocol_libdrizzleclient::netStoreData(const unsigned char *from, size_t length,
164
153
                              const CHARSET_INFO * const from_cs,
165
154
                                                          const CHARSET_INFO * const to_cs)
166
155
{
182
171
    */
183
172
    return (convert->copy((const char*) from, length, from_cs,
184
173
                          to_cs, &dummy_errors) ||
185
 
            net_store_data((const unsigned char*) convert->ptr(), convert->length()));
 
174
            netStoreData((const unsigned char*) convert->ptr(), convert->length()));
186
175
  }
187
176
 
188
177
  size_t packet_length= packet->length();
224
213
  @param message           Message to send to the client (Used by mysql_status)
225
214
*/
226
215
 
227
 
static void
228
 
net_send_ok(Session *session, NET *net,
229
 
            uint32_t server_status, uint32_t total_warn_count,
 
216
#if 0
 
217
void Protocol_libdrizzleclient::sendOK(uint32_t server_status,
 
218
                                       uint32_t total_warn_count,
230
219
            ha_rows affected_rows, uint64_t id, const char *message)
231
220
{
232
221
  unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
239
228
  buff[0]=0;                                    // No fields
240
229
  pos=drizzleclient_net_store_length(buff+1,affected_rows);
241
230
  pos=drizzleclient_net_store_length(pos, id);
242
 
 
243
231
  int2store(pos, server_status);
244
232
  pos+=2;
245
233
 
262
250
 
263
251
  session->main_da.can_overwrite_status= false;
264
252
}
 
253
#endif
 
254
void Protocol_libdrizzleclient::sendOK()
 
255
{
 
256
  unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
 
257
  const char *message= NULL;
 
258
  uint32_t tmp;
 
259
 
 
260
  if (!net.vio) // hack for re-parsing queries
 
261
  {
 
262
    return;
 
263
  }
 
264
 
 
265
  buff[0]=0;                                    // No fields
 
266
  if (session->main_da.status() == Diagnostics_area::DA_OK)
 
267
  {
 
268
    pos=drizzleclient_net_store_length(buff+1,session->main_da.affected_rows());
 
269
    pos=drizzleclient_net_store_length(pos, session->main_da.last_insert_id());
 
270
    int2store(pos, session->main_da.server_status());
 
271
    pos+=2;
 
272
    tmp= cmin(session->main_da.total_warn_count(), (uint32_t)65535);
 
273
    message= session->main_da.message();
 
274
  }
 
275
  else
 
276
  {
 
277
    pos=drizzleclient_net_store_length(buff+1,0);
 
278
    pos=drizzleclient_net_store_length(pos, 0);
 
279
    int2store(pos, session->server_status);
 
280
    pos+=2;
 
281
    tmp= cmin(session->total_warn_count, (uint32_t)65535);
 
282
  }
 
283
 
 
284
  /* We can only return up to 65535 warnings in two bytes */
 
285
  int2store(pos, tmp);
 
286
  pos+= 2;
 
287
 
 
288
  session->main_da.can_overwrite_status= true;
 
289
 
 
290
  if (message && message[0])
 
291
  {
 
292
    size_t length= strlen(message);
 
293
    pos=drizzleclient_net_store_length(pos,length);
 
294
    memcpy(pos,(unsigned char*) message,length);
 
295
    pos+=length;
 
296
  }
 
297
  drizzleclient_net_write(&net, buff, (size_t) (pos-buff));
 
298
  drizzleclient_net_flush(&net);
 
299
 
 
300
  session->main_da.can_overwrite_status= false;
 
301
}
265
302
 
266
303
/**
267
304
  Send eof (= end of result set) to the client.
282
319
                    like in send_fields().
283
320
*/
284
321
 
285
 
static void
286
 
net_send_eof(Session *session, NET *net, uint32_t server_status, uint32_t total_warn_count)
 
322
#if 0
 
323
void Protocol_libdrizzleclient::sendEOF(uint32_t server_status, uint32_t total_warn_count)
287
324
{
288
325
  /* Set to true if no active vio, to work well in case of --init-file */
289
 
  if (net->vio != 0)
 
326
  if (net.vio != 0)
290
327
  {
291
328
    session->main_da.can_overwrite_status= true;
292
329
    write_eof_packet(session, net, server_status, total_warn_count);
294
331
    session->main_da.can_overwrite_status= false;
295
332
  }
296
333
}
 
334
#endif
 
335
void Protocol_libdrizzleclient::sendEOF()
 
336
{
 
337
  /* Set to true if no active vio, to work well in case of --init-file */
 
338
  if (net.vio != 0)
 
339
  {
 
340
    session->main_da.can_overwrite_status= true;
 
341
    write_eof_packet(session, &net, session->main_da.server_status(),
 
342
                     session->main_da.total_warn_count());
 
343
    drizzleclient_net_flush(&net);
 
344
    session->main_da.can_overwrite_status= false;
 
345
  }
 
346
}
297
347
 
298
348
 
299
349
/**
324
374
  drizzleclient_net_write(net, buff, 5);
325
375
}
326
376
 
327
 
void Protocol_text::send_error_packet(uint32_t sql_errno, const char *err)
 
377
void Protocol_libdrizzleclient::sendErrorPacket(uint32_t sql_errno, const char *err)
328
378
{
329
379
  uint32_t length;
330
380
  /*
367
417
  critical that every error that can be intercepted is issued in one
368
418
  place only, my_message_sql.
369
419
*/
370
 
void Protocol_text::send_error(uint32_t sql_errno, const char *err)
 
420
void Protocol_libdrizzleclient::sendError(uint32_t sql_errno, const char *err)
371
421
{
372
422
  assert(sql_errno);
373
423
  assert(err && err[0]);
381
431
  /* Abort multi-result sets */
382
432
  session->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
383
433
 
384
 
  send_error_packet(sql_errno, err);
 
434
  sendErrorPacket(sql_errno, err);
385
435
 
386
436
  session->main_da.can_overwrite_status= false;
387
437
}
388
438
 
389
 
 
390
 
/**
391
 
  Send the status of the current statement execution over network.
392
 
 
393
 
  @param  session   in fact, carries two parameters, NET for the transport and
394
 
                Diagnostics_area as the source of status information.
395
 
 
396
 
  In MySQL, there are two types of SQL statements: those that return
397
 
  a result set and those that return status information only.
398
 
 
399
 
  If a statement returns a result set, it consists of 3 parts:
400
 
  - result set meta-data
401
 
  - variable number of result set rows (can be 0)
402
 
  - followed and terminated by EOF or ERROR packet
403
 
 
404
 
  Once the  client has seen the meta-data information, it always
405
 
  expects an EOF or ERROR to terminate the result set. If ERROR is
406
 
  received, the result set rows are normally discarded (this is up
407
 
  to the client implementation, libmysql at least does discard them).
408
 
  EOF, on the contrary, means "successfully evaluated the entire
409
 
  result set". Since we don't know how many rows belong to a result
410
 
  set until it's evaluated, EOF/ERROR is the indicator of the end
411
 
  of the row stream. Note, that we can not buffer result set rows
412
 
  on the server -- there may be an arbitrary number of rows. But
413
 
  we do buffer the last packet (EOF/ERROR) in the Diagnostics_area and
414
 
  delay sending it till the very end of execution (here), to be able to
415
 
  change EOF to an ERROR if commit failed or some other error occurred
416
 
  during the last cleanup steps taken after execution.
417
 
 
418
 
  A statement that does not return a result set doesn't send result
419
 
  set meta-data either. Instead it returns one of:
420
 
  - OK packet
421
 
  - ERROR packet.
422
 
  Similarly to the EOF/ERROR of the previous statement type, OK/ERROR
423
 
  packet is "buffered" in the diagnostics area and sent to the client
424
 
  in the end of statement.
425
 
 
426
 
  @pre  The diagnostics area is assigned or disabled. It can not be empty
427
 
        -- we assume that every SQL statement or COM_* command
428
 
        generates OK, ERROR, or EOF status.
429
 
 
430
 
  @post The status information is encoded to protocol format and sent to the
431
 
        client.
432
 
 
433
 
  @return We conventionally return void, since the only type of error
434
 
          that can happen here is a NET (transport) error, and that one
435
 
          will become visible when we attempt to read from the NET the
436
 
          next command.
437
 
          Diagnostics_area::is_sent is set for debugging purposes only.
438
 
*/
439
 
 
440
 
void Protocol::end_statement()
441
 
{
442
 
  assert(! session->main_da.is_sent);
443
 
 
444
 
  /* Can not be true, but do not take chances in production. */
445
 
  if (session->main_da.is_sent)
446
 
    return;
447
 
 
448
 
  switch (session->main_da.status()) {
449
 
  case Diagnostics_area::DA_ERROR:
450
 
    /* The query failed, send error to log and abort bootstrap. */
451
 
    send_error(session->main_da.sql_errno(),
452
 
               session->main_da.message());
453
 
    break;
454
 
  case Diagnostics_area::DA_EOF:
455
 
    net_send_eof(session, &net,
456
 
                 session->main_da.server_status(),
457
 
                 session->main_da.total_warn_count());
458
 
    break;
459
 
  case Diagnostics_area::DA_OK:
460
 
    net_send_ok(session, &net,
461
 
                session->main_da.server_status(),
462
 
                session->main_da.total_warn_count(),
463
 
                session->main_da.affected_rows(),
464
 
                session->main_da.last_insert_id(),
465
 
                session->main_da.message());
466
 
    break;
467
 
  case Diagnostics_area::DA_DISABLED:
468
 
    break;
469
 
  case Diagnostics_area::DA_EMPTY:
470
 
  default:
471
 
    //TODO: Something is being masked here by commenting this out
472
 
    //  assert(0);
473
 
    net_send_ok(session, &net, session->server_status, session->total_warn_count,
474
 
                0, 0, NULL);
475
 
    break;
476
 
  }
477
 
  session->main_da.is_sent= true;
478
 
}
479
 
 
480
 
 
481
439
/*****************************************************************************
482
440
  Default Protocol functions
483
441
*****************************************************************************/
484
442
 
485
 
void Protocol::init(Session *session_arg)
486
 
{
487
 
  session=session_arg;
 
443
Protocol_libdrizzleclient::Protocol_libdrizzleclient()
 
444
{
 
445
  scramble[0]= 0;
 
446
  net.vio= 0;
 
447
}
 
448
 
 
449
void Protocol_libdrizzleclient::setSession(Session *session_arg)
 
450
{
 
451
  session= session_arg;
488
452
  packet= &session->packet;
489
453
  convert= &session->convert_buffer;
490
 
  net.vio= 0;
491
454
}
492
455
 
493
 
 
494
 
bool Protocol::flush()
 
456
bool Protocol_libdrizzleclient::flush()
495
457
{
496
458
  return drizzleclient_net_flush(&net);
497
459
}
515
477
    1   Error  (Note that in this case the error is not sent to the
516
478
    client)
517
479
*/
518
 
bool Protocol::send_fields(List<Item> *list, uint32_t flags)
 
480
bool Protocol_libdrizzleclient::send_fields(List<Item> *list, uint32_t flags)
519
481
{
520
482
  List_iterator_fast<Item> it(*list);
521
483
  Item *item;
613
575
}
614
576
 
615
577
 
616
 
bool Protocol::write()
 
578
bool Protocol_libdrizzleclient::write()
617
579
{
618
580
  return(drizzleclient_net_write(&net, (unsigned char*) packet->ptr(),
619
581
                           packet->length()));
634
596
    1           error
635
597
*/
636
598
 
637
 
bool Protocol::store(const char *from, const CHARSET_INFO * const cs)
 
599
bool Protocol_libdrizzleclient::store(const char *from, const CHARSET_INFO * const cs)
638
600
{
639
601
  if (!from)
640
602
    return store_null();
647
609
  Send a set of strings as one long string with ',' in between.
648
610
*/
649
611
 
650
 
bool Protocol::store(I_List<i_string>* str_list)
 
612
bool Protocol_libdrizzleclient::store(I_List<i_string>* str_list)
651
613
{
652
614
  char buf[256];
653
615
  String tmp(buf, sizeof(buf), &my_charset_bin);
667
629
}
668
630
 
669
631
 
670
 
bool Protocol::store(String *str)
 
632
bool Protocol_libdrizzleclient::store(String *str)
671
633
{
672
634
  return store((char*) str->ptr(), str->length(), str->charset());
673
635
}
674
636
 
675
 
void Protocol::free()
 
637
void Protocol_libdrizzleclient::free()
676
638
{
677
639
  packet->free();
678
640
}
686
648
  All data are sent as 'packed-string-length' followed by 'string-data'
687
649
****************************************************************************/
688
650
 
689
 
void Protocol_text::init_random(uint64_t seed1, uint64_t seed2)
 
651
void Protocol_libdrizzleclient::init_random(uint64_t seed1, uint64_t seed2)
690
652
{
691
 
  drizzleclient_randominit(&_rand, seed1, seed2);
 
653
  drizzleclient_randominit(&rand, seed1, seed2);
692
654
}
693
655
 
694
 
bool Protocol_text::init_file_descriptor(int fd)
 
656
bool Protocol_libdrizzleclient::init_file_descriptor(int fd)
695
657
{
696
658
  if (drizzleclient_net_init_sock(&net, fd, 0))
697
659
    return true;
698
660
  return false;
699
661
}
700
662
 
701
 
int Protocol_text::file_descriptor(void)
 
663
int Protocol_libdrizzleclient::file_descriptor(void)
702
664
{
703
665
  return drizzleclient_net_get_sd(&net);
704
666
}
705
667
 
706
 
bool Protocol_text::authenticate()
 
668
bool Protocol_libdrizzleclient::authenticate()
707
669
{
708
670
  bool connection_is_valid;
709
671
 
711
673
  drizzleclient_net_set_read_timeout(&net, connect_timeout);
712
674
  drizzleclient_net_set_write_timeout(&net, connect_timeout);
713
675
 
714
 
  connection_is_valid= _check_connection();
715
 
  end_statement();
 
676
  connection_is_valid= checkConnection();
716
677
 
717
 
  if (!connection_is_valid)
 
678
  if (connection_is_valid)
 
679
    sendOK();
 
680
  else
 
681
  {
 
682
    sendError(session->main_da.sql_errno(), session->main_da.message());
718
683
    return false;
 
684
  }
719
685
 
720
686
  /* Connect completed, set read/write timeouts back to default */
721
687
  drizzleclient_net_set_read_timeout(&net,
725
691
  return true;
726
692
}
727
693
 
728
 
bool Protocol_text::read_command(char **l_packet, uint32_t *packet_length)
 
694
bool Protocol_libdrizzleclient::read_command(char **l_packet, uint32_t *packet_length)
729
695
{
730
696
  /*
731
697
    This thread will do a blocking read from the client which
736
702
  drizzleclient_net_set_read_timeout(&net,
737
703
                                     session->variables.net_wait_timeout);
738
704
 
739
 
  /*
740
 
    XXX: this code is here only to clear possible errors of init_connect.
741
 
    Consider moving to init_connect() instead.
742
 
  */
743
 
  session->clear_error();                    // Clear error message
744
 
  session->main_da.reset_diagnostics_area();
745
 
 
746
705
  net.pkt_nr=0;
747
706
 
748
707
  *packet_length= drizzleclient_net_read(&net);
752
711
 
753
712
    if(net.last_errno== CR_NET_PACKET_TOO_LARGE)
754
713
      my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
755
 
    /* Assert is invalid for dirty connection shutdown
756
 
     *     assert(session->is_error());
757
 
     */
758
 
    end_statement();
 
714
    if (session->main_da.status() == Diagnostics_area::DA_ERROR)
 
715
      sendError(session->main_da.sql_errno(), session->main_da.message());
 
716
    else
 
717
      session->protocol->sendOK();
759
718
 
760
719
    if (net.error != 3)
761
720
      return false;                       // We have to close it.
792
751
  return true;
793
752
}
794
753
 
795
 
void Protocol_text::close(void)
 
754
void Protocol_libdrizzleclient::close(void)
796
755
{
797
756
  if (net.vio)
798
757
  { 
801
760
  }
802
761
}
803
762
 
804
 
void Protocol_text::prepare_for_resend()
 
763
void Protocol_libdrizzleclient::prepare_for_resend()
805
764
{
806
765
  packet->length(0);
807
766
}
808
767
 
809
 
bool Protocol_text::store_null()
 
768
bool Protocol_libdrizzleclient::store_null()
810
769
{
811
770
  char buff[1];
812
771
  buff[0]= (char)251;
819
778
  and store in network buffer.
820
779
*/
821
780
 
822
 
bool Protocol::store_string_aux(const char *from, size_t length,
 
781
bool Protocol_libdrizzleclient::storeStringAux(const char *from, size_t length,
823
782
                                const CHARSET_INFO * const fromcs,
824
783
                                                                const CHARSET_INFO * const tocs)
825
784
{
829
788
      tocs != &my_charset_bin)
830
789
  {
831
790
    /* Store with conversion */
832
 
    return net_store_data((unsigned char*) from, length, fromcs, tocs);
 
791
    return netStoreData((unsigned char*) from, length, fromcs, tocs);
833
792
  }
834
793
  /* Store without conversion */
835
 
  return net_store_data((unsigned char*) from, length);
 
794
  return netStoreData((unsigned char*) from, length);
836
795
}
837
796
 
838
797
 
839
 
bool Protocol_text::store(const char *from, size_t length,
 
798
bool Protocol_libdrizzleclient::store(const char *from, size_t length,
840
799
                          const CHARSET_INFO * const fromcs,
841
800
                                                  const CHARSET_INFO * const tocs)
842
801
{
843
 
  return store_string_aux(from, length, fromcs, tocs);
 
802
  return storeStringAux(from, length, fromcs, tocs);
844
803
}
845
804
 
846
805
 
847
 
bool Protocol_text::store(const char *from, size_t length,
 
806
bool Protocol_libdrizzleclient::store(const char *from, size_t length,
848
807
                          const CHARSET_INFO * const fromcs)
849
808
{
850
809
  const CHARSET_INFO * const tocs= default_charset_info;
851
 
  return store_string_aux(from, length, fromcs, tocs);
 
810
  return storeStringAux(from, length, fromcs, tocs);
852
811
}
853
812
 
854
813
 
855
 
bool Protocol_text::store_tiny(int64_t from)
 
814
bool Protocol_libdrizzleclient::store_tiny(int64_t from)
856
815
{
857
816
  char buff[20];
858
 
  return net_store_data((unsigned char*) buff,
 
817
  return netStoreData((unsigned char*) buff,
859
818
                        (size_t) (int10_to_str((int) from, buff, -10) - buff));
860
819
}
861
820
 
862
821
 
863
 
bool Protocol_text::store_short(int64_t from)
 
822
bool Protocol_libdrizzleclient::store_short(int64_t from)
864
823
{
865
824
  char buff[20];
866
 
  return net_store_data((unsigned char*) buff,
 
825
  return netStoreData((unsigned char*) buff,
867
826
                        (size_t) (int10_to_str((int) from, buff, -10) -
868
827
                                  buff));
869
828
}
870
829
 
871
830
 
872
 
bool Protocol_text::store_long(int64_t from)
 
831
bool Protocol_libdrizzleclient::store_long(int64_t from)
873
832
{
874
833
  char buff[20];
875
 
  return net_store_data((unsigned char*) buff,
 
834
  return netStoreData((unsigned char*) buff,
876
835
                        (size_t) (int10_to_str((long int)from, buff,
877
836
                                               (from <0)?-10:10)-buff));
878
837
}
879
838
 
880
839
 
881
 
bool Protocol_text::store_int64_t(int64_t from, bool unsigned_flag)
 
840
bool Protocol_libdrizzleclient::store_int64_t(int64_t from, bool unsigned_flag)
882
841
{
883
842
  char buff[22];
884
 
  return net_store_data((unsigned char*) buff,
 
843
  return netStoreData((unsigned char*) buff,
885
844
                        (size_t) (int64_t10_to_str(from,buff,
886
845
                                                    unsigned_flag ? 10 : -10)-
887
846
                                  buff));
888
847
}
889
848
 
890
849
 
891
 
bool Protocol_text::store_decimal(const my_decimal *d)
 
850
bool Protocol_libdrizzleclient::store_decimal(const my_decimal *d)
892
851
{
893
852
  char buff[DECIMAL_MAX_STR_LENGTH];
894
853
  String str(buff, sizeof(buff), &my_charset_bin);
895
854
  (void) my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
896
 
  return net_store_data((unsigned char*) str.ptr(), str.length());
 
855
  return netStoreData((unsigned char*) str.ptr(), str.length());
897
856
}
898
857
 
899
858
 
900
 
bool Protocol_text::store(float from, uint32_t decimals, String *buffer)
 
859
bool Protocol_libdrizzleclient::store(float from, uint32_t decimals, String *buffer)
901
860
{
902
861
  buffer->set_real((double) from, decimals, session->charset());
903
 
  return net_store_data((unsigned char*) buffer->ptr(), buffer->length());
 
862
  return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
904
863
}
905
864
 
906
865
 
907
 
bool Protocol_text::store(double from, uint32_t decimals, String *buffer)
 
866
bool Protocol_libdrizzleclient::store(double from, uint32_t decimals, String *buffer)
908
867
{
909
868
  buffer->set_real(from, decimals, session->charset());
910
 
  return net_store_data((unsigned char*) buffer->ptr(), buffer->length());
 
869
  return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
911
870
}
912
871
 
913
872
 
914
 
bool Protocol_text::store(Field *field)
 
873
bool Protocol_libdrizzleclient::store(Field *field)
915
874
{
916
875
  if (field->is_null())
917
876
    return store_null();
921
880
 
922
881
  field->val_str(&str);
923
882
 
924
 
  return store_string_aux(str.ptr(), str.length(), str.charset(), tocs);
 
883
  return storeStringAux(str.ptr(), str.length(), str.charset(), tocs);
925
884
}
926
885
 
927
886
 
931
890
    we support 0-6 decimals for time.
932
891
*/
933
892
 
934
 
bool Protocol_text::store(DRIZZLE_TIME *tm)
 
893
bool Protocol_libdrizzleclient::store(DRIZZLE_TIME *tm)
935
894
{
936
895
  char buff[40];
937
896
  uint32_t length;
945
904
  if (tm->second_part)
946
905
    length+= sprintf(buff+length, ".%06d",
947
906
                                     (int)tm->second_part);
948
 
  return net_store_data((unsigned char*) buff, length);
 
907
  return netStoreData((unsigned char*) buff, length);
949
908
}
950
909
 
951
910
 
952
 
bool Protocol_text::store_date(DRIZZLE_TIME *tm)
 
911
bool Protocol_libdrizzleclient::store_date(DRIZZLE_TIME *tm)
953
912
{
954
913
  char buff[MAX_DATE_STRING_REP_LENGTH];
955
914
  size_t length= my_date_to_str(tm, buff);
956
 
  return net_store_data((unsigned char*) buff, length);
 
915
  return netStoreData((unsigned char*) buff, length);
957
916
}
958
917
 
959
918
 
963
922
    we support 0-6 decimals for time.
964
923
*/
965
924
 
966
 
bool Protocol_text::store_time(DRIZZLE_TIME *tm)
 
925
bool Protocol_libdrizzleclient::store_time(DRIZZLE_TIME *tm)
967
926
{
968
927
  char buff[40];
969
928
  uint32_t length;
975
934
                           (int) tm->second);
976
935
  if (tm->second_part)
977
936
    length+= sprintf(buff+length, ".%06d", (int)tm->second_part);
978
 
  return net_store_data((unsigned char*) buff, length);
 
937
  return netStoreData((unsigned char*) buff, length);
979
938
}
980
939
 
981
 
bool Protocol_text::_check_connection(void)
 
940
bool Protocol_libdrizzleclient::checkConnection(void)
982
941
{
983
942
  uint32_t pkt_len= 0;
984
943
  char *end;
1022
981
      procedure, scramble is set here. This gives us new scramble for
1023
982
      each handshake.
1024
983
    */
1025
 
    drizzleclient_create_random_string(_scramble, SCRAMBLE_LENGTH, &_rand);
 
984
    drizzleclient_create_random_string(scramble, SCRAMBLE_LENGTH, &rand);
1026
985
    /*
1027
986
      Old clients does not understand long scrambles, but can ignore packet
1028
987
      tail: that's why first part of the scramble is placed here, and second
1029
988
      part at the end of packet.
1030
989
    */
1031
 
    end= strncpy(end, _scramble, SCRAMBLE_LENGTH_323);
 
990
    end= strncpy(end, scramble, SCRAMBLE_LENGTH_323);
1032
991
    end+= SCRAMBLE_LENGTH_323;
1033
992
 
1034
993
    *end++= 0; /* an empty byte for some reason */
1041
1000
    end+= 18;
1042
1001
    /* write scramble tail */
1043
1002
    size_t scramble_len= SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323;
1044
 
    end= strncpy(end, _scramble + SCRAMBLE_LENGTH_323, scramble_len);
 
1003
    end= strncpy(end, scramble + SCRAMBLE_LENGTH_323, scramble_len);
1045
1004
    end+= scramble_len;
1046
1005
 
1047
1006
    *end++= 0; /* an empty byte for some reason */