~mkindahl/drizzle/remove-mem-casts

« back to all changes in this revision

Viewing changes to libdrizzle/libdrizzle.c

  • Committer: Brian Aker
  • Date: 2008-07-26 04:51:46 UTC
  • mfrom: (202.1.25 codestyle)
  • Revision ID: brian@tangent.org-20080726045146-ax7ofn8aqnkycjl3
Merge from Monty

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