~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: Monty Taylor
  • Date: 2008-07-30 03:26:20 UTC
  • mto: (236.1.4 codestyle)
  • mto: This revision was merged to the branch mainline in revision 239.
  • Revision ID: monty@inaugust.com-20080730032620-9g6t1ua4p0p0r177
Removed my_stat.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004 MySQL AB
 
1
/* Copyright (C) 2000-2004 DRIZZLE AB
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
21
21
#include <my_sys.h>
22
22
#include <my_time.h>
23
23
#include <mysys_err.h>
24
 
#include <m_string.h>
25
 
#include <m_ctype.h>
 
24
#include <mystrings/m_string.h>
 
25
#include <mystrings/m_ctype.h>
26
26
#include "drizzle.h"
27
 
#include "drizzle_version.h"
28
 
#include "mysqld_error.h"
 
27
#include "drizzled_error.h"
29
28
#include "errmsg.h"
30
29
#include <violite.h>
31
30
#include <sys/stat.h>
32
31
#include <signal.h>
33
32
#include <time.h>
34
 
#ifdef   HAVE_PWD_H
 
33
#ifdef   HAVE_PWD_H
35
34
#include <pwd.h>
36
35
#endif
37
36
 
52
51
#ifdef HAVE_SYS_UN_H
53
52
#include <sys/un.h>
54
53
#endif
55
 
#include <my_pthread.h>                         /* because of signal()  */
 
54
#include <my_pthread.h>        /* because of signal()  */
56
55
#ifndef INADDR_NONE
57
 
#define INADDR_NONE     -1
 
56
#define INADDR_NONE  -1
58
57
#endif
59
58
 
60
59
#include <sql_common.h>
63
62
#undef net_buffer_length
64
63
#undef max_allowed_packet
65
64
 
66
 
uint32_t                net_buffer_length= 8192;
67
 
uint32_t                max_allowed_packet= 1024L*1024L*1024L;
 
65
uint32_t     net_buffer_length= 8192;
 
66
uint32_t    max_allowed_packet= 1024L*1024L*1024L;
68
67
 
69
68
#include <errno.h>
70
69
#define SOCKET_ERROR -1
78
77
 
79
78
static void append_wild(char *to,char *end,const char *wild);
80
79
 
81
 
static my_bool mysql_client_init= 0;
82
 
static my_bool org_my_init_done= 0;
83
 
 
84
 
 
85
 
/*
86
 
  Initialize the MySQL client library
87
 
 
88
 
  SYNOPSIS
89
 
    mysql_server_init()
90
 
 
91
 
  NOTES
92
 
    Should be called before doing any other calls to the MySQL
93
 
    client library to initialize thread specific variables etc.
94
 
    It's called by mysql_init() to ensure that things will work for
95
 
    old not threaded applications that doesn't call mysql_server_init()
96
 
    directly.
97
 
 
98
 
  RETURN
99
 
    0  ok
100
 
    1  could not initialize environment (out of memory or thread keys)
101
 
*/
102
 
 
103
 
int STDCALL mysql_server_init(int argc __attribute__((unused)),
104
 
                              char **argv __attribute__((unused)),
105
 
                              char **groups __attribute__((unused)))
106
 
{
107
 
  int result= 0;
108
 
  if (!mysql_client_init)
109
 
  {
110
 
    mysql_client_init=1;
111
 
    org_my_init_done=my_init_done;
112
 
    if (my_init())                              /* Will init threads */
113
 
      return 1;
114
 
    init_client_errs();
115
 
    if (!mysql_port)
116
 
    {
117
 
      mysql_port = MYSQL_PORT;
118
 
      {
119
 
        struct servent *serv_ptr;
120
 
        char    *env;
121
 
 
122
 
        /*
123
 
          if builder specifically requested a default port, use that
124
 
          (even if it coincides with our factory default).
125
 
          only if they didn't do we check /etc/services (and, failing
126
 
          on that, fall back to the factory default of 4427).
127
 
          either default can be overridden by the environment variable
128
 
          MYSQL_TCP_PORT, which in turn can be overridden with command
129
 
          line options.
130
 
        */
131
 
 
132
 
#if MYSQL_PORT_DEFAULT == 0
133
 
        if ((serv_ptr = getservbyname("mysql", "tcp")))
134
 
          mysql_port = (uint) ntohs((ushort) serv_ptr->s_port);
135
 
#endif
136
 
        if ((env = getenv("MYSQL_TCP_PORT")))
137
 
          mysql_port =(uint) atoi(env);
138
 
      }
139
 
    }
140
 
    if (!mysql_unix_port)
141
 
    {
142
 
      char *env;
143
 
      mysql_unix_port = (char*) MYSQL_UNIX_ADDR;
144
 
      if ((env = getenv("MYSQL_UNIX_PORT")))
145
 
        mysql_unix_port = env;
146
 
    }
147
 
#if defined(SIGPIPE)
148
 
    (void) signal(SIGPIPE, SIG_IGN);
149
 
#endif
150
 
  }
151
 
  else
152
 
    result= (int)my_thread_init();         /* Init if new thread */
153
 
  return result;
154
 
}
155
 
 
156
 
 
157
 
/*
158
 
  Free all memory and resources used by the client library
159
 
 
160
 
  NOTES
161
 
    When calling this there should not be any other threads using
162
 
    the library.
163
 
 
164
 
    To make things simpler when used with windows dll's (which calls this
165
 
    function automaticly), it's safe to call this function multiple times.
166
 
*/
167
 
 
168
 
 
169
 
void STDCALL mysql_server_end()
170
 
{
171
 
  if (!mysql_client_init)
172
 
    return;
173
 
 
174
 
  finish_client_errs();
175
 
  vio_end();
176
 
 
177
 
  /* If library called my_init(), free memory allocated by it */
178
 
  if (!org_my_init_done)
179
 
  {
180
 
    my_end(0);
181
 
  }
182
 
  else
183
 
  {
184
 
    free_charsets();
185
 
    mysql_thread_end();
186
 
  }
187
 
 
188
 
  mysql_client_init= org_my_init_done= 0;
189
 
#ifdef EMBEDDED_SERVER
190
 
  if (stderror_file)
191
 
  {
192
 
    fclose(stderror_file);
193
 
    stderror_file= 0;
194
 
  }
195
 
#endif
196
 
}
197
 
 
198
 
static MYSQL_PARAMETERS mysql_internal_parameters=
 
80
 
 
81
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
199
82
{&max_allowed_packet, &net_buffer_length, 0};
200
83
 
201
 
MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void)
 
84
DRIZZLE_PARAMETERS *STDCALL drizzle_get_parameters(void)
202
85
{
203
 
  return &mysql_internal_parameters;
 
86
  return &drizzle_internal_parameters;
204
87
}
205
88
 
