~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/oldlibdrizzle/oldlibdrizzle.cc

Finished store() cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
198
198
  @param message       Message to send to the client (Used by mysql_status)
199
199
*/
200
200
 
201
 
#if 0
202
 
void ProtocolOldLibdrizzle::sendOK(uint32_t server_status,
203
 
                                       uint32_t total_warn_count,
204
 
            ha_rows affected_rows, uint64_t id, const char *message)
205
 
{
206
 
  unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
207
 
 
208
 
  if (!net->vio)    // hack for re-parsing queries
209
 
  {
210
 
    return;
211
 
  }
212
 
 
213
 
  buff[0]=0;                    // No fields
214
 
  pos=drizzleclient_net_store_length(buff+1,affected_rows);
215
 
  pos=drizzleclient_net_store_length(pos, id);
216
 
  int2store(pos, server_status);
217
 
  pos+=2;
218
 
 
219
 
  /* We can only return up to 65535 warnings in two bytes */
220
 
  uint32_t tmp= cmin(total_warn_count, (uint32_t)65535);
221
 
  int2store(pos, tmp);
222
 
  pos+= 2;
223
 
 
224
 
  session->main_da.can_overwrite_status= true;
225
 
 
226
 
  if (message && message[0])
227
 
  {
228
 
    size_t length= strlen(message);
229
 
    pos=drizzleclient_net_store_length(pos,length);
230
 
    memcpy(pos,(unsigned char*) message,length);
231
 
    pos+=length;
232
 
  }
233
 
  drizzleclient_net_write(net, buff, (size_t) (pos-buff));
234
 
  drizzleclient_net_flush(net);
235
 
 
236
 
  session->main_da.can_overwrite_status= false;
237
 
}
238
 
