~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/libdrizzle.cc

Moved the last of the libdrizzleclient calls into Protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
#include <drizzled/global.h>
 
21
#include "libdrizzle_priv.h"
 
22
 
20
23
#include "libdrizzle.h"
21
 
#include "libdrizzle_priv.h"
22
24
#include "errmsg.h"
 
25
#include "pack.h"
 
26
 
23
27
#include <sys/stat.h>
24
28
#include <signal.h>
25
29
#include <time.h>
50
54
 
51
55
#include <stdlib.h>
52
56
#include <string.h>
53
 
 
54
 
#include <sql_common.h>
55
 
#include <drizzled/version.h>
56
 
 
57
 
/* Borrowed from libicu header */
58
 
 
59
 
#define U8_IS_SINGLE(c) (((c)&0x80)==0)
60
 
#define U8_LENGTH(c) \
61
 
    ((uint32_t)(c)<=0x7f ? 1 : \
62
 
        ((uint32_t)(c)<=0x7ff ? 2 : \
63
 
            ((uint32_t)(c)<=0xd7ff ? 3 : \
64
 
                ((uint32_t)(c)<=0xdfff || (uint32_t)(c)>0x10ffff ? 0 : \
65
 
                    ((uint32_t)(c)<=0xffff ? 3 : 4)\
66
 
                ) \
67
 
            ) \
68
 
        ) \
69
 
    )
70
 
 
71
 
 
72
 
#undef net_buffer_length
73
 
#undef max_allowed_packet
74
 
 
75
 
uint32_t     net_buffer_length= 8192;
76
 
uint32_t    max_allowed_packet= 1024L*1024L*1024L;
 
57
#include <mystrings/utf8.h>
 
58
 
 
59
uint32_t net_buffer_length= 8192;
 
60
uint32_t max_allowed_packet= 1024L*1024L*1024L;
77
61
 
78
62
unsigned int drizzle_port=0;
79
63
 
80
64
#include <errno.h>
81
 
#define SOCKET_ERROR -1
82
 
 
83
 
/*
84
 
  If allowed through some configuration, then this needs to
85
 
  be changed
86
 
*/
87
 
#define MAX_LONG_DATA_LENGTH 8192
88
 
#define unsigned_field(A) ((A)->flags & UNSIGNED_FLAG)
89
65
 
90
66
 
91
67
static DRIZZLE_PARAMETERS drizzle_internal_parameters=
92
68
{&max_allowed_packet, &net_buffer_length, 0};
93
69
 
94
 
const DRIZZLE_PARAMETERS * drizzle_get_parameters(void)
 
70
const DRIZZLE_PARAMETERS * drizzleclient_get_parameters(void)
95
71
{
96
72
  return &drizzle_internal_parameters;
97
73
}
98
74
 
99
 
unsigned int drizzle_get_default_port(void)
 
75
unsigned int drizzleclient_get_default_port(void)
100
76
{
101
77
  return drizzle_port;
102
78
}
103
79
 
104
 
void drizzle_set_default_port(unsigned int port)
 
80
void drizzleclient_set_default_port(unsigned int port)
105
81
{
106
82
  drizzle_port= port;
107
83
}
132
108
  }
133
109
}
134
110
 
135
 
/**************************************************************************
136
 
  Change user and database
137
 
**************************************************************************/
138
 
 
139
 
int cli_read_change_user_result(DRIZZLE *drizzle)
140
 
{
141
 
  uint32_t pkt_length;
142
 
 
143
 
  pkt_length= cli_safe_read(drizzle);
144
 
  
145
 
  if (pkt_length == packet_error)
146
 
    return 1;
147
 
 
148
 
  return 0;
149
 
}
150
 
 
151
 
bool drizzle_change_user(DRIZZLE *drizzle, const char *user,
152
 
                                 const char *passwd, const char *db)
153
 