206
 
my_bool STDCALL mysql_thread_init()
 
89
bool STDCALL drizzle_thread_init()
207
90
{
208
91
  return my_thread_init();
209
92
}
210
93
 
211
 
void STDCALL mysql_thread_end()
 
94
void STDCALL drizzle_thread_end()
212
95
{
213
96
  my_thread_end();
214
97
}
221
104
static void
222
105
append_wild(char *to, char *end, const char *wild)
223
106
{
224
 
  end-=5;                                       /* Some extra */
 
107
  end-=5;          /* Some extra */
225
108
  if (wild && wild[0])
226
109
  {
227
110
    to=strmov(to," like '");
228
111
    while (*wild && to < end)
229
112
    {
230
113
      if (*wild == '\\' || *wild == '\'')
231
 
        *to++='\\';
 
114
  *to++='\\';
232
115
      *to++= *wild++;
233
116
    }
234
 
    if (*wild)                                  /* Too small buffer */
235
 
      *to++='%';                                /* Nicer this way */
 
117
    if (*wild)          /* Too small buffer */
 
118
      *to++='%';        /* Nicer this way */
236
119
    to[0]='\'';
237
120
    to[1]=0;
238
121
  }
258
141
**************************************************************************/
259
142
 
260
143
#ifdef USE_OLD_FUNCTIONS
261
 
MYSQL * STDCALL
262
 
mysql_connect(MYSQL *mysql,const char *host,
263
 
              const char *user, const char *passwd)
 
144
DRIZZLE * STDCALL
 
145
drizzle_connect(DRIZZLE *drizzle,const char *host,
 
146
        const char *user, const char *passwd)
264
147
{
265
 
  MYSQL *res;
266
 
  mysql=mysql_init(mysql);                      /* Make it thread safe */
 
148
  DRIZZLE *res;
 
149
  drizzle=drizzle_init(drizzle);      /* Make it thread safe */
267
150
  {
268
 
    if (!(res=mysql_real_connect(mysql,host,user,passwd,NullS,0,NullS,0)))
 
151
    if (!(res=drizzle_connect(drizzle,host,user,passwd,NullS,0,NullS,0)))
269
152
    {
270
 
      if (mysql->free_me)
271
 
        my_free((uchar*) mysql,MYF(0));
 
153
      if (drizzle->free_me && drizzle)
 
154
        free((uchar*) drizzle);
272
155
    }
273
 
    mysql->reconnect= 1;
 
156
    drizzle->reconnect= 1;
274
157
    return(res);
275
158
  }
276
159
}
281
164
  Change user and database
282
165
**************************************************************************/
283
166
 
284
 
int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd)
 
167
int cli_read_change_user_result(DRIZZLE *drizzle, char *buff, const char *passwd)
285
168
{
286
169
  (void)buff;
287
170
  (void)passwd;
288
171
  ulong pkt_length;
289
172
 
290
 
  pkt_length= cli_safe_read(mysql);
 
173
  pkt_length= cli_safe_read(drizzle);
291
174
  
292
175
  if (pkt_length == packet_error)
293
176
    return 1;
295
178
  return 0;
296
179
}
297
180
 
298
 
my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
299
 
                                  const char *passwd, const char *db)
 
181
bool STDCALL drizzle_change_user(DRIZZLE *drizzle, const char *user,
 
182
          const char *passwd, const char *db)
300
183
{
301
184
  char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2];
302
185
  char *end= buff;
303
186
  int rc;
304
 
  CHARSET_INFO *saved_cs= mysql->charset;
 
187
  CHARSET_INFO *saved_cs= drizzle->charset;
305
188
 
306
189
  /* Get the connection-default character set. */
307
190
 
308
 
  if (mysql_init_character_set(mysql))
 
191
  if (drizzle_init_character_set(drizzle))
309
192
  {
310
 
    mysql->charset= saved_cs;
 
193
    drizzle->charset= saved_cs;
311
194
    return(true);
312
195
  }
313
196
 
326
209
  {
327
210
    {
328
211
      *end++= SCRAMBLE_LENGTH;
329
 
      scramble(end, mysql->scramble, passwd);
 
212
      scramble(end, drizzle->scramble, passwd);
330
213
      end+= SCRAMBLE_LENGTH;
331
214
    }
332
215
  }
337
220
 
338
221
  /* Add character set number. */
339
222
 
340
 
  if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION)
 
223
  if (drizzle->server_capabilities & CLIENT_SECURE_CONNECTION)
341
224
  {
342
 
    int2store(end, (ushort) mysql->charset->number);
 
225
    int2store(end, (ushort) drizzle->charset->number);
343
226
    end+= 2;
344
227
  }
345
228
 
346
229
  /* Write authentication package */
347
 
  (void)simple_command(mysql,COM_CHANGE_USER, (uchar*) buff, (ulong) (end-buff), 1);
 
230
  (void)simple_command(drizzle,COM_CHANGE_USER, (uchar*) buff, (ulong) (end-buff), 1);
348
231
 
349
 
  rc= (*mysql->methods->read_change_user_result)(mysql, buff, passwd);
 
232
  rc= (*drizzle->methods->read_change_user_result)(drizzle, buff, passwd);
350
233
 
351
234
  if (rc == 0)
352
235
  {
353
236
    /* Free old connect information */
354
 
    my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR));
355
 
    my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR));
356
 
    my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
 
237
    if(drizzle->user)
 
238
      free(drizzle->user);
 
239
    if(drizzle->passwd)
 
240
      free(drizzle->passwd);
 
241
    if(drizzle->db)
 
242
      free(drizzle->db);
357
243
 
358
244
    /* alloc new connect information */
359
 
    mysql->user=  my_strdup(user,MYF(MY_WME));
360
 
    mysql->passwd=my_strdup(passwd,MYF(MY_WME));
361
 
    mysql->db=    db ? my_strdup(db,MYF(MY_WME)) : 0;
 
245
    drizzle->user=  my_strdup(user,MYF(MY_WME));
 
246
    drizzle->passwd=my_strdup(passwd,MYF(MY_WME));
 
247
    drizzle->db=    db ? my_strdup(db,MYF(MY_WME)) : 0;
362
248
  }
363
249
  else
364
250
  {
365
 
    mysql->charset= saved_cs;
 
251
    drizzle->charset= saved_cs;
366
252
  }
367
253
 
368
254
  return(rc);
