~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/protocol.cc

  • Committer: Jim Winstead
  • Date: 2008-07-19 02:56:45 UTC
  • mto: (202.1.8 codestyle)
  • mto: This revision was merged to the branch mainline in revision 207.
  • Revision ID: jimw@mysql.com-20080719025645-w2pwytebgzusjzjb
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
Temporarily disables tab-completion in the drizzle client until an appropriate
autoconf check can be added/enabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
  Low level functions for storing data to be send to the MySQL client.
20
20
  The actual communction is handled by the net_xxx functions in net_serv.cc
21
21
*/
22
 
#include <drizzled/server_includes.h>
23
 
#include <drizzled/drizzled_error_messages.h>
24
 
#include <drizzled/sql_state.h>
 
22
 
 
23
#ifdef USE_PRAGMA_IMPLEMENTATION
 
24
#pragma implementation                          // gcc: Class implementation
 
25
#endif
 
26
 
 
27
#include "mysql_priv.h"
 
28
#include <stdarg.h>
25
29
 
26
30
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
27
31
/* Declared non-static only because of the embedded library. */
28
 
static void net_send_error_packet(THD *thd, uint32_t sql_errno, const char *err);
 
32
void net_send_error_packet(THD *thd, uint sql_errno, const char *err);
 
33
void net_send_ok(THD *, uint, uint, ha_rows, uint64_t, const char *);
 
34
void net_send_eof(THD *thd, uint server_status, uint total_warn_count);
29
35
static void write_eof_packet(THD *thd, NET *net,
30
 
                             uint32_t server_status, uint32_t total_warn_count);
 
36
                             uint server_status, uint total_warn_count);
31
37
 
32
 
bool Protocol::net_store_data(const unsigned char *from, size_t length)
 
38
bool Protocol::net_store_data(const uchar *from, size_t length)
33
39
{
34
40
  ulong packet_length=packet->length();
35
41
  /* 
39
45
  if (packet_length+9+length > packet->alloced_length() &&
40
46
      packet->realloc(packet_length+9+length))
41
47
    return 1;
42
 
  unsigned char *to= net_store_length((unsigned char*) packet->ptr()+packet_length, length);
 
48
  uchar *to= net_store_length((uchar*) packet->ptr()+packet_length, length);
43
49
  memcpy(to,from,length);
44
 
  packet->length((uint) (to+length-(unsigned char*) packet->ptr()));
 
50
  packet->length((uint) (to+length-(uchar*) packet->ptr()));
45
51
  return 0;
46
52
}
47
53
 
60
66
  because column, table, database names fit into this limit.
61
67
*/
62
68
 
63
 
bool Protocol::net_store_data(const unsigned char *from, size_t length,
64
 
                              const CHARSET_INFO * const from_cs,
65
 
                                                          const CHARSET_INFO * const to_cs)
 
69
bool Protocol::net_store_data(const uchar *from, size_t length,
 
70
                              CHARSET_INFO *from_cs, CHARSET_INFO *to_cs)
66
71
{
67
 
  uint32_t dummy_errors;
 
72
  uint dummy_errors;
68
73
  /* Calculate maxumum possible result length */
69
 
  uint32_t conv_length= to_cs->mbmaxlen * length / from_cs->mbminlen;
 
74
  uint conv_length= to_cs->mbmaxlen * length / from_cs->mbminlen;
70
75
  if (conv_length > 250)
71
76
  {
72
77
    /*
82
87
    */
83
88
    return (convert->copy((const char*) from, length, from_cs,
84
89
                          to_cs, &dummy_errors) ||
85
 
            net_store_data((const unsigned char*) convert->ptr(), convert->length()));
 
90
            net_store_data((const uchar*) convert->ptr(), convert->length()));
86
91
  }
87
92
 
88
93
  ulong packet_length= packet->length();
97
102
  to+= copy_and_convert(to, conv_length, to_cs,
98
103
                        (const char*) from, length, from_cs, &dummy_errors);
99
104
 
100
 
  net_store_length((unsigned char*) length_pos, to - length_pos - 1);
 
105
  net_store_length((uchar*) length_pos, to - length_pos - 1);
101
106
  packet->length((uint) (to - packet->ptr()));
102
107
  return 0;
103
108
}
115
120
  critical that every error that can be intercepted is issued in one
