~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/libdrizzle.c

  • Committer: Brian Aker
  • Date: 2009-02-05 10:38:55 UTC
  • Revision ID: brian@tangent.org-20090205103855-wajzccrbu7zbvmh4
Reworked some classes out of session.h
Also updated ignore file.

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 <drizzled/global.h>
 
21
#include "libdrizzle_priv.h"
 
22
 
20
23
#include "libdrizzle.h"
21
 
#include "libdrizzle_priv.h"
22
24
#include "errmsg.h"
 
25
#include "pack.h"
 
26
 
23
27
#include <sys/stat.h>
24
28
#include <signal.h>
25
29
#include <time.h>
50
54
 
51
55
#include <stdlib.h>
52
56
#include <string.h>
53
 
 
54
 
#include <sql_common.h>
55
 
#include <drizzled/version.h>
56
 
 
57
 
/* Borrowed from libicu header */
58
 
 
59
 
#define U8_IS_SINGLE(c) (((c)&0x80)==0)
60
 
#define U8_LENGTH(c) \
61
 
    ((uint32_t)(c)<=0x7f ? 1 : \
62
 
        ((uint32_t)(c)<=0x7ff ? 2 : \
63
 
            ((uint32_t)(c)<=0xd7ff ? 3 : \
64
 
                ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
65
 
                    ((uint32_t)(c)<=0xffff ? 3 : 4)\
66
 
                ) \
67
 
            ) \
68
 
        ) \
69
 
    )
 
57
#include <mystrings/utf8.h>
70
58
 
71
59
 
72
60
#undef net_buffer_length
78
66
unsigned int drizzle_port=0;
79
67
 
80
68
#include <errno.h>
81
 
#define SOCKET_ERROR -1
82
 
 
83
 
/*
84
 
  If allowed through some configuration, then this needs to
85
 
  be changed
86
 
*/
87
 
#define MAX_LONG_DATA_LENGTH 8192
88
 
#define unsigned_field(A) ((A)->flags & UNSIGNED_FLAG)
89
69
 
90
70
 
91
71
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
141
121
  uint32_t pkt_length;
142
122
 
143
123
  pkt_length= cli_safe_read(drizzle);
144
 
  
 
124
 
145
125
  if (pkt_length == packet_error)
146
126
    return 1;
147
127
 
449
429
const char *
450
430
drizzle_get_client_info(void)
451
431
{
452
 
  return (char*) DRIZZLE_SERVER_VERSION;
 
432
  return (char*) VERSION;
453
433
}
454
434
 
455
435
uint32_t drizzle_get_client_version(void)
538
518
}
539
519
 
540
520
/*
541
 
  This function is used to create HEX string that you
542
 
  can use in a SQL statement in of the either ways:
543
 
    INSERT INTO blob_column VALUES (0xAABBCC);  (any DRIZZLE version)
544
 
    INSERT INTO blob_column VALUES (X'AABBCC'); 
545
 
  
546
 
  The string in "from" is encoded to a HEX string.
547
 
  The result is placed in "to" and a terminating null byte is appended.
548
 
  
549
 
  The string pointed to by "from" must be "length" bytes long.
550
 
  You must allocate the "to" buffer to be at least length*2+1 bytes long.
551
 
  Each character needs two bytes, and you need room for the terminating
552
 
  null byte. When drizzle_hex_string() returns, the contents of "to" will
553
 
  be a null-terminated string. The return value is the length of the
554
 
  encoded string, not including the terminating null character.  The return value does not contain any leading 0x or a leading X' and
555
 
  trailing '. The caller must supply whichever of those is desired.
556
 
*/
557
 
 
558
 
uint32_t
559
 
drizzle_hex_string(char *to, const char *from, uint32_t length)
560
 
{
561
 
  char *to0= to;
562
 
  const char *end;
563
 
            
564
 
  for (end= from + length; from < end; from++)
565
 
  {
566
 
    *to++= _dig_vec_upper[((unsigned char) *from) >> 4];
567
 
    *to++= _dig_vec_upper[((unsigned char) *from) & 0x0F];
568
 
  }
569
 
  *to= '\0';
570
 
  return (uint32_t) (to-to0);
571
 
}
572
 
 
573
 
/*
574
521
  Add escape characters to a string (blob?) to make it suitable for a insert
575
522
  to should at least have place for length*2+1 chars
576
523
  Returns the length of the to string
588
535
    char escape= 0;
589
536
    if (!U8_IS_SINGLE(*from))
590
537
    {
591
 
      tmp_length= U8_LENGTH(*from);
 
538
      tmp_length= U8_LENGTH(*(uint32_t*)from);
592
539
      if (to + tmp_length > to_end)
593
540
      {
594
541
        overflow= true;