376
262
void read_user_name(char *name)
377
263
{
378
264
  if (geteuid() == 0)
379
 
    (void) strmov(name,"root");         /* allow use of surun */
 
265
    (void) strmov(name,"root");    /* allow use of surun */
380
266
  else
381
267
  {
382
268
#ifdef HAVE_GETPWUID
385
271
    if ((str=getlogin()) == NULL)
386
272
    {
387
273
      if ((skr=getpwuid(geteuid())) != NULL)
388
 
        str=skr->pw_name;
 
274
  str=skr->pw_name;
389
275
      else if (!(str=getenv("USER")) && !(str=getenv("LOGNAME")) &&
390
 
               !(str=getenv("LOGIN")))
391
 
        str="UNKNOWN_USER";
 
276
         !(str=getenv("LOGIN")))
 
277
  str="UNKNOWN_USER";
392
278
    }
393
279
    (void) strmake(name,str,USERNAME_LENGTH);
394
280
#elif HAVE_CUSERID
400
286
  return;
401
287
}
402
288
 
403
 
my_bool handle_local_infile(MYSQL *mysql, const char *net_filename)
 
289
bool handle_local_infile(DRIZZLE *drizzle, const char *net_filename)
404
290
{
405
 
  my_bool result= 1;
406
 
  uint packet_length=MY_ALIGN(mysql->net.max_packet-16,IO_SIZE);
407
 
  NET *net= &mysql->net;
 
291
  bool result= true;
 
292
  uint packet_length=MY_ALIGN(drizzle->net.max_packet-16,IO_SIZE);
 
293
  NET *net= &drizzle->net;
408
294
  int readcount;
409
295
  void *li_ptr;          /* pass state to local_infile functions */
410
 
  char *buf;            /* buffer to be filled by local_infile_read */
411
 
  struct st_mysql_options *options= &mysql->options;
 
296
  char *buf;    /* buffer to be filled by local_infile_read */
 
297
  struct st_drizzle_options *options= &drizzle->options;
412
298
 
413
299
  /* check that we've got valid callback functions */
414
300
  if (!(options->local_infile_init &&
415
 
        options->local_infile_read &&
416
 
        options->local_infile_end &&
417
 
        options->local_infile_error))
 
301
  options->local_infile_read &&
 
302
  options->local_infile_end &&
 
303
  options->local_infile_error))
418
304
  {
419
305
    /* if any of the functions is invalid, set the default */
420
 
    mysql_set_local_infile_default(mysql);
 
306
    drizzle_set_local_infile_default(drizzle);
421
307
  }
422
308
 
423
309
  /* copy filename into local memory and allocate read buffer */
424
 
  if (!(buf=my_malloc(packet_length, MYF(0))))
 
310
  if (!(buf=malloc(packet_length)))
425
311
  {
426
 
    set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
 
312
    set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
427
313
    return(1);
428
314
  }
429
315
 
443
329
 
444
330
  /* read blocks of data from local infile callback */
445
331
  while ((readcount =
446
 
          (*options->local_infile_read)(li_ptr, buf,
447
 
                                        packet_length)) > 0)
 
332
    (*options->local_infile_read)(li_ptr, buf,
 
333
          packet_length)) > 0)
448
334
  {
449
335
    if (my_net_write(net, (uchar*) buf, readcount))
450
336
    {
455
341
  /* Send empty packet to mark end of file */
456
342
  if (my_net_write(net, (const uchar*) "", 0) || net_flush(net))
457
343
  {
458
 
    set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
 
344
    set_drizzle_error(drizzle, CR_SERVER_LOST, unknown_sqlstate);
459
345
    goto err;
460
346
  }
461
347
 
468
354
    goto err;
469
355
  }
470
356
 
471
 
  result=0;                                     /* Ok */
 
357
  result=false;                                 /* Ok */
472
358
 
473
359
err:
474
360
  /* free up memory allocated with _init, usually */
475
361
  (*options->local_infile_end)(li_ptr);
476
 
  my_free(buf, MYF(0));
 
362
  if(buf)
 
363
    free(buf);
477
364
  return(result);
478
365
}
479
366
 
496
383
 
497
384
  SYNOPSIS
498
385
    default_local_infile_init()
499
 
    ptr                 Store pointer to internal data here
500
 
    filename            File name to open. This may be in unix format !
 
386
    ptr      Store pointer to internal data here
 
387
    filename    File name to open. This may be in unix format !
501
388
 
502
389
 
503
390
  NOTES
505
392
    guarantees that default_local_infile_end() is called.
506
393
 
507
394
  RETURN
508
 
    0   ok
509
 
    1   error
 
395
    0  ok
 
396
    1  error
510
397
*/
511
398
 
512
399
static int default_local_infile_init(void **ptr, const char *filename,
516
403
  char tmp_name[FN_REFLEN];
517
404
 
518
405
  if (!(*ptr= data= ((default_local_infile_data *)
519
 
                     my_malloc(sizeof(default_local_infile_data),  MYF(0)))))
 
406
                     malloc(sizeof(default_local_infile_data)))))
520
407
    return 1; /* out of memory */
521
408
 
522
409
  data->error_msg[0]= 0;
540
427
 
541
428
  SYNOPSIS
542
429
    default_local_infile_read()
543
 
    ptr                 Points to handle allocated by _init
544
 
    buf                 Read data here
545
 
    buf_len             Ammount of data to read
 
430
    ptr      Points to handle allocated by _init
 
431
    buf      Read data here
 
432
    buf_len    Ammount of data to read
546
433
 
547
434
  RETURN
548
 
    > 0         number of bytes read
549
 
    == 0        End of data
550
 
    < 0         Error
 
435
    > 0    number of bytes read
 
436
    == 0  End of data
 
437
    < 0    Error
551
438
*/
552
439
 
553
440
static int default_local_infile_read(void *ptr, char *buf, uint buf_len)
571
458
 
572
459
  SYNOPSIS
573
460
    default_local_infile_end()
574
 
    ptr                 Points to handle allocated by _init
575
 
                        May be NULL if _init failed!
 
461
    ptr      Points to handle allocated by _init
 
462
      May be NULL if _init failed!
576
463
 
577
464
  RETURN
578
465
*/
580
467
static void default_local_infile_end(void *ptr)
581
468
{
582
469
  default_local_infile_data *data= (default_local_infile_data *) ptr;
583
 
  if (data)                                     /* If not error on open */
 
470
  if (data)          /* If not error on open */
584
471
  {
585
472
    if (data->fd >= 0)
586
473
      my_close(data->fd, MYF(MY_WME));
587
 
    my_free(ptr, MYF(MY_WME));
 
474
    free(ptr);
588
475
  }
589
476
}
590
477
 
594
481
 
595
482
  SYNOPSIS
596
483
    default_local_infile_end()
597
 
    ptr                 Points to handle allocated by _init
598
 
                        May be NULL if _init failed!
599
 
    error_msg           Store error text here
600
 
    error_msg_len       Max lenght of error_msg
 
484
    ptr      Points to handle allocated by _init
 
485
      May be NULL if _init failed!
 
486
    error_msg    Store error text here
 
