~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: Brian Aker
  • Date: 2008-11-16 02:13:14 UTC
  • mfrom: (584.1.7 devel)
  • Revision ID: brian@tangent.org-20081116021314-31uh0w1l0601cwd5
Merger from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
530
530
}
531
531
 
532
532
/*
533
 
  This function is used to create HEX string that you
534
 
  can use in a SQL statement in of the either ways:
535
 
    INSERT INTO blob_column VALUES (0xAABBCC);  (any DRIZZLE version)
536
 
    INSERT INTO blob_column VALUES (X'AABBCC'); 
537
 
  
538
 
  The string in "from" is encoded to a HEX string.
539
 
  The result is placed in "to" and a terminating null byte is appended.
540
 
  
541
 
  The string pointed to by "from" must be "length" bytes long.
542
 
  You must allocate the "to" buffer to be at least length*2+1 bytes long.
543
 
  Each character needs two bytes, and you need room for the terminating
544
 
  null byte. When drizzle_hex_string() returns, the contents of "to" will
545
 
  be a null-terminated string. The return value is the length of the
546
 
  encoded string, not including the terminating null character.  The return value does not contain any leading 0x or a leading X' and
547
 
  trailing '. The caller must supply whichever of those is desired.
548
 
*/
549
 
 
550
 
uint32_t
551
 
drizzle_hex_string(char *to, const char *from, uint32_t length)
552
 
{
553
 
  char *to0= to;
554
 
  const char *end;
555
 
            
556
 
  for (end= from + length; from < end; from++)
557
 
  {
558
 
    *to++= _dig_vec_upper[((unsigned char) *from) >> 4];
559
 
    *to++= _dig_vec_upper[((unsigned char) *from) & 0x0F];
560
 
  }
561
 
  *to= '\0';
562
 
  return (uint32_t) (to-to0);
563
 
}
564
 
 
565
 
/*
566
533
  Add escape characters to a string (blob?) to make it suitable for a insert
567
534
  to should at least have place for length*2+1 chars
568
535
  Returns the length of the to string