116
121
  place only, my_message_sql.
117
122
*/
118
 
void net_send_error(THD *thd, uint32_t sql_errno, const char *err)
 
123
void net_send_error(THD *thd, uint sql_errno, const char *err)
119
124
{
120
125
  assert(sql_errno);
121
126
  assert(err && err[0]);
132
137
  net_send_error_packet(thd, sql_errno, err);
133
138
 
134
139
  thd->main_da.can_overwrite_status= false;
 
140
 
 
141
  return;
135
142
}
136
143
 
137
144
/**
155
162
  @param message           Message to send to the client (Used by mysql_status)
156
163
*/
157
164
 
158
 
static void
 
165
void
159
166
net_send_ok(THD *thd,
160
 
            uint32_t server_status, uint32_t total_warn_count,
 
167
            uint server_status, uint total_warn_count,
161
168
            ha_rows affected_rows, uint64_t id, const char *message)
162
169
{
163
170
  NET *net= &thd->net;
164
 
  unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
 
171
  uchar buff[MYSQL_ERRMSG_SIZE+10],*pos;
165
172
 
166
173
  if (! net->vio)       // hack for re-parsing queries
167
174
  {
171
178
  buff[0]=0;                                    // No fields
172
179
  pos=net_store_length(buff+1,affected_rows);
173
180
  pos=net_store_length(pos, id);
174
 
 
175
 
  int2store(pos, server_status);
176
 
  pos+=2;
177
 
 
178
 
  /* We can only return up to 65535 warnings in two bytes */
179
 
  uint32_t tmp= cmin(total_warn_count, (uint)65535);
180
 
  int2store(pos, tmp);
181
 
  pos+= 2;
182
 
 
 
181
  if (thd->client_capabilities & CLIENT_PROTOCOL_41)
 
182
  {
 
183
    int2store(pos, server_status);
 
184
    pos+=2;
 
185
 
 
186
    /* We can only return up to 65535 warnings in two bytes */
 
187
    uint tmp= min(total_warn_count, 65535);
 
188
    int2store(pos, tmp);
 
189
    pos+= 2;
 
190
  }
 
191
  else if (net->return_status)                  // For 4.0 protocol
 
192
  {
 
193
    int2store(pos, server_status);
 
194
    pos+=2;
 
195
  }
183
196
  thd->main_da.can_overwrite_status= true;
184
197
 
185
198
  if (message && message[0])
186
 
    pos= net_store_data(pos, (unsigned char*) message, strlen(message));
187
 
  my_net_write(net, buff, (size_t) (pos-buff));
188
 
  net_flush(net);
 
199
    pos= net_store_data(pos, (uchar*) message, strlen(message));
 
200
  VOID(my_net_write(net, buff, (size_t) (pos-buff)));
 
201
  VOID(net_flush(net));
189
202
 
190
203
  thd->main_da.can_overwrite_status= false;
 
204
 
 
205
  return;
191
206
}
192
207
 
 
208
static uchar eof_buff[1]= { (uchar) 254 };      /* Marker for end of fields */
 
209
 
193
210
/**
194
211
  Send eof (= end of result set) to the client.
195
212
 
196
213
  The eof packet has the following structure:
197
214
 
198
 
  - 254 (DRIZZLE_PROTOCOL_NO_MORE_DATA) : Marker (1 byte)
 
215
  - 254         : Marker (1 byte)
199
216
  - warning_count       : Stored in 2 bytes; New in 4.1 protocol
200
217
  - status_flag : Stored in 2 bytes;
201
218
  For flags like SERVER_MORE_RESULTS_EXISTS.
209
226
                    like in send_fields().
210
227
*/    
211
228
 
212
 
static void
213
 
net_send_eof(THD *thd, uint32_t server_status, uint32_t total_warn_count)
 
229
void
 
230
net_send_eof(THD *thd, uint server_status, uint total_warn_count)
214
231
{
215
232
  NET *net= &thd->net;
216
233
  /* Set to true if no active vio, to work well in case of --init-file */
218
235
  {
219
236
    thd->main_da.can_overwrite_status= true;
220
237
    write_eof_packet(thd, net, server_status, total_warn_count);
221
 
    net_flush(net);
 
238
    VOID(net_flush(net));
222
239
    thd->main_da.can_overwrite_status= false;
223
240
  }
 
241
  return;
224
242
}
225
243
 
226
244
 
230
248
*/
231
249
 
232
250
static void write_eof_packet(THD *thd, NET *net,
233
 
                             uint32_t server_status,
234
 
                             uint32_t total_warn_count)
 
251
                             uint server_status,
 
252
                             uint total_warn_count)
