~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*/
26
26
 
27
27
#include <drizzled/server_includes.h>
 
28
#include <drizzled/error.h>
28
29
 
29
30
static void do_field_eq(Copy_field *copy)
30
31
{
370
371
{                                               // Shorter string field
371
372
  int well_formed_error;
372
373
  const CHARSET_INFO * const cs= copy->from_field->charset();
373
 
  const uchar *from_end= copy->from_ptr + copy->from_length;
374
 
  uint copy_length= cs->cset->well_formed_len(cs,
 
374
  const unsigned char *from_end= copy->from_ptr + copy->from_length;
 
375
  uint32_t copy_length= cs->cset->well_formed_len(cs,
375
376
                                              (char*) copy->from_ptr,
376
377
                                              (char*) from_end, 
377
378
                                              copy->to_length / cs->mbmaxlen,
419
420
 
420
421
static void do_varstring1(Copy_field *copy)
421
422
{
422
 
  uint length= (uint) *(uchar*) copy->from_ptr;
 
423
  uint32_t length= (uint) *(unsigned char*) copy->from_ptr;
423
424
  if (length > copy->to_length- 1)
424
425
  {
425
426
    length=copy->to_length - 1;
427
428
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
428
429
                                  ER_WARN_DATA_TRUNCATED, 1);
429
430
  }
430
 
  *(uchar*) copy->to_ptr= (uchar) length;
 
431
  *(unsigned char*) copy->to_ptr= (unsigned char) length;
431
432
  memcpy(copy->to_ptr+1, copy->from_ptr + 1, length);
432
433
}
433
434
 
436
437
{
437
438
  int well_formed_error;
438
439
  const CHARSET_INFO * const cs= copy->from_field->charset();
439
 
  uint from_length= (uint) *(uchar*) copy->from_ptr;
440
 
  const uchar *from_ptr= copy->from_ptr + 1;
441
 
  uint to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
442
 
  uint length= cs->cset->well_formed_len(cs, (char*) from_ptr,
 
440
  uint32_t from_length= (uint) *(unsigned char*) copy->from_ptr;
 
441
  const unsigned char *from_ptr= copy->from_ptr + 1;
 
442
  uint32_t to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
 
443
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_ptr,
443
444
                                         (char*) from_ptr + from_length,
444
445
                                         to_char_length, &well_formed_error);
445
446
  if (length < from_length)
446
447
  {
447
 
    if (current_thd->count_cuted_fields)
 
448
    if (current_session->count_cuted_fields)
448
449
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
449
450
                                  ER_WARN_DATA_TRUNCATED, 1);
450
451
  }
451
 
  *copy->to_ptr= (uchar) length;
 
452
  *copy->to_ptr= (unsigned char) length;
452
453
  memcpy(copy->to_ptr + 1, from_ptr, length);
453
454
}
454
455
 
455
456
 
456
457
static void do_varstring2(Copy_field *copy)
457
458
{
458
 
  uint length=uint2korr(copy->from_ptr);
 
459
  uint32_t length=uint2korr(copy->from_ptr);
459
460
  if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
460
461
  {
461
462
    length=copy->to_length-HA_KEY_BLOB_LENGTH;
473
474
{
474
475
  int well_formed_error;
475
476
  const CHARSET_INFO * const cs= copy->from_field->charset();
476
 
  uint char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
477
 
  uint from_length= uint2korr(copy->from_ptr);
478
 
  const uchar *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
479
 
  uint length= cs->cset->well_formed_len(cs, (char*) from_beg,
 
477
  uint32_t char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
 
478
  uint32_t from_length= uint2korr(copy->from_ptr);
 
479
  const unsigned char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
 
480
  uint32_t length= cs->cset->well_formed_len(cs, (char*) from_beg,
480
481
                                         (char*) from_beg + from_length,
481
482
                                         char_length, &well_formed_error);
482
483
  if (length < from_length)
483
484
  {
484
 
    if (current_thd->count_cuted_fields)
 
485
    if (current_session->count_cuted_fields)
485
486
      copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
486
487
                                  ER_WARN_DATA_TRUNCATED, 1);
487
488
  }  
502
503
  The 'to' buffer should have a size of field->pack_length()+1
503
504
*/
504
505
 
505
 
void Copy_field::set(uchar *to,Field *from)
 
506
void Copy_field::set(unsigned char *to,Field *from)
506
507
{
507
508
  from_ptr=from->ptr;
508
509
  to_ptr=to;
512
513
    from_null_ptr=from->null_ptr;
513
514
    from_bit=     from->null_bit;
514
515
    to_ptr[0]=    1;                            // Null as default value
515
 
    to_null_ptr=  (uchar*) to_ptr++;
 
516
    to_null_ptr=  (unsigned char*) to_ptr++;
516
517
    to_bit=       1;
517
518
    if (from->table->maybe_null)
518
519
    {