~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: Brian Aker
  • Date: 2008-08-14 20:59:41 UTC
  • Revision ID: brian@tangent.org-20080814205941-rdqc6mqguf50mvoq
Remove SET

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
19
 
20
20
#include <drizzled/global.h>
21
 
#include "libdrizzle.h"
 
21
#include <mysys/my_sys.h>
 
22
#include "my_time.h"
 
23
#include <mysys/mysys_err.h>
 
24
#include "drizzle.h"
22
25
#include "errmsg.h"
 
26
#include <vio/violite.h>
23
27
#include <sys/stat.h>
24
28
#include <signal.h>
25
29
#include <time.h>
44
48
#ifdef HAVE_SYS_UN_H
45
49
#include <sys/un.h>
46
50
#endif
 
51
#include <mysys/my_pthread.h>        /* because of signal()  */
47
52
#ifndef INADDR_NONE
48
53
#define INADDR_NONE  -1
49
54
#endif
52
57
#include "client_settings.h"
53
58
#include <drizzled/version.h>
54
59
 
55
 
/* Borrowed from libicu header */
56
 
 
57
 
#define U8_IS_SINGLE(c) (((c)&0x80)==0)
58
 
#define U8_LENGTH(c) \
59
 
    ((uint32_t)(c)<=0x7f ? 1 : \
60
 
        ((uint32_t)(c)<=0x7ff ? 2 : \
61
 
            ((uint32_t)(c)<=0xd7ff ? 3 : \
62
 
                ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
63
 
                    ((uint32_t)(c)<=0xffff ? 3 : 4)\
64
 
                ) \
65
 
            ) \
66
 
        ) \
67
 
    )
68
 
 
69
 
 
70
60
#undef net_buffer_length
71
61
#undef max_allowed_packet
72
62
 
92
82
  return &drizzle_internal_parameters;
93
83
}
94
84
 
 
85
bool drizzle_thread_init()
 
86
{
 
87
  return my_thread_init();
 
88
}
 
89
 
 
90
void drizzle_thread_end()
 
91
{
 
92
  my_thread_end();
 
93
}
 
94
 
 
95
 
95
96
/*
96
97
  Expand wildcard to a sql string
97
98
*/
154
155
  char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2];
155
156
  char *end= buff;
156
157
  int rc;
 
158
  const CHARSET_INFO *saved_cs= drizzle->charset;
 
159
 
 
160
  /* Get the connection-default character set. */
 
161
 
 
162
  if (drizzle_init_character_set(drizzle))
 
163
  {
 
164
    drizzle->charset= saved_cs;
 
165
    return(true);
 
166
  }
157
167
 
158
168
  /* Use an empty string instead of NULL. */
159
169
 
179
189
  end= strncpy(end, db ? db : "", NAME_LEN) + NAME_LEN + 1;
180
190
 
181
191
  /* Add character set number. */
 
192
 
182
193
  if (drizzle->server_capabilities & CLIENT_SECURE_CONNECTION)
183
194
  {
184
 
    int2store(end, (ushort) 45); // utf8mb4 number from mystrings/ctype-utf8.c
 
195
    int2store(end, (ushort) drizzle->charset->number);
185
196
    end+= 2;
186
197
  }
187
198
 
205
216
    drizzle->passwd= strdup(passwd);
206
217
    drizzle->db= db ? strdup(db) : 0;
207
218
  }
 
219
  else
 
220
  {
 
221
    drizzle->charset= saved_cs;
 
222
  }
208
223
 
209
224
  return(rc);
210
225
}
305
320
    return NULL;
306
321
 
307
322
  drizzle->field_count= (uint) query->rows;
308
 
  return unpack_fields(query, drizzle->field_count, 1);
 
323
  return unpack_fields(query,&drizzle->field_alloc, drizzle->field_count, 1);
309
324
}
310
325
 
311
326
 
338
353
  memset(result, 0, sizeof(DRIZZLE_RES));
339
354
 
340
355
  result->methods= drizzle->methods;
 
356
  result->field_alloc=drizzle->field_alloc;
341
357
  drizzle->fields=0;
342
358
  result->field_count = drizzle->field_count;
343
359
  result->fields= fields;
361
377
  field_count=(uint) net_field_length(&pos);
362
378
  if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0, 7)))
363
379
    return(NULL);
364
 
  if (!(drizzle->fields=unpack_fields(fields, field_count, 0)))
 
380
  if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,field_count,0)))
365
381
    return(0);
366
382
  drizzle->status=DRIZZLE_STATUS_GET_RESULT;
367
383
  drizzle->field_count=field_count;
521
537
  return drizzle->thread_id;
522
538
}
523
539
 
 
540
const char * drizzle_character_set_name(const DRIZZLE *drizzle)
 
541
{
 
542
  return drizzle->charset->csname;
 
543
}
 
544
 
 
545
void drizzle_get_character_set_info(const DRIZZLE *drizzle, MY_CHARSET_INFO *csinfo)
 