487
    error_msg_len  Max lenght of error_msg
601
488
 
602
489
  RETURN
603
490
    error message number
607
494
default_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
608
495
{
609
496
  default_local_infile_data *data = (default_local_infile_data *) ptr;
610
 
  if (data)                                     /* If not error on open */
 
497
  if (data)          /* If not error on open */
611
498
  {
612
499
    strmake(error_msg, data->error_msg, error_msg_len);
613
500
    return data->error_num;
619
506
 
620
507
 
621
508
void
622
 
mysql_set_local_infile_handler(MYSQL *mysql,
 
509
drizzle_set_local_infile_handler(DRIZZLE *drizzle,
623
510
                               int (*local_infile_init)(void **, const char *,
624
511
                               void *),
625
512
                               int (*local_infile_read)(void *, char *, uint),
627
514
                               int (*local_infile_error)(void *, char *, uint),
628
515
                               void *userdata)
629
516
{
630
 
  mysql->options.local_infile_init=  local_infile_init;
631
 
  mysql->options.local_infile_read=  local_infile_read;
632
 
  mysql->options.local_infile_end=   local_infile_end;
633
 
  mysql->options.local_infile_error= local_infile_error;
634
 
  mysql->options.local_infile_userdata = userdata;
 
517
  drizzle->options.local_infile_init=  local_infile_init;
 
518
  drizzle->options.local_infile_read=  local_infile_read;
 
519
  drizzle->options.local_infile_end=   local_infile_end;
 
520
  drizzle->options.local_infile_error= local_infile_error;
 
521
  drizzle->options.local_infile_userdata = userdata;
635
522
}
636
523
 
637
524
 
638
 
void mysql_set_local_infile_default(MYSQL *mysql)
 
525
void drizzle_set_local_infile_default(DRIZZLE *drizzle)
639
526
{
640
 
  mysql->options.local_infile_init=  default_local_infile_init;
641
 
  mysql->options.local_infile_read=  default_local_infile_read;
642
 
  mysql->options.local_infile_end=   default_local_infile_end;
643
 
  mysql->options.local_infile_error= default_local_infile_error;
 
527
  drizzle->options.local_infile_init=  default_local_infile_init;
 
528
  drizzle->options.local_infile_read=  default_local_infile_read;
 
529
  drizzle->options.local_infile_end=   default_local_infile_end;
 
530
  drizzle->options.local_infile_error= default_local_infile_error;
644
531
}
645
532
 
646
533
 
647
534
/**************************************************************************
648
535
  Do a query. If query returned rows, free old rows.
649
 
  Read data by mysql_store_result or by repeat call of mysql_fetch_row
 
536
  Read data by drizzle_store_result or by repeat call of drizzle_fetch_row
650
537
**************************************************************************/
651
538
 
652
539
int STDCALL
653
 
mysql_query(MYSQL *mysql, const char *query)
 
540
drizzle_query(DRIZZLE *drizzle, const char *query)
654
541
{
655
 
  return mysql_real_query(mysql,query, (uint) strlen(query));
 
542
  return drizzle_real_query(drizzle,query, (uint) strlen(query));
656
543
}
657
544
 
658
545
 
660
547
  Return next field of the query results
661
548
**************************************************************************/
662
549
 
663
 
MYSQL_FIELD * STDCALL
664
 
mysql_fetch_field(MYSQL_RES *result)
 
550
DRIZZLE_FIELD * STDCALL
 
551
drizzle_fetch_field(DRIZZLE_RES *result)
665
552
{
666
553
  if (result->current_field >= result->field_count)
667
554
    return(NULL);
674
561
**************************************************************************/
675
562
 
676
563
void STDCALL
677
 
mysql_data_seek(MYSQL_RES *result, uint64_t row)
 
564
drizzle_data_seek(DRIZZLE_RES *result, uint64_t row)
678
565
{
679
 
  MYSQL_ROWS    *tmp=0;
 
566
  DRIZZLE_ROWS  *tmp=0;
680
567
  if (result->data)
681
568
    for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ;
682
569
  result->current_row=0;
685
572
 
686
573
 
687
574
/*************************************************************************
688
 
  put the row or field cursor one a position one got from mysql_row_tell()
689
 
  This doesn't restore any data. The next mysql_fetch_row or
690
 
  mysql_fetch_field will return the next row or field after the last used
 
575
  put the row or field cursor one a position one got from DRIZZLE_ROW_tell()
 
576
  This doesn't restore any data. The next drizzle_fetch_row or
 
577
  drizzle_fetch_field will return the next row or field after the last used
691
578
*************************************************************************/
692
579
 
693
 
MYSQL_ROW_OFFSET STDCALL
694
 
mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET row)
 
580
DRIZZLE_ROW_OFFSET STDCALL
 
581
drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET row)
695
582
{
696
 
  MYSQL_ROW_OFFSET return_value=result->data_cursor;
 
583
  DRIZZLE_ROW_OFFSET return_value=result->data_cursor;
697
584
  result->current_row= 0;
698
585
  result->data_cursor= row;
699
586
  return return_value;
700
587
}
701
588
 
702
589
 
703
 
MYSQL_FIELD_OFFSET STDCALL
704
 
mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET field_offset)
 
590
DRIZZLE_FIELD_OFFSET STDCALL
 
591
drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET field_offset)
705
592
{
706
 
  MYSQL_FIELD_OFFSET return_value=result->current_field;
 
593
  DRIZZLE_FIELD_OFFSET return_value=result->current_field;
707
594
  result->current_field=field_offset;
708
595
  return return_value;
709
596
}
713
600
  List all databases
714
601
*****************************************************************************/
715
602
 
716
 
MYSQL_RES * STDCALL
717
 
mysql_list_dbs(MYSQL *mysql, const char *wild)
 
603
DRIZZLE_RES * STDCALL
 
604
drizzle_list_dbs(DRIZZLE *drizzle, const char *wild)
718
605
{
719
606
  char buff[255];
720
607
 
721
608
  append_wild(strmov(buff,"show databases"),buff+sizeof(buff),wild);
722
 
  if (mysql_query(mysql,buff))
 
609
  if (drizzle_query(drizzle,buff))
723
610
    return(0);
724
 
  return (mysql_store_result(mysql));
 
611
  return (drizzle_store_result(drizzle));
725
612
}
726
613
 
727
614
 
730
617
  If wild is given then only the tables matching wild is returned
731
618
*****************************************************************************/
732
619
 
733
 
MYSQL_RES * STDCALL
734
 
mysql_list_tables(MYSQL *mysql, const char *wild)
 
620
DRIZZLE_RES * STDCALL
 
621
drizzle_list_tables(DRIZZLE *drizzle, const char *wild)
735
622
{
736
623
  char buff[255];
737
624
 
738
625
  append_wild(strmov(buff,"show tables"),buff+sizeof(buff),wild);
739
 
  if (mysql_query(mysql,buff))
 
626
  if (drizzle_query(drizzle,buff))
740
627
    return(0);
741
 
  return (mysql_store_result(mysql));
 
628
  return (drizzle_store_result(drizzle));
742
629
}
743
630
 
744
631
 
745
 
MYSQL_FIELD *cli_list_fields(MYSQL *mysql)
 
632
DRIZZLE_FIELD *cli_list_fields(DRIZZLE *drizzle)
746
633
{
747
 
  MYSQL_DATA *query;
748
 
  if (!(query= cli_read_rows(mysql,(MYSQL_FIELD*) 0, 
749
 
                             protocol_41(mysql) ? 8 : 6)))
 
634
  DRIZZLE_DATA *query;
 
635
  if (!(query= cli_read_rows(drizzle,(DRIZZLE_FIELD*) 0, 
 
636
           protocol_41(drizzle) ? 8 : 6)))
750
637
    return NULL;
751
638
 
752
 
  mysql->field_count= (uint) query->rows;
753
 
  return unpack_fields(query,&mysql->field_alloc,
754
 
                       mysql->field_count, 1, mysql->server_capabilities);
 
639
  drizzle->field_count= (uint) query->rows;
 
640
  return unpack_fields(query,&drizzle->field_alloc,
 
641
           drizzle->field_count, 1, drizzle->server_capabilities);
755
642
}
756
643
 
757
644
 
762
649
  show fields in 'table' like "wild"
763
650
**************************************************************************/
764
651
 
765
 
MYSQL_RES * STDCALL
766
 
mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
 
652
DRIZZLE_RES * STDCALL
 
653
drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild)
767
654
{
768
 
  MYSQL_RES   *result;
769
 
  MYSQL_FIELD *fields;
770
 
  char       buff[257],*end;
 
655
  DRIZZLE_RES   *result;
 
656
  DRIZZLE_FIELD *fields;
 
657
  char       buff[257],*end;
771
658
 
772
659
  end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128);