#endif
239
201
void ProtocolOldLibdrizzle::sendOK()
240
202
{
241
203
  unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
298
260
  Note that the warning count will not be sent if 'no_flush' is set as
299
261
  we don't want to report the warning count until all data is sent to the
300
262
  client.
301
 
 
302
 
  @param session        Thread handler
303
 
  @param no_flush    Set to 1 if there will be more data to the client,
304
 
                    like in send_fields().
305
263
*/
306
264
 
307
 
#if 0
308
 
void ProtocolOldLibdrizzle::sendEOF(uint32_t server_status, uint32_t total_warn_count)
309
 
{
310
 
  /* Set to true if no active vio, to work well in case of --init-file */
311
 
  if (net.vio != 0)
312
 
  {
313
 
    session->main_da.can_overwrite_status= true;
314
 
    write_eof_packet(session, net, server_status, total_warn_count);
315
 
    drizzleclient_net_flush(net);
316
 
    session->main_da.can_overwrite_status= false;
317
 
  }
318
 
}
319
 
#endif
320
265
void ProtocolOldLibdrizzle::sendEOF()
321
266
{
322
267
  /* Set to true if no active vio, to work well in case of --init-file */
459
404
  unsigned char buff[80];
460
405
  String tmp((char*) buff,sizeof(buff),&my_charset_bin);
461
406
  String *local_packet= storage_packet();
462
 
  const CHARSET_INFO * const session_charset= default_charset_info;
463
407
 
464
408
  if (flags & SEND_NUM_ROWS)
465
409
  {                // Packet with number of elements
477
421
    prepare_for_resend();
478
422
 
479
423
 
480
 
    if (store(STRING_WITH_LEN("def"), cs, session_charset) ||
481
 
        store(field.db_name, (uint32_t) strlen(field.db_name),
482
 
                   cs, session_charset) ||
483
 
        store(field.table_name, (uint32_t) strlen(field.table_name),
484
 
                   cs, session_charset) ||
485
 
        store(field.org_table_name, (uint32_t) strlen(field.org_table_name),
486
 
                   cs, session_charset) ||
487
 
        store(field.col_name, (uint32_t) strlen(field.col_name),
488
 
                   cs, session_charset) ||
489
 
        store(field.org_col_name, (uint32_t) strlen(field.org_col_name),
490
 
                   cs, session_charset) ||
 
424
    if (store(STRING_WITH_LEN("def"), cs) ||
 
425
        store(field.db_name, cs) ||
 
426
        store(field.table_name, cs) ||
 
427
        store(field.org_table_name, cs) ||
 
428
        store(field.col_name, cs) ||
 
429
        store(field.org_col_name, cs) ||
491
430
        local_packet->realloc(local_packet->length()+12))
492
431
      goto err;
493
432
 
494
433
    /* Store fixed length fields */
495
434
    pos= (char*) local_packet->ptr()+local_packet->length();
496
435
    *pos++= 12;                // Length of packed fields
497
 
    if (item->collation.collation == &my_charset_bin || session_charset == NULL)
 
436
    if (item->collation.collation == &my_charset_bin)
498
437
    {
499
438
      /* No conversion */
500
439
      int2store(pos, field.charsetnr);
504
443
    {
505
444
      /* With conversion */
506
445
      uint32_t max_char_len;
507
 
      int2store(pos, session_charset->number);
 
446
      int2store(pos, cs->number);
508
447
      /*
509
448
        For TEXT/BLOB columns, field_length describes the maximum data
510
449
        length in bytes. There is no limit to the number of characters
516
455
        of characters here is limited by the column definition.
517
456
      */
518
457
      max_char_len= field.length / item->collation.collation->mbmaxlen;
519
 
      int4store(pos+2, max_char_len * session_charset->mbmaxlen);
 
458
      int4store(pos+2, max_char_len * cs->mbmaxlen);
520
459
    }
521
460
    pos[6]= field.type;
522
461
    int2store(pos+7,field.flags);
556
495
                           packet->length()));
557
496
}
558
497
 
559
 
 
560
 
/**
561
 
  Send \\0 end terminated string.
562
 
 
563
 
  @param from    NULL or \\0 terminated string
564
 
 
565
 
  @note
566
 
    In most cases one should use store(from, length) instead of this function
567
 
 
568
 
  @retval
569
 
    0        ok
570
 
  @retval
571
 
    1        error
572
 
*/
573
 
 
574
 
bool ProtocolOldLibdrizzle::store(const char *from, const CHARSET_INFO * const cs)
575
 
{
576
 
  if (!from)
577
 
    return store();
578
 
  uint32_t length= strlen(from);
579
 
  return store(from, length, cs);
580
 
}
581
 
 
582
 
 
583
 
/**
584
 
  Send a set of strings as one long string with ',' in between.
585
 
*/
586
 
 
587
 
bool ProtocolOldLibdrizzle::store(I_List<i_string>* str_list)
588
 
{
589
 
  char buf[256];
590
 
  String tmp(buf, sizeof(buf), &my_charset_bin);
591
 
  uint32_t len;
592
 
  I_List_iterator<i_string> it(*str_list);
593
 
  i_string* s;
594
 
 
595
 
  tmp.length(0);
596
 
  while ((s=it++))
597
 
  {
598
 
    tmp.append(s->ptr);
599
 
    tmp.append(',');
600
 
  }
601
 
  if ((len= tmp.length()))
602
 
    len--;                    // Remove last ','
603
 
  return store((char*) tmp.ptr(), len,  tmp.charset());
604
 
}
605
 
 
606
 
 
607
 
bool ProtocolOldLibdrizzle::store(String *str)
608
 
{
609
 
  return store((char*) str->ptr(), str->length(), str->charset());
610
 
}
611
 
 
612
498
void ProtocolOldLibdrizzle::free()
613
499
{
614
500
  packet->free();
774
660
 
775
661
 
776
662
bool ProtocolOldLibdrizzle::store(const char *from, size_t length,
777
 
                          const CHARSET_INFO * const fromcs,
778
 
                          const CHARSET_INFO * const tocs)
779
 
{
780
 
  return storeStringAux(from, length, fromcs, tocs);
781
 
}
782
 
 
783
 
 
784
 
bool ProtocolOldLibdrizzle::store(const char *from, size_t length,
785
663
                          const CHARSET_INFO * const fromcs)
786
664
{
787
665
  const CHARSET_INFO * const tocs= default_charset_info;
818
696
}
819
697
 
820
698
 
821
 
bool ProtocolOldLibdrizzle::store_decimal(const my_decimal *d)
822
 
{
823
 
  char buff[DECIMAL_MAX_STR_LENGTH];
824
 
  String str(buff, sizeof(buff), &my_charset_bin);
825
 
  (void) my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
826
 
  return netStoreData((unsigned char*) str.ptr(), str.length());
827
 
}
828
 
 
829
 
 
830
 
bool ProtocolOldLibdrizzle::store(float from, uint32_t decimals, String *buffer)
831
 
{
832
 
  buffer->set_real((double) from, decimals, session->charset());
833
 
  return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
834
 
}
835
 
 
836
 
 
837
699
bool ProtocolOldLibdrizzle::store(double from, uint32_t decimals, String *buffer)
838
700
{
839
701
  buffer->set_real(from, decimals, session->charset());
841
703
}
842
704
 
843
705
 
844
 
bool ProtocolOldLibdrizzle::store(Field *field)
 
706
bool ProtocolOldLibdrizzle::store(Field *from)
845
707
{
846
 
  if (field->is_null())
 
708
  if (from->is_null())
847
709
    return store();
848
710
  char buff[MAX_FIELD_WIDTH];
849
711
  String str(buff,sizeof(buff), &my_charset_bin);
850
712
  const CHARSET_INFO * const tocs= default_charset_info;
851
713
 
852
 
  field->val_str(&str);
 
714
  from->val_str(&str);
853
715
 
854
716
  return storeStringAux(str.ptr(), str.length(), str.charset(), tocs);
855
717
}
861
723
    we support 0-6 decimals for time.
862
724
*/
863
725
 
864
 
bool ProtocolOldLibdrizzle::store(DRIZZLE_TIME *tm)
 
726
bool ProtocolOldLibdrizzle::store(const DRIZZLE_TIME *tm)
865
727
{
866
728
  char buff[40];
867
729
  uint32_t length;