~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: Brian Aker
  • Date: 2008-12-19 22:44:25 UTC
  • mto: (642.1.43 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 726.
  • Revision ID: brian@gir.tangent.org-20081219224425-dyfp85hppystsxqy
Adding in missing flush results.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include <drizzled/global.h>
21
21
#include "libdrizzle_priv.h"
22
22
 
23
23
#include <libdrizzle/libdrizzle.h>
133
133
  uint32_t pkt_length;
134
134
 
135
135
  pkt_length= cli_safe_read(drizzle);
136
 
  
 
136
 
137
137
  if (pkt_length == packet_error)
138
138
    return 1;
139
139
 
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