{
154
 
  char buff[USERNAME_LENGTH+SCRAMBLED_PASSWORD_CHAR_LENGTH+NAME_LEN+2];
155
 
  char *end= buff;
156
 
  int rc;
157
 
 
158
 
  /* Use an empty string instead of NULL. */
159
 
 
160
 
  if (!user)
161
 
    user="";
162
 
  if (!passwd)
163
 
    passwd="";
164
 
 
165
 
  /* Store user into the buffer */
166
 
  end= strncpy(end, user, USERNAME_LENGTH) + USERNAME_LENGTH + 1;
167
 
 
168
 
  /* write scrambled password according to server capabilities */
169
 
  if (passwd[0])
170
 
  {
171
 
    {
172
 
      *end++= SCRAMBLE_LENGTH;
173
 
      end+= SCRAMBLE_LENGTH;
174
 
    }
175
 
  }
176
 
  else
177
 
    *end++= '\0';                               /* empty password */
178
 
  /* Add database if needed */
179
 
  end= strncpy(end, db ? db : "", NAME_LEN) + NAME_LEN + 1;
180
 
 
181
 
  /* Add character set number. */
182
 
  if (drizzle->server_capabilities & CLIENT_SECURE_CONNECTION)
183
 
  {
184
 
    int2store(end, (uint16_t) 45); // utf8mb4 number from mystrings/ctype-utf8.c
185
 
    end+= 2;
186
 
  }
187
 
 
188
 
  /* Write authentication package */
189
 
  (void)simple_command(drizzle,COM_CHANGE_USER, (unsigned char*) buff, (uint32_t) (end-buff), 1);
190
 
 
191
 
  rc= (*drizzle->methods->read_change_user_result)(drizzle);
192
 
 
193
 
  if (rc == 0)
194
 
  {
195
 
    /* Free old connect information */
196
 
    if(drizzle->user)
197
 
      free(drizzle->user);
198
 
    if(drizzle->passwd)
199
 
      free(drizzle->passwd);
200
 
    if(drizzle->db)
201
 
      free(drizzle->db);
202
 
 
203
 
    /* alloc new connect information */
204
 
    drizzle->user= strdup(user);
205
 
    drizzle->passwd= strdup(passwd);
206
 
    drizzle->db= db ? strdup(db) : 0;
207
 
  }
208
 
 
209
 
  return(rc);
210
 
}
211
 
 
212
111
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
213
112
struct passwd *getpwuid(uid_t);
214
113
char* getlogin(void);
216
115
 
217
116
/**************************************************************************
218
117
  Do a query. If query returned rows, free old rows.
219
 
  Read data by drizzle_store_result or by repeat call of drizzle_fetch_row
 
118
  Read data by drizzleclient_store_result or by repeat call of drizzleclient_fetch_row
220
119
**************************************************************************/
221
120
 
222
121
int
223
 
drizzle_query(DRIZZLE *drizzle, const char *query)
 
122
drizzleclient_query(DRIZZLE *drizzle, const char *query)
224
123
{
225
 
  return drizzle_real_query(drizzle,query, (uint32_t) strlen(query));
 
124
  return drizzleclient_real_query(drizzle,query, (uint32_t) strlen(query));
226
125
}
227
126
 
228
127
 
231
130
**************************************************************************/
232
131
 
233
132
DRIZZLE_FIELD *
234
 
drizzle_fetch_field(DRIZZLE_RES *result)
 