546
{
 
547
  csinfo->number   = drizzle->charset->number;
 
548
  csinfo->state    = drizzle->charset->state;
 
549
  csinfo->csname   = drizzle->charset->csname;
 
550
  csinfo->name     = drizzle->charset->name;
 
551
  csinfo->comment  = drizzle->charset->comment;
 
552
  csinfo->mbminlen = drizzle->charset->mbminlen;
 
553
  csinfo->mbmaxlen = drizzle->charset->mbmaxlen;
 
554
 
 
555
  if (drizzle->options.charset_dir)
 
556
    csinfo->dir = drizzle->options.charset_dir;
 
557
  else
 
558
    csinfo->dir = charsets_dir;
 
559
}
 
560
 
 
561
uint drizzle_thread_safe(void)
 
562
{
 
563
  return 1;
 
564
}
 
565
 
 
566
 
 
567
bool drizzle_embedded(void)
 
568
{
 
569
#ifdef EMBEDDED_LIBRARY
 
570
  return true;
 
571
#else
 
572
  return false;
 
573
#endif
 
574
}
 
575
 
524
576
/****************************************************************************
525
577
  Some support functions
526
578
****************************************************************************/
552
604
  Each character needs two bytes, and you need room for the terminating
553
605
  null byte. When drizzle_hex_string() returns, the contents of "to" will
554
606
  be a null-terminated string. The return value is the length of the
555
 
  encoded string, not including the terminating null character.  The return value does not contain any leading 0x or a leading X' and
 
607
  encoded string, not including the terminating null character.
 
608
 
 
609
  The return value does not contain any leading 0x or a leading X' and
556
610
  trailing '. The caller must supply whichever of those is desired.
557
611
*/
558
612
 
580
634
uint32_t
581
635
drizzle_escape_string(char *to,const char *from, uint32_t length)
582
636
{
583
 
  const char *to_start= to;
584
 
  const char *end, *to_end=to_start + 2*length;
585
 
  bool overflow= false;
586
 
  for (end= from + length; from < end; from++)
 
637
  return escape_string_for_drizzle(default_charset_info, to, 0, from, length);
 
638
}
 
639
 
 
640
uint32_t
 
641
drizzle_real_escape_string(DRIZZLE *drizzle, char *to,const char *from,
 
642
       uint32_t length)
 
643
{
 
644
  if (drizzle->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
 
645
    return escape_quotes_for_drizzle(drizzle->charset, to, 0, from, length);
 
646
  return escape_string_for_drizzle(drizzle->charset, to, 0, from, length);
 
647
}
 
648
 
 
649
void
 
650
myodbc_remove_escape(const DRIZZLE *drizzle, char *name)
 
651
{
 
652
  char *to;
 
653
#ifdef USE_MB
 
654
  bool use_mb_flag= use_mb(drizzle->charset);
 
655
  char *end=NULL;
 
656
  if (use_mb_flag)
 
657
    for (end=name; *end ; end++) ;
 
658
#endif
 
659
 
 
660
  for (to=name ; *name ; name++)
587
661
  {
588
 
    uint32_t tmp_length;
589
 
    char escape= 0;
590
 
    if (!U8_IS_SINGLE(*from))
 
662
#ifdef USE_MB
 
663
    int l;
 
664
    if (use_mb_flag && (l = my_ismbchar( drizzle->charset, name , end ) ) )
591
665
    {
592
 
      tmp_length= U8_LENGTH(*from);
593
 
      if (to + tmp_length > to_end)
594
 
      {
595
 
        overflow= true;
596
 
        break;
597
 
      }
598
 
      while (tmp_length--)
599
 
        *to++= *from++;
600
 
      from--;
 
666
      while (l--)
 
667
        *to++ = *name++;
 
668
      name--;
601
669
      continue;
602
670
    }
603
 
    switch (*from) {
604
 
    case 0:                             /* Must be escaped for 'mysql' */
605
 
      escape= '0';
606
 
      break;
607
 
    case '\n':                          /* Must be escaped for logs */
608
 
      escape= 'n';
609
 
      break;
610
 
    case '\r':
611
 
      escape= 'r';
612
 
      break;
613
 
    case '\\':
614
 
      escape= '\\';
615
 
      break;
616
 
    case '\'':
617
 
      escape= '\'';
618
 
      break;
619
 
    case '"':                           /* Better safe than sorry */
620
 
      escape= '"';
621
 
      break;
622
 
    case '\032':                        /* This gives problems on Win32 */
623
 
      escape= 'Z';
624
 
      break;
625
 
    }
626
 
    if (escape)
627
 
    {
628
 
      if (to + 2 > to_end)
629
 
      {
630
 
        overflow= true;
631
 
        break;
632
 
      }
633
 
      *to++= '\\';
634
 
      *to++= escape;
635
 
    }
636
 
    else
637
 
    {
638
 
      if (to + 1 > to_end)
639
 
      {
640
 
        overflow= true;
641
 
        break;
642
 
      }
643
 
      *to++= *from;
644
 
    }
 
671
#endif
 
672
    if (*name == '\\' && name[1])
 
673
      name++;
 
674
    *to++= *name;
645
675
  }
646
 
  *to= 0;
647
 
  return overflow ? (size_t) -1 : (size_t) (to - to_start);
 
676
  *to=0;
648
677
}
649
678
 
650
679
int cli_unbuffered_fetch(DRIZZLE *drizzle, char **row)