235
253
{
236
 
  unsigned char buff[5];
237
 
  /*
238
 
    Don't send warn count during SP execution, as the warn_list
239
 
    is cleared between substatements, and mysqltest gets confused
240
 
  */
241
 
  uint32_t tmp= cmin(total_warn_count, (uint)65535);
242
 
  buff[0]= DRIZZLE_PROTOCOL_NO_MORE_DATA;
243
 
  int2store(buff+1, tmp);
244
 
  /*
245
 
    The following test should never be true, but it's better to do it
246
 
    because if 'is_fatal_error' is set the server is not going to execute
247
 
    other queries (see the if test in dispatch_command / COM_QUERY)
248
 
  */
249
 
  if (thd->is_fatal_error)
250
 
    server_status&= ~SERVER_MORE_RESULTS_EXISTS;
251
 
  int2store(buff + 3, server_status);
252
 
  my_net_write(net, buff, 5);
 
254
  if (thd->client_capabilities & CLIENT_PROTOCOL_41)
 
255
  {
 
256
    uchar buff[5];
 
257
    /*
 
258
      Don't send warn count during SP execution, as the warn_list
 
259
      is cleared between substatements, and mysqltest gets confused
 
260
    */
 
261
    uint tmp= min(total_warn_count, 65535);
 
262
    buff[0]= 254;
 
263
    int2store(buff+1, tmp);
 
264
    /*
 
265
      The following test should never be true, but it's better to do it
 
266
      because if 'is_fatal_error' is set the server is not going to execute
 
267
      other queries (see the if test in dispatch_command / COM_QUERY)
 
268
    */
 
269
    if (thd->is_fatal_error)
 
270
      server_status&= ~SERVER_MORE_RESULTS_EXISTS;
 
271
    int2store(buff + 3, server_status);
 
272
    VOID(my_net_write(net, buff, 5));
 
273
  }
 
274
  else
 
275
    VOID(my_net_write(net, eof_buff, 1));
253
276
}
254
277
 
255
 
void net_send_error_packet(THD *thd, uint32_t sql_errno, const char *err)
 