773
 
  free_old_query(mysql);
774
 
  if (simple_command(mysql, COM_FIELD_LIST, (uchar*) buff,
 
660
  free_old_query(drizzle);
 
661
  if (simple_command(drizzle, COM_FIELD_LIST, (uchar*) buff,
775
662
                     (ulong) (end-buff), 1) ||
776
 
      !(fields= (*mysql->methods->list_fields)(mysql)))
777
 
    return(NULL);
778
 
 
779
 
  if (!(result = (MYSQL_RES *) my_malloc(sizeof(MYSQL_RES),
780
 
                                         MYF(MY_WME | MY_ZEROFILL))))
781
 
    return(NULL);
782
 
 
783
 
  result->methods= mysql->methods;
784
 
  result->field_alloc=mysql->field_alloc;
785
 
  mysql->fields=0;
786
 
  result->field_count = mysql->field_count;
 
663
      !(fields= (*drizzle->methods->list_fields)(drizzle)))
 
664
    return(NULL);
 
665
 
 
666
  if (!(result = (DRIZZLE_RES *) malloc(sizeof(DRIZZLE_RES))))
 
667
    return(NULL);
 
668
 
 
669
  result->methods= drizzle->methods;
 
670
  result->field_alloc=drizzle->field_alloc;
 
671
  drizzle->fields=0;
 
672
  result->field_count = drizzle->field_count;
787
673
  result->fields= fields;
788
674
  result->eof=1;
789
675
  return(result);
791
677
 
792
678
/* List all running processes (threads) in server */
793
679
 
794
 
MYSQL_RES * STDCALL
795
 
mysql_list_processes(MYSQL *mysql)
 
680
DRIZZLE_RES * STDCALL
 
681
drizzle_list_processes(DRIZZLE *drizzle)
796
682
{
797
 
  MYSQL_DATA *fields;
 
683
  DRIZZLE_DATA *fields;
798
684
  uint field_count;
799
685
  uchar *pos;
800
686
 
801
 
  if (simple_command(mysql,COM_PROCESS_INFO,0,0,0))
 
687
  if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0))
802
688
    return(0);
803
 
  free_old_query(mysql);
804
 
  pos=(uchar*) mysql->net.read_pos;
 
689
  free_old_query(drizzle);
 
690
  pos=(uchar*) drizzle->net.read_pos;
805
691
  field_count=(uint) net_field_length(&pos);
806
 
  if (!(fields = (*mysql->methods->read_rows)(mysql,(MYSQL_FIELD*) 0,
807
 
                                              protocol_41(mysql) ? 7 : 5)))
 
692
  if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0,
 
693
                protocol_41(drizzle) ? 7 : 5)))
808
694
    return(NULL);
809
 
  if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0,
810
 
                                    mysql->server_capabilities)))
 
695
  if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,field_count,0,
 
696
            drizzle->server_capabilities)))
811
697
    return(0);
812
 
  mysql->status=MYSQL_STATUS_GET_RESULT;
813
 
  mysql->field_count=field_count;
814
 
  return(mysql_store_result(mysql));
 
698
  drizzle->status=DRIZZLE_STATUS_GET_RESULT;
 
699
  drizzle->field_count=field_count;
 
700
  return(drizzle_store_result(drizzle));
815
701
}
816
702
 
817
703
 
818
704
#ifdef USE_OLD_FUNCTIONS
819
705
int  STDCALL
820
 
mysql_create_db(MYSQL *mysql, const char *db)
 
706
drizzle_create_db(DRIZZLE *drizzle, const char *db)
821
707
{
822
 
  return(simple_command(mysql,COM_CREATE_DB,db, (ulong) strlen(db),0));
 
708
  return(simple_command(drizzle,COM_CREATE_DB,db, (ulong) strlen(db),0));
823
709
}
824
710
 
825
711
 
826
712
int  STDCALL
827
 
mysql_drop_db(MYSQL *mysql, const char *db)
 
713
drizzle_drop_db(DRIZZLE *drizzle, const char *db)
828
714
{
829
 
  return(simple_command(mysql,COM_DROP_DB,db,(ulong) strlen(db),0));
 
715
  return(simple_command(drizzle,COM_DROP_DB,db,(ulong) strlen(db),0));
830
716
}
831
717
#endif
832
718
 
833
719
 
834
720
int STDCALL
835
 
mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level)
 
721
drizzle_shutdown(DRIZZLE *drizzle, enum drizzle_enum_shutdown_level shutdown_level)
836
722
{
837
723
  uchar level[1];
838
724
  level[0]= (uchar) shutdown_level;
839
 
  return(simple_command(mysql, COM_SHUTDOWN, level, 1, 0));
 
725
  return(simple_command(drizzle, COM_SHUTDOWN, level, 1, 0));
840
726
}
841
727
 