133
drizzleclient_fetch_field(DRIZZLE_RES *result)
235
134
{
236
135
  if (result->current_field >= result->field_count)
237
136
    return(NULL);
244
143
**************************************************************************/
245
144
 
246
145
void
247
 
drizzle_data_seek(DRIZZLE_RES *result, uint64_t row)
 
146
drizzleclient_data_seek(DRIZZLE_RES *result, uint64_t row)
248
147
{
249
148
  DRIZZLE_ROWS  *tmp=0;
250
149
  if (result->data)
256
155
 
257
156
/*************************************************************************
258
157
  put the row or field cursor one a position one got from DRIZZLE_ROW_tell()
259
 
  This doesn't restore any data. The next drizzle_fetch_row or
260
 
  drizzle_fetch_field will return the next row or field after the last used
 
158
  This doesn't restore any data. The next drizzleclient_fetch_row or
 
159
  drizzleclient_fetch_field will return the next row or field after the last used
261
160
*************************************************************************/
262
161
 
263
162
DRIZZLE_ROW_OFFSET
264
 
drizzle_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET row)
 
163
drizzleclient_row_seek(DRIZZLE_RES *result, DRIZZLE_ROW_OFFSET row)
265
164
{
266
165
  DRIZZLE_ROW_OFFSET return_value=result->data_cursor;
267
166
  result->current_row= 0;
271
170
 
272
171
 
273
172
DRIZZLE_FIELD_OFFSET
274
 
drizzle_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET field_offset)
 
173
drizzleclient_field_seek(DRIZZLE_RES *result, DRIZZLE_FIELD_OFFSET field_offset)
275
174
{
276
175
  DRIZZLE_FIELD_OFFSET return_value=result->current_field;
277
176
  result->current_field=field_offset;
285
184
*****************************************************************************/
286
185
 
287
186
DRIZZLE_RES *
288
 
drizzle_list_tables(DRIZZLE *drizzle, const char *wild)
 
187
drizzleclient_list_tables(DRIZZLE *drizzle, const char *wild)
289
188
{
290
189
  char buff[255];
291
190
  char *ptr= strcpy(buff, "show tables");
292
191
  ptr+= 11; /* strlen("show tables"); */
293
192
 
294
193
  append_wild(ptr,buff+sizeof(buff),wild);
295
 
  if (drizzle_query(drizzle,buff))
 
194
  if (drizzleclient_query(drizzle,buff))
296
195
    return(0);
297
 
  return (drizzle_store_result(drizzle));
 
196
  return (drizzleclient_store_result(drizzle));
298
197
}
299
198
 
300
199
 
301
 
DRIZZLE_FIELD *cli_list_fields(DRIZZLE *drizzle)
 
200
DRIZZLE_FIELD *drizzleclient_cli_list_fields(DRIZZLE *drizzle)
302
201
{
303
202
  DRIZZLE_DATA *query;
304
 
  if (!(query= cli_read_rows(drizzle,(DRIZZLE_FIELD*) 0, 8)))
 
203
  if (!(query= drizzleclient_cli_read_rows(drizzle,(DRIZZLE_FIELD*) 0, 8)))
305
204
    return NULL;
306
205
 
307
206
  drizzle->field_count= (uint32_t) query->rows;
308
 
  return unpack_fields(query, drizzle->field_count, 1);
309
 
}
310
 
 
311
 
 
312
 
/**************************************************************************
313
 
  List all fields in a table
314
 
  If wild is given then only the fields matching wild is returned
315
 
  Instead of this use query:
316
 
  show fields in 'table' like "wild"
317
 
**************************************************************************/
318
 
 
319
 
DRIZZLE_RES *
320
 
drizzle_list_fields(DRIZZLE *drizzle, const char *table, const char *wild)
321
 
{
322
 
  DRIZZLE_RES   *result;
323
 
  DRIZZLE_FIELD *fields;
324
 
  char buff[257], *end;
325
 
 
326
 
  end= strncpy(buff, table, 128) + 128;
327
 
  end= strncpy(end+1, wild ? wild : "", 128) + 128;
328
 
 
329
 
  free_old_query(drizzle);
330
 
  if (simple_command(drizzle, COM_FIELD_LIST, (unsigned char*) buff,
331
 
                     (uint32_t) (end-buff), 1) ||
332
 
      !(fields= (*drizzle->methods->list_fields)(drizzle)))
333
 
    return(NULL);
334
 
 
335
 
  if (!(result = (DRIZZLE_RES *) malloc(sizeof(DRIZZLE_RES))))
336
 
    return(NULL);
337
 
 
338
 
  memset(result, 0, sizeof(DRIZZLE_RES));
339
 
 
340
 
  result->methods= drizzle->methods;
341
 
  drizzle->fields=0;
342
 
  result->field_count = drizzle->field_count;
343
 
  result->fields= fields;
344
 
  result->eof=1;
345
 
  return(result);
346
 
}
347
 
 
348
 
/* List all running processes (threads) in server */
349
 
 
350
 
DRIZZLE_RES *
351
 
drizzle_list_processes(DRIZZLE *drizzle)
352
 
{
353
 
  DRIZZLE_DATA *fields;
354
 
  uint32_t field_count;
355
 
  unsigned char *pos;
356
 
 
357
 
  if (simple_command(drizzle,COM_PROCESS_INFO,0,0,0))
358
 
    return(0);
359
 
  free_old_query(drizzle);
360
 
  pos=(unsigned char*) drizzle->net.read_pos;
361
 
  field_count=(uint32_t) net_field_length(&pos);
362
 
  if (!(fields = (*drizzle->methods->read_rows)(drizzle,(DRIZZLE_FIELD*) 0, 7)))
363
 
    return(NULL);
364
 
  if (!(drizzle->fields=unpack_fields(fields, field_count, 0)))
365
 
    return(0);
366
 
  drizzle->status=DRIZZLE_STATUS_GET_RESULT;
367
 
  drizzle->field_count=field_count;
368
 
  return(drizzle_store_result(drizzle));
369
 
}
370
 
 
 
207
  return drizzleclient_unpack_fields(query, drizzle->field_count, 1);
 
208
}
371
209
 
372
210
int
373
 
drizzle_shutdown(DRIZZLE *drizzle)
 
211
drizzleclient_shutdown(DRIZZLE *drizzle)
374
212
{
375
213
  return(simple_command(drizzle, COM_SHUTDOWN, 0, 0, 0));
376
214
}
377
215
 
378
216
 
379
 
int
380
 
drizzle_refresh(DRIZZLE *drizzle, uint32_t options)
381
 
{
382
 
  unsigned char bits[1];
383
 
  bits[0]= (unsigned char) options;
384
 
  return(simple_command(drizzle, COM_REFRESH, bits, 1, 0));
385
 
}
386
 
 
387
 
 
388
 
int32_t
389
 
drizzle_kill(DRIZZLE *drizzle, uint32_t pid)
390
 
{
391
 
  unsigned char buff[4];
392
 
  int4store(buff,pid);
393
 
  return(simple_command(drizzle,COM_PROCESS_KILL,buff,sizeof(buff),0));
394
 
}
395
 
 
396
 
 
397
 
int
398
 
drizzle_set_server_option(DRIZZLE *drizzle, enum enum_drizzle_set_option option)
399
 
{
400
 
  unsigned char buff[2];
401
 
  int2store(buff, (uint32_t) option);
402
 
  return(simple_command(drizzle, COM_SET_OPTION, buff, sizeof(buff), 0));
403
 
}
404
 
 
405
 
 
406
 
const char *cli_read_statistics(DRIZZLE *drizzle)
 
217
const char *drizzleclient_cli_read_statistics(DRIZZLE *drizzle)
407
218
{
408
219
  drizzle->net.read_pos[drizzle->packet_length]=0;  /* End of stat string */
409
220
  if (!drizzle->net.read_pos[0])
410
221
  {
411
 
    drizzle_set_error(drizzle, CR_WRONG_HOST_INFO, sqlstate_get_unknown());
 
222
    drizzleclient_set_error(drizzle, CR_WRONG_HOST_INFO, drizzleclient_sqlstate_get_unknown());
412
223
    return drizzle->net.last_error;
413
224
  }
414
225
  return (char*) drizzle->net.read_pos;
416
227
 
417
228
 
418
229
int
419
 
drizzle_ping(DRIZZLE *drizzle)
 
230
drizzleclient_ping(DRIZZLE *drizzle)
420
231
{
421
232
  int res;
422
233
  res= simple_command(drizzle,COM_PING,0,0,0);
427
238
 
428
239
 
429
240
const char *
430
 
drizzle_get_server_info(const DRIZZLE *drizzle)
 
241
drizzleclient_get_server_info(const DRIZZLE *drizzle)
431
242
{
432
243
  return((char*) drizzle->server_version);
433
244
}
434
245
 
435
246
 
436
247
const char *
437
 
drizzle_get_host_info(const DRIZZLE *drizzle)
 
248
drizzleclient_get_host_info(const DRIZZLE *drizzle)
438
249
{
439
250
  return(drizzle->host_info);
440
251
}
441
252
 
442
253
 
443
254
uint32_t
444
 
drizzle_get_proto_info(const DRIZZLE *drizzle)
 
255
drizzleclient_get_proto_info(const DRIZZLE *drizzle)
445
256
{
446
257
  return (drizzle->protocol_version);
447
258
}
448
259
 
449
260
const char *
450
 
drizzle_get_client_info(void)
 
261
drizzleclient_get_client_info(void)
451
262
{
452
 
  return (char*) DRIZZLE_SERVER_VERSION;
 
263
  return (char*) VERSION;
453
264
}
454
265
 
455
 
uint32_t drizzle_get_client_version(void)
 
266
uint32_t drizzleclient_get_client_version(void)
456
267
{
457
268
  return DRIZZLE_VERSION_ID;
458
269
}
459
270
 
460
 
bool drizzle_eof(const DRIZZLE_RES *res)
 
271
bool drizzleclient_eof(const DRIZZLE_RES *res)
461
272
{
462
273
  return res->eof;
463
274
}
464
275
 
465
 
const DRIZZLE_FIELD * drizzle_fetch_field_direct(const DRIZZLE_RES *res, unsigned int fieldnr)
 
276
const DRIZZLE_FIELD * drizzleclient_fetch_field_direct(const DRIZZLE_RES *res, unsigned int fieldnr)
466
277
{
467
278
  return &(res)->fields[fieldnr];
468
279
}
469
280
 
470
 
const DRIZZLE_FIELD * drizzle_fetch_fields(const DRIZZLE_RES *res)
 
281
const DRIZZLE_FIELD * drizzleclient_fetch_fields(const DRIZZLE_RES *res)
471
282
{
472
283
  return res->fields;
473
284
}
474
285
 
475
 
DRIZZLE_ROW_OFFSET drizzle_row_tell(const DRIZZLE_RES *res)
 
286
DRIZZLE_ROW_OFFSET drizzleclient_row_tell(const DRIZZLE_RES *res)
476
287
{
477
288
  return res->data_cursor;
478
289
}
479
290
 
480
 
DRIZZLE_FIELD_OFFSET drizzle_field_tell(const DRIZZLE_RES *res)
 
291
DRIZZLE_FIELD_OFFSET drizzleclient_field_tell(const DRIZZLE_RES *res)
481
292
{
482
293
  return res->current_field;
483
294
}
484
295
 
485
296
/* DRIZZLE */
486
297
 
487
 
unsigned int drizzle_field_count(const DRIZZLE *drizzle)
 
298
unsigned int drizzleclient_field_count(const DRIZZLE *drizzle)
488
299
{
489
300
  return drizzle->field_count;
490
301
}
491
302
 
492
 
uint64_t drizzle_affected_rows(const DRIZZLE *drizzle)
 
303
uint64_t drizzleclient_affected_rows(const DRIZZLE *drizzle)
493
304
{
494
305
  return drizzle->affected_rows;
495
306
}
496
307
 
497
 
uint64_t drizzle_insert_id(const DRIZZLE *drizzle)
 
308
uint64_t drizzleclient_insert_id(const DRIZZLE *drizzle)
498
309
{
499
310
  return drizzle->insert_id;
500
311
}
501
312
 
502
 
const char * drizzle_sqlstate(const DRIZZLE *drizzle)
 
313
const char * drizzleclient_sqlstate(const DRIZZLE *drizzle)
503
314
{
504
 
  return drizzle ? drizzle->net.sqlstate : sqlstate_get_cant_connect();
 
315
  return drizzle ? drizzle->net.sqlstate : drizzleclient_sqlstate_get_cant_connect();
505
316
}
506
317
 
507
 
uint32_t drizzle_warning_count(const DRIZZLE *drizzle)
 
318
uint32_t drizzleclient_warning_count(const DRIZZLE *drizzle)
508
319
{
509
320
  return drizzle->warning_count;
510
321
}
511
322
 
512
 
const char * drizzle_info(const DRIZZLE *drizzle)
 
323
const char * drizzleclient_info(const DRIZZLE *drizzle)
513
324
{
514
325
  return drizzle->info;
515
326
}
516
327
 
517
 
uint32_t drizzle_thread_id(const DRIZZLE *drizzle)
 
328
uint32_t drizzleclient_thread_id(const DRIZZLE *drizzle)
518
329
{
519
330
  return drizzle->thread_id;
520
331
}
524
335
****************************************************************************/
525
336
 
526
337
/*
527
 
  Functions called my my_net_init() to set some application specific variables
528
 
*/
529
 
 
530
 
void my_net_local_init(NET *net)
531
 
{
532
 
  net->max_packet=   (uint32_t) net_buffer_length;
533
 
  my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
534
 
  my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
535
 
  net->retry_count=  1;
536
 
  net->max_packet_size= (net_buffer_length > max_allowed_packet) ?
537
 
    net_buffer_length : max_allowed_packet;
538
 
}
539
 
 
540
 
/*
541
 
  This function is used to create HEX string that you
542
 
  can use in a SQL statement in of the either ways:
543
 
    INSERT INTO blob_column VALUES (0xAABBCC);  (any DRIZZLE version)
544
 
    INSERT INTO blob_column VALUES (X'AABBCC'); 
545
 
  
546
 
  The string in "from" is encoded to a HEX string.
547
 
  The result is placed in "to" and a terminating null byte is appended.
548
 
  
549
 
  The string pointed to by "from" must be "length" bytes long.
550
 
  You must allocate the "to" buffer to be at least length*2+1 bytes long.
551
 
  Each character needs two bytes, and you need room for the terminating
552
 
  null byte. When drizzle_hex_string() returns, the contents of "to" will
553
 
  be a null-terminated string. The return value is the length of the
554
 
  encoded string, not including the terminating null character.  The return value does not contain any leading 0x or a leading X' and
555
 
  trailing '. The caller must supply whichever of those is desired.
556
 
*/
557
 
 
558
 
uint32_t
559
 
drizzle_hex_string(char *to, const char *from, uint32_t length)
560
 
{
561
 
  char *to0= to;
562
 
  const char *end;
563
 
            
564
 
  for (end= from + length; from < end; from++)
565
 
  {
566
 
    *to++= _dig_vec_upper[((unsigned char) *from) >> 4];
567
 
    *to++= _dig_vec_upper[((unsigned char) *from) & 0x0F];
568
 
  }
569
 
  *to= '\0';
570
 
  return (uint32_t) (to-to0);
571
 
}
572
 
 
573
 
/*
574
338
  Add escape characters to a string (blob?) to make it suitable for a insert
575
339
  to should at least have place for length*2+1 chars
576
340
  Returns the length of the to string
577
341
*/
578
342
 
579
343
uint32_t
580
 
drizzle_escape_string(char *to,const char *from, uint32_t length)
 
344
drizzleclient_escape_string(char *to,const char *from, uint32_t length)
581
345
{
582
346
  const char *to_start= to;
583
347
  const char *end, *to_end=to_start + 2*length;
588
352
    char escape= 0;
589
353
    if (!U8_IS_SINGLE(*from))
590
354
    {
591
 
      tmp_length= U8_LENGTH(*from);
 
355
      tmp_length= U8_LENGTH(*(uint32_t*)from);
592
356
      if (to + tmp_length > to_end)
593
357
      {
594
358
        overflow= true;
646
410
  return overflow ? (size_t) -1 : (size_t) (to - to_start);
647
411
}
648
412
 
649
 
int cli_unbuffered_fetch(DRIZZLE *drizzle, char **row)
 
413
int drizzleclient_cli_unbuffered_fetch(DRIZZLE *drizzle, char **row)
650
414
{
651
 
  if (packet_error == cli_safe_read(drizzle))
 
415
  if (packet_error == drizzleclient_cli_safe_read(drizzle))
652
416
    return 1;
653
417
 
654
418
  *row= ((drizzle->net.read_pos[0] == DRIZZLE_PROTOCOL_NO_MORE_DATA) ? NULL :
664
428
  Commit the current transaction
665
429
*/
666
430
 
667
 
bool drizzle_commit(DRIZZLE *drizzle)
 
431
bool drizzleclient_commit(DRIZZLE *drizzle)
668
432
{
669
 
  return((bool) drizzle_real_query(drizzle, "commit", 6));
 
433
  return((bool) drizzleclient_real_query(drizzle, "commit", 6));
670
434
}
671
435
 
672
436
/*
673
437
  Rollback the current transaction
674
438
*/
675
439
 
676
 
bool drizzle_rollback(DRIZZLE *drizzle)
 
440
bool drizzleclient_rollback(DRIZZLE *drizzle)
677
441
{
678
 
  return((bool) drizzle_real_query(drizzle, "rollback", 8));
 
442
  return((bool) drizzleclient_real_query(drizzle, "rollback", 8));
679
443
}
680
444
 
681
445
 
683
447
  Set autocommit to either true or false
684
448
*/
685
449
 
686
 
bool drizzle_autocommit(DRIZZLE *drizzle, bool auto_mode)
 
450
bool drizzleclient_autocommit(DRIZZLE *drizzle, bool auto_mode)
687
451
{
688
 
  return((bool) drizzle_real_query(drizzle, auto_mode ?
 
452
  return((bool) drizzleclient_real_query(drizzle, auto_mode ?
689
453
                                         "set autocommit=1":"set autocommit=0",
690
454
                                         16));
691
455
}
697
461
 
698
462
/*
699
463
  Returns true/false to indicate whether any more query results exist
700
 
  to be read using drizzle_next_result()
 
464
  to be read using drizzleclient_next_result()
701
465
*/
702
466
 
703
 
bool drizzle_more_results(const DRIZZLE *drizzle)
 
467
bool drizzleclient_more_results(const DRIZZLE *drizzle)
704
468
{
705
469
  return (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS) ? true:false;
706
470
}
709
473
/*
710
474
  Reads and returns the next query results
711
475
*/
712
 
int drizzle_next_result(DRIZZLE *drizzle)
 
476
int drizzleclient_next_result(DRIZZLE *drizzle)
713
477
{
714
478
  if (drizzle->status != DRIZZLE_STATUS_READY)
715
479
  {
716
 
    drizzle_set_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, sqlstate_get_unknown());
 
480
    drizzleclient_set_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, drizzleclient_sqlstate_get_unknown());
717
481
    return(1);
718
482
  }
719
483
 
720
 
  net_clear_error(&drizzle->net);
 
484
  drizzleclient_drizzleclient_net_clear_error(&drizzle->net);
721
485
  drizzle->affected_rows= ~(uint64_t) 0;
722
486
 
723
487
  if (drizzle->server_status & SERVER_MORE_RESULTS_EXISTS)
727
491
}
728
492
 
729
493
 
730
 
DRIZZLE_RES * drizzle_use_result(DRIZZLE *drizzle)
 
494
DRIZZLE_RES * drizzleclient_use_result(DRIZZLE *drizzle)
731
495
{
732
496
  return (*drizzle->methods->use_result)(drizzle);
733
497
}
734
498
 
735
 
bool drizzle_read_query_result(DRIZZLE *drizzle)
 
499
bool drizzleclient_read_query_result(DRIZZLE *drizzle)
736
500
{
737
501
  return (*drizzle->methods->read_query_result)(drizzle);
738
502
}