278
void net_send_error_packet(THD *thd, uint sql_errno, const char *err)
256
279
{
257
280
  NET *net= &thd->net;
258
 
  uint32_t length;
 
281
  uint length;
259
282
  /*
260
 
    buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + DRIZZLE_ERRMSG_SIZE:512
 
283
    buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + MYSQL_ERRMSG_SIZE:512
261
284
  */
262
 
  unsigned char buff[2+1+SQLSTATE_LENGTH+DRIZZLE_ERRMSG_SIZE], *pos;
 
285
  uchar buff[2+1+SQLSTATE_LENGTH+MYSQL_ERRMSG_SIZE], *pos;
263
286
 
264
287
  if (net->vio == 0)
265
288
  {
268
291
 
269
292
  int2store(buff,sql_errno);
270
293
  pos= buff+2;
271
 
 
272
 
  /* The first # is to make the protocol backward compatible */
273
 
  buff[2]= '#';
274
 
  pos= (unsigned char*) my_stpcpy((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
275
 
 
276
 
  length= (uint) (strmake((char*) pos, err, DRIZZLE_ERRMSG_SIZE-1) -
 
294
  if (thd->client_capabilities & CLIENT_PROTOCOL_41)
 
295
  {
 
296
    /* The first # is to make the protocol backward compatible */
 
297
    buff[2]= '#';
 
298
    pos= (uchar*) strmov((char*) buff+3, mysql_errno_to_sqlstate(sql_errno));
 
299
  }
 
300
  length= (uint) (strmake((char*) pos, err, MYSQL_ERRMSG_SIZE-1) -
277
301
                  (char*) buff);
278
302
  err= (char*) buff;
279
303
 
280
 
  net_write_command(net,(unsigned char) 255, (unsigned char*) "", 0, (unsigned char*) err, length);
 
304
  VOID(net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) err,
 
305
                         length));
281
306
  return;
282
307
}
283
308
 
287
312
  We keep a separate version for that range because it's widely used in
288
313
  libmysql.
289
314
 
290
 
  uint32_t is used as agrument type because of MySQL type conventions:
291
 
  - uint32_t for 0..65536
 
315
  uint is used as agrument type because of MySQL type conventions:
 
316
  - uint for 0..65536
292
317
  - ulong for 0..4294967296
293
318
  - uint64_t for bigger numbers.
294
319
*/
295
320
 
296
 
static unsigned char *net_store_length_fast(unsigned char *packet, uint32_t length)
 
321
static uchar *net_store_length_fast(uchar *packet, uint length)
297
322
{
298
323
  if (length < 251)
299
324
  {
300
 
    *packet=(unsigned char) length;
 
325
    *packet=(uchar) length;
301
326
    return packet+1;
302
327
  }
303
328
  *packet++=252;
403
428
 
404
429
/* The following will only be used for short strings < 65K */
405
430
 
406
 
unsigned char *net_store_data(unsigned char *to, const unsigned char *from, size_t length)
 
431
uchar *net_store_data(uchar *to, const uchar *from, size_t length)
407
432
{
408
433
  to=net_store_length_fast(to,length);
409
434
  memcpy(to,from,length);
410
435
  return to+length;
411
436
}
412
437
 
413
 
unsigned char *net_store_data(unsigned char *to,int32_t from)
 
438
uchar *net_store_data(uchar *to,int32 from)
414
439
{
415
440
  char buff[20];
416
 
  uint32_t length=(uint) (int10_to_str(from,buff,10)-buff);
 
441
  uint length=(uint) (int10_to_str(from,buff,10)-buff);
417
442
  to=net_store_length_fast(to,length);
418
443
  memcpy(to,buff,length);
419
444
  return to+length;
420
445
}
421
446
 
422
 
unsigned char *net_store_data(unsigned char *to,int64_t from)
 
447
uchar *net_store_data(uchar *to,int64_t from)
423
448
{
424
449
  char buff[22];
425
 
  uint32_t length=(uint) (int64_t10_to_str(from,buff,10)-buff);
 
450
  uint length=(uint) (int64_t10_to_str(from,buff,10)-buff);
426
451
  to=net_store_length_fast(to,length);
427
452
  memcpy(to,buff,length);
428
453
  return to+length;
476
501
    1   Error  (Note that in this case the error is not sent to the
477
502
    client)
478
503
*/
479
 
bool Protocol::send_fields(List<Item> *list, uint32_t flags)
 
504
bool Protocol::send_fields(List<Item> *list, uint flags)
480
505
{
481
506
  List_iterator_fast<Item> it(*list);
482
507
  Item *item;
483
 
  unsigned char buff[80];
 
508
  uchar buff[80];
484
509
  String tmp((char*) buff,sizeof(buff),&my_charset_bin);
485
510
  Protocol_text prot(thd);
486
511
  String *local_packet= prot.storage_packet();
487
 
  const CHARSET_INFO * const thd_charset= thd->variables.character_set_results;
 
512
  CHARSET_INFO *thd_charset= thd->variables.character_set_results;
488
513
 
489
514
  if (flags & SEND_NUM_ROWS)
490
515
  {                             // Packet with number of elements
491
 
    unsigned char *pos= net_store_length(buff, list->elements);
 
516
    uchar *pos= net_store_length(buff, list->elements);
492
517
    (void) my_net_write(&thd->net, buff, (size_t) (pos-buff));
493
518
  }
494
519
 
495
520
  while ((item=it++))
496
521
  {
497
522
    char *pos;
498
 
    const CHARSET_INFO * const cs= system_charset_info;
 
523
    CHARSET_INFO *cs= system_charset_info;
499
524
    Send_field field;
500
525
    item->make_field(&field);
501
526
 
502
527
    prot.prepare_for_resend();
503
528
 
504
 
 
505
 
    if (prot.store(STRING_WITH_LEN("def"), cs, thd_charset) ||
506
 
        prot.store(field.db_name, (uint) strlen(field.db_name),
507
 
                   cs, thd_charset) ||
508
 
        prot.store(field.table_name, (uint) strlen(field.table_name),
509
 
                   cs, thd_charset) ||
510
 
        prot.store(field.org_table_name, (uint) strlen(field.org_table_name),
511
 
                   cs, thd_charset) ||
512
 
        prot.store(field.col_name, (uint) strlen(field.col_name),
513
 
                   cs, thd_charset) ||
514
 
        prot.store(field.org_col_name, (uint) strlen(field.org_col_name),
515
 
                   cs, thd_charset) ||
516
 
        local_packet->realloc(local_packet->length()+12))
517
 
      goto err;
518
 
 
519
 
    /* Store fixed length fields */
520
 
    pos= (char*) local_packet->ptr()+local_packet->length();
521
 
    *pos++= 12;                         // Length of packed fields
522
 
    if (item->collation.collation == &my_charset_bin || thd_charset == NULL)
 
529
    if (thd->client_capabilities & CLIENT_PROTOCOL_41)
523
530
    {
524
 
      /* No conversion */
525
 
      int2store(pos, field.charsetnr);
526
 
      int4store(pos+2, field.length);
 
531
      if (prot.store(STRING_WITH_LEN("def"), cs, thd_charset) ||
 
532
          prot.store(field.db_name, (uint) strlen(field.db_name),
 
533
                     cs, thd_charset) ||
 
534
          prot.store(field.table_name, (uint) strlen(field.table_name),
 
535
                     cs, thd_charset) ||
 
536
          prot.store(field.org_table_name, (uint) strlen(field.org_table_name),
 
537
                     cs, thd_charset) ||
 
538
          prot.store(field.col_name, (uint) strlen(field.col_name),
 
539
                     cs, thd_charset) ||
 
540
          prot.store(field.org_col_name, (uint) strlen(field.org_col_name),
 
541
                     cs, thd_charset) ||
 
542
          local_packet->realloc(local_packet->length()+12))
 
543
        goto err;
 
544
      /* Store fixed length fields */
 
545
      pos= (char*) local_packet->ptr()+local_packet->length();
 
546
      *pos++= 12;                               // Length of packed fields
 
547
      if (item->collation.collation == &my_charset_bin || thd_charset == NULL)
 
548
      {
 
549
        /* No conversion */
 
550
        int2store(pos, field.charsetnr);
 
551
        int4store(pos+2, field.length);
 
552
      }
 
553
      else
 
554
      {
 
555
        /* With conversion */
 
556
        uint max_char_len;
 
557
        int2store(pos, thd_charset->number);
 
558
        /*
 
559
          For TEXT/BLOB columns, field_length describes the maximum data
 
560
          length in bytes. There is no limit to the number of characters
 
561
          that a TEXT column can store, as long as the data fits into
 
562
          the designated space.
 
563
          For the rest of textual columns, field_length is evaluated as
 
564
          char_count * mbmaxlen, where character count is taken from the
 
565
          definition of the column. In other words, the maximum number
 
566
          of characters here is limited by the column definition.
 
567
        */
 
568
        max_char_len= field.length / item->collation.collation->mbmaxlen;
 
569
        int4store(pos+2, max_char_len * thd_charset->mbmaxlen);
 
570
      }
 
571
      pos[6]= field.type;
 
572
      int2store(pos+7,field.flags);
 
573
      pos[9]= (char) field.decimals;
 
574
      pos[10]= 0;                               // For the future
 
575
      pos[11]= 0;                               // For the future
 
576
      pos+= 12;
527
577
    }
528
578
    else
529
579
    {
530
 
      /* With conversion */
531
 
      uint32_t max_char_len;
532
 
      int2store(pos, thd_charset->number);
533
 
      /*
534
 
        For TEXT/BLOB columns, field_length describes the maximum data
535
 
        length in bytes. There is no limit to the number of characters
536
 
        that a TEXT column can store, as long as the data fits into
537
 
        the designated space.
538
 
        For the rest of textual columns, field_length is evaluated as
539
 
        char_count * mbmaxlen, where character count is taken from the
540
 
        definition of the column. In other words, the maximum number
541
 
        of characters here is limited by the column definition.
542
 
      */
543
 
      max_char_len= field.length / item->collation.collation->mbmaxlen;
544
 
      int4store(pos+2, max_char_len * thd_charset->mbmaxlen);
 
580
      if (prot.store(field.table_name, (uint) strlen(field.table_name),
 
581
                     cs, thd_charset) ||
 
582
          prot.store(field.col_name, (uint) strlen(field.col_name),
 
583
                     cs, thd_charset) ||
 
584
          local_packet->realloc(local_packet->length()+10))
 
585
        goto err;
 
586
      pos= (char*) local_packet->ptr()+local_packet->length();
 
587
 
 
588
        pos[0]=3;
 
589
        int3store(pos+1,field.length);
 
590
        pos[4]=1;
 
591
        pos[5]=field.type;
 
592
        pos[6]=3;
 
593
        int2store(pos+7,field.flags);
 
594
        pos[9]= (char) field.decimals;
 
595
        pos+= 10;
545
596
    }
546
 
    pos[6]= field.type;
547
 
    int2store(pos+7,field.flags);
548
 
    pos[9]= (char) field.decimals;
549
 
    pos[10]= 0;                         // For the future
550
 
    pos[11]= 0;                         // For the future
551
 
    pos+= 12;
552
 
 
553
597
    local_packet->length((uint) (pos - local_packet->ptr()));
554
598
    if (flags & SEND_DEFAULTS)
555
599
      item->send(&prot, &tmp);                  // Send default value
577
621
 
578
622
bool Protocol::write()
579
623
{
580
 
  return(my_net_write(&thd->net, (unsigned char*) packet->ptr(),
 
624
  return(my_net_write(&thd->net, (uchar*) packet->ptr(),
581
625
                           packet->length()));
582
626
}
583
627
 
585
629
/**
586
630
  Send \\0 end terminated string.
587
631
 
588
 
  @param from   NULL or \\0 terminated string
 
632
  @param from   NullS or \\0 terminated string
589
633
 
590
634
  @note
591
635
    In most cases one should use store(from, length) instead of this function
596
640
    1           error
597
641
*/
598
642
 
599
 
bool Protocol::store(const char *from, const CHARSET_INFO * const cs)
 
643
bool Protocol::store(const char *from, CHARSET_INFO *cs)
600
644
{
601
645
  if (!from)
602
646
    return store_null();
603
 
  uint32_t length= strlen(from);
 
647
  uint length= strlen(from);
604
648
  return store(from, length, cs);
605
649
}
606
650
 
613
657
{
614
658
  char buf[256];
615
659
  String tmp(buf, sizeof(buf), &my_charset_bin);
616
 
  uint32_t len;
 
660
  uint32 len;
617
661
  I_List_iterator<i_string> it(*str_list);
618
662
  i_string* s;
619
663
 
656
700
*/
657
701
 
658
702
bool Protocol::store_string_aux(const char *from, size_t length,
659
 
                                const CHARSET_INFO * const fromcs,
660
 
                                                                const CHARSET_INFO * const tocs)
 
703
                                CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
661
704
{
662
705
  /* 'tocs' is set 0 when client issues SET character_set_results=NULL */
663
706
  if (tocs && !my_charset_same(fromcs, tocs) &&
665
708
      tocs != &my_charset_bin)
666
709
  {
667
710
    /* Store with conversion */
668
 
    return net_store_data((unsigned char*) from, length, fromcs, tocs);
 
711
    return net_store_data((uchar*) from, length, fromcs, tocs);
669
712
  }
670
713
  /* Store without conversion */
671
 
  return net_store_data((unsigned char*) from, length);
 
714
  return net_store_data((uchar*) from, length);
672
715
}
673
716
 
674
717
 
675
718
bool Protocol_text::store(const char *from, size_t length,
676
 
                          const CHARSET_INFO * const fromcs,
677
 
                                                  const CHARSET_INFO * const tocs)
 
719
                          CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
678
720
{
679
721
  return store_string_aux(from, length, fromcs, tocs);
680
722
}
681
723
 
682
724
 
683
725
bool Protocol_text::store(const char *from, size_t length,
684
 
                          const CHARSET_INFO * const fromcs)
 
726
                          CHARSET_INFO *fromcs)
685
727
{
686
 
  const CHARSET_INFO * const tocs= this->thd->variables.character_set_results;
 
728
  CHARSET_INFO *tocs= this->thd->variables.character_set_results;
687
729
  return store_string_aux(from, length, fromcs, tocs);
688
730
}
689
731
 
691
733
bool Protocol_text::store_tiny(int64_t from)
692
734
{
693
735
  char buff[20];
694
 
  return net_store_data((unsigned char*) buff,
 
736
  return net_store_data((uchar*) buff,
695
737
                        (size_t) (int10_to_str((int) from, buff, -10) - buff));
696
738
}
697
739
 
699
741
bool Protocol_text::store_short(int64_t from)
700
742
{
701
743
  char buff[20];
702
 
  return net_store_data((unsigned char*) buff,
 
744
  return net_store_data((uchar*) buff,
703
745
                        (size_t) (int10_to_str((int) from, buff, -10) -
704
746
                                  buff));
705
747
}
708
750
bool Protocol_text::store_long(int64_t from)
709
751
{
710
752
  char buff[20];
711
 
  return net_store_data((unsigned char*) buff,
 
753
  return net_store_data((uchar*) buff,
712
754
                        (size_t) (int10_to_str((long int)from, buff,
713
755
                                               (from <0)?-10:10)-buff));
714
756
}
717
759
bool Protocol_text::store_int64_t(int64_t from, bool unsigned_flag)
718
760
{
719
761
  char buff[22];
720
 
  return net_store_data((unsigned char*) buff,
 
762
  return net_store_data((uchar*) buff,
721
763
                        (size_t) (int64_t10_to_str(from,buff,
722
764
                                                    unsigned_flag ? 10 : -10)-
723
765
                                  buff));
729
771
  char buff[DECIMAL_MAX_STR_LENGTH];
730
772
  String str(buff, sizeof(buff), &my_charset_bin);
731
773
  (void) my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
732
 
  return net_store_data((unsigned char*) str.ptr(), str.length());
 
774
  return net_store_data((uchar*) str.ptr(), str.length());
733
775
}
734
776
 
735
777
 
736
 
bool Protocol_text::store(float from, uint32_t decimals, String *buffer)
 
778
bool Protocol_text::store(float from, uint32 decimals, String *buffer)
737
779
{
738
780
  buffer->set_real((double) from, decimals, thd->charset());
739
 
  return net_store_data((unsigned char*) buffer->ptr(), buffer->length());
 
781
  return net_store_data((uchar*) buffer->ptr(), buffer->length());
740
782
}
741
783
 
742
784
 
743
 
bool Protocol_text::store(double from, uint32_t decimals, String *buffer)
 
785
bool Protocol_text::store(double from, uint32 decimals, String *buffer)
744
786
{
745
787
  buffer->set_real(from, decimals, thd->charset());
746
 
  return net_store_data((unsigned char*) buffer->ptr(), buffer->length());
 
788
  return net_store_data((uchar*) buffer->ptr(), buffer->length());
747
789
}
748
790
 
749
791
 
753
795
    return store_null();
754
796
  char buff[MAX_FIELD_WIDTH];
755
797
  String str(buff,sizeof(buff), &my_charset_bin);
756
 
  const CHARSET_INFO * const tocs= this->thd->variables.character_set_results;
 
798
  CHARSET_INFO *tocs= this->thd->variables.character_set_results;
757
799
 
758
800
  field->val_str(&str);
759
801
 
767
809
    we support 0-6 decimals for time.
768
810
*/
769
811
 
770
 
bool Protocol_text::store(DRIZZLE_TIME *tm)
 
812
bool Protocol_text::store(MYSQL_TIME *tm)
771
813
{
772
814
  char buff[40];
773
 
  uint32_t length;
 
815
  uint length;
774
816
  length= sprintf(buff, "%04d-%02d-%02d %02d:%02d:%02d",
775
817
                           (int) tm->year,
776
818
                           (int) tm->month,
781
823
  if (tm->second_part)
782
824
    length+= sprintf(buff+length, ".%06d",
783
825
                                     (int)tm->second_part);
784
 
  return net_store_data((unsigned char*) buff, length);
 
826
  return net_store_data((uchar*) buff, length);
785
827
}
786
828
 
787
829
 
788
 
bool Protocol_text::store_date(DRIZZLE_TIME *tm)
 
830
bool Protocol_text::store_date(MYSQL_TIME *tm)
789
831
{
790
832
  char buff[MAX_DATE_STRING_REP_LENGTH];
791
833
  size_t length= my_date_to_str(tm, buff);
792
 
  return net_store_data((unsigned char*) buff, length);
 
834
  return net_store_data((uchar*) buff, length);
793
835
}
794
836
 
795
837
 
799
841
    we support 0-6 decimals for time.
800
842
*/
801
843
 
802
 
bool Protocol_text::store_time(DRIZZLE_TIME *tm)
 
844
bool Protocol_text::store_time(MYSQL_TIME *tm)
803
845
{
804
846
  char buff[40];
805
 
  uint32_t length;
806
 
  uint32_t day= (tm->year || tm->month) ? 0 : tm->day;
 
847
  uint length;
 
848
  uint day= (tm->year || tm->month) ? 0 : tm->day;
807
849
  length= sprintf(buff, "%s%02ld:%02d:%02d",
808
850
                           tm->neg ? "-" : "",
809
851
                           (long) day*24L+(long) tm->hour,
811
853
                           (int) tm->second);
812
854
  if (tm->second_part)
813
855
    length+= sprintf(buff+length, ".%06d", (int)tm->second_part);
814
 
  return net_store_data((unsigned char*) buff, length);
 
856
  return net_store_data((uchar*) buff, length);
815
857
}
816
858