842
728
 
843
729
int STDCALL
844
 
mysql_refresh(MYSQL *mysql,uint options)
 
730
drizzle_refresh(DRIZZLE *drizzle,uint options)
845
731
{
846
732
  uchar bits[1];
847
733
  bits[0]= (uchar) options;
848
 
  return(simple_command(mysql, COM_REFRESH, bits, 1, 0));
 
734
  return(simple_command(drizzle, COM_REFRESH, bits, 1, 0));
849
735
}
850
736
 
851
737
 
852
738
int32_t STDCALL
853
 
mysql_kill(MYSQL *mysql, uint32_t pid)
 
739
drizzle_kill(DRIZZLE *drizzle, uint32_t pid)
854
740
{
855
741
  uchar buff[4];
856
742
  int4store(buff,pid);
857
 
  return(simple_command(mysql,COM_PROCESS_KILL,buff,sizeof(buff),0));
 
743
  return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0));
858
744
}
859
745
 
860
746
 
861
747
int STDCALL
862
 
mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option)
 
748
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option)
863
749
{
864
750
  uchar buff[2];
865
751
  int2store(buff, (uint) option);
866
 
  return(simple_command(mysql, COM_SET_OPTION, buff, sizeof(buff), 0));
 
752
  return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0));
867
753
}
868
754
 
869
755
 
870
 
const char *cli_read_statistics(MYSQL *mysql)
 
756
const char *cli_read_statistics(DRIZZLE *drizzle)
871
757
{
872
 
  mysql->net.read_pos[mysql->packet_length]=0;  /* End of stat string */
873
 
  if (!mysql->net.read_pos[0])
 
758
  drizzle->net.read_pos[drizzle->packet_length]=0;  /* End of stat string */
 
759
  if (!drizzle->net.read_pos[0])
874
760
  {
875
 
    set_mysql_error(mysql, CR_WRONG_HOST_INFO, unknown_sqlstate);
876
 
    return mysql->net.last_error;
 
761
    set_drizzle_error(drizzle, CR_WRONG_HOST_INFO, unknown_sqlstate);
 
762
    return drizzle->net.last_error;
877
763
  }
878
 
  return (char*) mysql->net.read_pos;
 
764
  return (char*) drizzle->net.read_pos;
879
765
}
880
766
 
881
767
 
882
768
const char * STDCALL
883
 
mysql_stat(MYSQL *mysql)
 
769
drizzle_stat(DRIZZLE *drizzle)
884
770
{
885
 
  if (simple_command(mysql,COM_STATISTICS,0,0,0))
886
 
    return(mysql->net.last_error);
887
 
  return((*mysql->methods->read_statistics)(mysql));
 
771
  if (simple_command(drizzle,COM_STATISTICS,0,0,0))
 
772
    return(drizzle->net.last_error);
 
773
  return((*drizzle->methods->read_statistics)(drizzle));
888
774
}
889
775
 
890
776
 
891
777
int STDCALL
892
 
mysql_ping(MYSQL *mysql)
 
778
drizzle_ping(DRIZZLE *drizzle)
893
779
{
894
780
  int res;
895
 
  res= simple_command(mysql,COM_PING,0,0,0);
896
 
  if (res == CR_SERVER_LOST && mysql->reconnect)
897
 
    res= simple_command(mysql,COM_PING,0,0,0);
 
781
  res= simple_command(drizzle,COM_PING,0,0,0);
 
782
  if (res == CR_SERVER_LOST && drizzle->reconnect)
 
783
    res= simple_command(drizzle,COM_PING,0,0,0);
898
784
  return(res);
899
785
}
900
786
 
901
787
 
902
788
const char * STDCALL
903
 
mysql_get_server_info(MYSQL *mysql)
 
789
drizzle_get_server_info(DRIZZLE *drizzle)
904
790
{
905
 
  return((char*) mysql->server_version);
 
791
  return((char*) drizzle->server_version);
906
792
}
907
793
 
908
794
 
909
795
const char * STDCALL
910
 
mysql_get_host_info(MYSQL *mysql)
 
796
drizzle_get_host_info(DRIZZLE *drizzle)
911
797
{
912
 
  return(mysql->host_info);
 
798
  return(drizzle->host_info);
913
799
}
914
800
 
915
801
 
916
802
uint STDCALL
917
 
mysql_get_proto_info(MYSQL *mysql)
 
803
drizzle_get_proto_info(DRIZZLE *drizzle)
918
804
{
919
 
  return (mysql->protocol_version);
 
805
  return (drizzle->protocol_version);
920
806
}
921
807
 
922
808
const char * STDCALL
923
 
mysql_get_client_info(void)
 
809
drizzle_get_client_info(void)
924
810
{
925
811
  return (char*) MYSQL_SERVER_VERSION;
926
812
}
927
813
 
928
 
uint32_t STDCALL mysql_get_client_version(void)
 
814
uint32_t STDCALL drizzle_get_client_version(void)
929
815
{
930
816
  return MYSQL_VERSION_ID;
931
817
}
932
818
 
933
 
my_bool STDCALL mysql_eof(MYSQL_RES *res)
 
819
bool STDCALL drizzle_eof(DRIZZLE_RES *res)
934
820
{
935
821
  return res->eof;
936
822
}
937
823
 
938
 
MYSQL_FIELD * STDCALL mysql_fetch_field_direct(MYSQL_RES *res,uint fieldnr)
 
824
DRIZZLE_FIELD * STDCALL drizzle_fetch_field_direct(DRIZZLE_RES *res,uint fieldnr)
939
825
{
940
826
  return &(res)->fields[fieldnr];
941
827
}
942
828
 
943
 
MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res)
 
829
DRIZZLE_FIELD * STDCALL drizzle_fetch_fields(DRIZZLE_RES *res)
944
830
{
945
831
  return (res)->fields;
946
832
}
947
833
 
948
 
MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res)
 
834
DRIZZLE_ROW_OFFSET STDCALL DRIZZLE_ROW_tell(DRIZZLE_RES *res)
949
835
{
950
836
  return res->data_cursor;
951
837
}
952
838
 
953
 
MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res)
 
839
DRIZZLE_FIELD_OFFSET STDCALL drizzle_field_tell(DRIZZLE_RES *res)
954
840
{
955
841
  return (res)->current_field;
956
842
}
957
843
 
958
 
/* MYSQL */
959
 
 
960
 
unsigned int STDCALL mysql_field_count(MYSQL *mysql)
961
 
{
962
 
  return mysql->field_count;
963
 
}
964
 
 
965
 
uint64_t STDCALL mysql_affected_rows(MYSQL *mysql)
966
 
