~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field_conv.cc

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

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