{
967
 
  return mysql->affected_rows;
968
 
}
969
 
 
970
 
uint64_t STDCALL mysql_insert_id(MYSQL *mysql)
971
 
{
972
 
  return mysql->insert_id;
973
 
}
974
 
 
975
 
const char *STDCALL mysql_sqlstate(MYSQL *mysql)
976
 
{
977
 
  return mysql ? mysql->net.sqlstate : cant_connect_sqlstate;
978
 
}
979
 
 
980
 
uint32_t STDCALL mysql_warning_count(MYSQL *mysql)
981
 
{
982
 
  return mysql->warning_count;
983
 
}
984
 
 
985
 
const char *STDCALL mysql_info(MYSQL *mysql)
986
 
{
987
 
  return mysql->info;
988
 
}
989
 
 
990
 
uint32_t STDCALL mysql_thread_id(MYSQL *mysql)
991
 
{
992
 
  return (mysql)->thread_id;
993
 
}
994
 
 
995
 
const char * STDCALL mysql_character_set_name(MYSQL *mysql)
996
 
{
997
 
  return mysql->charset->csname;
998
 
}
999
 
 
1000
 
void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *csinfo)
1001
 
{
1002
 
  csinfo->number   = mysql->charset->number;
1003
 
  csinfo->state    = mysql->charset->state;
1004
 
  csinfo->csname   = mysql->charset->csname;
1005
 
  csinfo->name     = mysql->charset->name;
1006
 
  csinfo->comment  = mysql->charset->comment;
1007
 
  csinfo->mbminlen = mysql->charset->mbminlen;
1008
 
  csinfo->mbmaxlen = mysql->charset->mbmaxlen;
1009
 
 
1010
 
  if (mysql->options.charset_dir)
1011
 
    csinfo->dir = mysql->options.charset_dir;
 
844
/* DRIZZLE */
 
845
 
 
846
unsigned int STDCALL drizzle_field_count(DRIZZLE *drizzle)
 
847
{
 
848
  return drizzle->field_count;
 
849
}
 
850
 
 
851
uint64_t STDCALL drizzle_affected_rows(DRIZZLE *drizzle)
 
852
{
 
853
  return drizzle->affected_rows;
 
854
}
 
855
 
 
856
uint64_t STDCALL drizzle_insert_id(DRIZZLE *drizzle)
 
857
{
 
858
  return drizzle->insert_id;
 
859
}
 
860
 
 
861
const char *STDCALL drizzle_sqlstate(DRIZZLE *drizzle)
 
862
{
 
863
  return drizzle ? drizzle->net.sqlstate : cant_connect_sqlstate;
 
864
}
 
865
 
 
866
uint32_t STDCALL drizzle_warning_count(DRIZZLE *drizzle)
 
867
{
 
868
  return drizzle->warning_count;
 
869
}
 
870
 
 
871
const char *STDCALL drizzle_info(DRIZZLE *drizzle)
 
872
{
 
873
  return drizzle->info;
 
874
}
 
875
 
 
876
uint32_t STDCALL drizzle_thread_id(DRIZZLE *drizzle)
 
877
{
 
878
  return (drizzle)->thread_id;
 
879
}
 
880
 
 
881
const char * STDCALL drizzle_character_set_name(DRIZZLE *drizzle)
 
882
{
 
883
  return drizzle->charset->csname;
 
884
}
 
885
 
 
886
void STDCALL drizzle_get_character_set_info(DRIZZLE *drizzle, MY_CHARSET_INFO *csinfo)
 
887
{
 
888
  csinfo->number   = drizzle->charset->number;
 
889
  csinfo->state    = drizzle->charset->state;
 
890
  csinfo->csname   = drizzle->charset->csname;
 
891
  csinfo->name     = drizzle->charset->name;
 
892
  csinfo->comment  = drizzle->charset->comment;
 
893
  csinfo->mbminlen = drizzle->charset->mbminlen;
 
894
  csinfo->mbmaxlen = drizzle->charset->mbmaxlen;
 
895
 
 
896
  if (drizzle->options.charset_dir)
 
897
    csinfo->dir = drizzle->options.charset_dir;
1012
898
  else
1013
899
    csinfo->dir = charsets_dir;
1014
900
}
1015
901
 
1016
 
uint STDCALL mysql_thread_safe(void)
 
902
uint STDCALL drizzle_thread_safe(void)
1017
903
{
1018
904
  return 1;
1019
905
}
1020
906
 
1021
907
 
1022
 
my_bool STDCALL mysql_embedded(void)
 
908
bool STDCALL drizzle_embedded(void)
1023
909
{
1024
910
#ifdef EMBEDDED_LIBRARY
1025
 
  return 1;
 
911
  return true;
1026
912
#else
1027
 
  return 0;
 
913
  return false;
1028
914
#endif
1029
915
}
1030
916
 
1048
934
/*
1049
935
  This function is used to create HEX string that you
1050
936
  can use in a SQL statement in of the either ways:
1051
 
    INSERT INTO blob_column VALUES (0xAABBCC);  (any MySQL version)
 
937
    INSERT INTO blob_column VALUES (0xAABBCC);  (any DRIZZLE version)
1052
938
    INSERT INTO blob_column VALUES (X'AABBCC'); (4.1 and higher)
1053
939
  
1054
940
  The string in "from" is encoded to a HEX string.
1057
943
  The string pointed to by "from" must be "length" bytes long.
1058
944
  You must allocate the "to" buffer to be at least length*2+1 bytes long.
1059
945
  Each character needs two bytes, and you need room for the terminating
1060
 
  null byte. When mysql_hex_string() returns, the contents of "to" will
 
946
  null byte. When drizzle_hex_string() returns, the contents of "to" will
1061
947
  be a null-terminated string. The return value is the length of the
1062
948
  encoded string, not including the terminating null character.
1063
949
 
1066
952
*/
1067
953
 
1068
954
uint32_t STDCALL
1069
 
mysql_hex_string(char *to, const char *from, uint32_t length)
 
955
drizzle_hex_string(char *to, const char *from, uint32_t length)
1070
956
{
1071
957
  char *to0= to;
1072
958
  const char *end;
1087
973
*/
1088
974
 
1089
975
uint32_t STDCALL
1090
 
mysql_escape_string(char *to,const char *from, uint32_t length)
 
976
drizzle_escape_string(char *to,const char *from, uint32_t length)
1091
977
{
1092
978
  return escape_string_for_mysql(default_charset_info, to, 0, from, length);
1093
979
}
1094
980
 
1095
981
uint32_t STDCALL
1096
 
mysql_real_escape_string(MYSQL *mysql, char *to,const char *from,
1097
 
                         uint32_t length)
 
982
drizzle_real_escape_string(DRIZZLE *drizzle, char *to,const char *from,
 
983
       uint32_t length)
1098
984
{
1099
 
  if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
1100
 
    return escape_quotes_for_mysql(mysql->charset, to, 0, from, length);
1101
 
  return escape_string_for_mysql(mysql->charset, to, 0, from, length);
 
985
  if (drizzle->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)
 
986
    return escape_quotes_for_mysql(drizzle->charset, to, 0, from, length);
 
987
  return escape_string_for_mysql(drizzle->charset, to, 0, from, length);
1102
988
}
1103
989
 
1104
990
void STDCALL
1105
 
myodbc_remove_escape(MYSQL *mysql,char *name)
 
991
myodbc_remove_escape(DRIZZLE *drizzle,char *name)
1106
992
{
1107
993
  char *to;
1108
994
#ifdef USE_MB
1109
 
  my_bool use_mb_flag=use_mb(mysql->charset);
 
995
  bool use_mb_flag=use_mb(drizzle->charset);
1110
996
  char *end=NULL;
1111
997
  if (use_mb_flag)
1112
998
    for (end=name; *end ; end++) ;
1116
1002
  {
1117
1003
#ifdef USE_MB
1118
1004
    int l;
1119
 
    if (use_mb_flag && (l = my_ismbchar( mysql->charset, name , end ) ) )
 
1005
    if (use_mb_flag && (l = my_ismbchar( drizzle->charset, name , end ) ) )
1120
1006
    {
1121
1007
      while (l--)
1122
 
        *to++ = *name++;
 
1008
  *to++ = *name++;
1123
1009
      name--;
1124
1010
      continue;
1125
1011
    }
1131
1017
  *to=0;
1132
1018
}
1133
1019
 
1134
 
int cli_unbuffered_fetch(MYSQL *mysql, char **row)
 
1020
int cli_unbuffered_fetch(DRIZZLE *drizzle, char **row)
1135
1021
{
1136
 
  if (packet_error == cli_safe_read(mysql))
 
1022
  if (packet_error == cli_safe_read(drizzle))
1137
1023
    return 1;
1138
1024
 
1139
 
  *row= ((mysql->net.read_pos[0] == 254) ? NULL :
1140
 
         (char*) (mysql->net.read_pos+1));
 
1025
  *row= ((drizzle->net.read_pos[0] == 254) ? NULL :
 
1026
   (char*) (drizzle->net.read_pos+1));
1141
1027
  return 0;
1142
1028
}
1143
1029
 
1149
1035
  Commit the current transaction
1150
1036
*/
1151
1037
 
1152
 
my_bool STDCALL mysql_commit(MYSQL * mysql)
 
1038
bool STDCALL drizzle_commit(DRIZZLE *drizzle)
1153
1039
{
1154
 
  return((my_bool) mysql_real_query(mysql, "commit", 6));
 
1040
  return((bool) drizzle_real_query(drizzle, "commit", 6));
1155
1041
}
1156
1042
 
1157
1043
/*
1158
1044
  Rollback the current transaction
1159
1045
*/
1160
1046
 
1161
 
my_bool STDCALL mysql_rollback(MYSQL * mysql)
 
1047
bool STDCALL drizzle_rollback(DRIZZLE *drizzle)
1162
1048
{
1163
 
  return((my_bool) mysql_real_query(mysql, "rollback", 8));
 
1049
  return((bool) drizzle_real_query(drizzle, "rollback", 8));
1164
1050
}
1165
1051
 
1166
1052
 
1168
1054
  Set autocommit to either true or false
1169
1055
*/
1170
1056
 
1171
 
my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode)
 
1057
bool STDCALL drizzle_autocommit(DRIZZLE *drizzle, bool auto_mode)
1172
1058
{
1173
 
  return((my_bool) mysql_real_query(mysql, auto_mode ?
 
1059
  return((bool) drizzle_real_query(drizzle, auto_mode ?
1174
1060
                                         "set autocommit=1":"set autocommit=0",
1175
1061
                                         16));
1176
1062
}
1182
1068
 
1183
1069
/*
1184
1070
  Returns true/false to indicate whether any more query results exist
1185
 
  to be read using mysql_next_result()
 
1071
  to be read using drizzle_next_result()
1186
1072
*/
1187
1073
 
1188
 
my_bool STDCALL mysql_more_results(MYSQL *mysql)
 
1074
bool STDCALL drizzle_more_results(DRIZZLE *drizzle)
1189
1075
{
1190
 
  my_bool res;
 
1076
  bool res;
1191
1077
 
1192
 
  res= ((mysql->server_status & SERVER_MORE_RESULTS_EXISTS) ? 1: 0);
 
1078
  res= ((drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) ? 1: 0);
1193
1079
  return(res);
1194
1080
}
1195
1081
 
1197
1083
/*
1198
1084
  Reads and returns the next query results
1199
1085
*/
1200
 
int STDCALL mysql_next_result(MYSQL *mysql)
 
1086
int STDCALL drizzle_next_result(DRIZZLE *drizzle)
1201
1087
{
1202
 
  if (mysql->status != MYSQL_STATUS_READY)
 
1088
  if (drizzle->status != DRIZZLE_STATUS_READY)
1203
1089
  {
1204
 
    set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
 
1090
    set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
1205
1091
    return(1);
1206
1092
  }
1207
1093
 
1208
 
  net_clear_error(&mysql->net);
1209
 
  mysql->affected_rows= ~(uint64_t) 0;
1210
 
 
1211
 
  if (mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
1212
 
    return((*mysql->methods->next_result)(mysql));
1213
 
 
1214
 
  return(-1);                           /* No more results */
1215
 
}
1216
 
 
1217
 
 
1218
 
MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql)
1219
 
{
1220
 
  return (*mysql->methods->use_result)(mysql);
1221
 
}
1222
 
 
1223
 
my_bool STDCALL mysql_read_query_result(MYSQL *mysql)
1224
 
{
1225
 
  return (*mysql->methods->read_query_result)(mysql);
 
1094
  net_clear_error(&drizzle->net);
 
1095
  drizzle->affected_rows= ~(uint64_t) 0;
 
1096
 
 
1097
  if (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS)
 
1098
    return((*drizzle->methods->next_result)(drizzle));
 
1099
 
 
1100
  return(-1);        /* No more results */
 
1101
}
 
1102
 
 
1103
 
 
1104
DRIZZLE_RES * STDCALL drizzle_use_result(DRIZZLE *drizzle)
 
1105
{
 
1106
  return (*drizzle->methods->use_result)(drizzle);
 
1107
}
 
1108
 
 
1109
bool STDCALL drizzle_read_query_result(DRIZZLE *drizzle)
 
1110
{
 
1111
  return (*drizzle->methods->read_query_result)(drizzle);
1226
1112
}
1227
1113