156
178
drizzle_st *drizzle_con_drizzle(const drizzle_con_st *con)
158
184
return con->drizzle;
161
187
const char *drizzle_con_error(const drizzle_con_st *con)
163
194
return drizzle_error(con->drizzle);
166
197
int drizzle_con_errno(const drizzle_con_st *con)
168
204
return drizzle_errno(con->drizzle);
171
207
uint16_t drizzle_con_error_code(const drizzle_con_st *con)
173
214
return drizzle_error_code(con->drizzle);
176
217
const char *drizzle_con_sqlstate(const drizzle_con_st *con)
178
224
return drizzle_sqlstate(con->drizzle);
181
227
drizzle_con_options_t drizzle_con_options(const drizzle_con_st *con)
231
return drizzle_con_options_t();
183
234
return drizzle_con_options_t(con->options);
186
237
void drizzle_con_set_options(drizzle_con_st *con,
187
238
drizzle_con_options_t options)
189
245
con->options= options;
192
248
void drizzle_con_add_options(drizzle_con_st *con,
193
249
drizzle_con_options_t options)
195
256
con->options|= options;
197
258
/* If asking for the experimental Drizzle protocol, clean the MySQL flag. */
204
265
void drizzle_con_remove_options(drizzle_con_st *con,
205
266
drizzle_con_options_t options)
207
273
con->options&= ~options;
210
276
const char *drizzle_con_host(const drizzle_con_st *con)
212
283
if (con->socket_type == DRIZZLE_CON_SOCKET_TCP)
214
285
if (con->socket.tcp.host == NULL && !(con->options & DRIZZLE_CON_LISTEN))
223
294
in_port_t drizzle_con_port(const drizzle_con_st *con)
225
if (con->socket_type == DRIZZLE_CON_SOCKET_TCP)
296
if (con and con->socket_type == DRIZZLE_CON_SOCKET_TCP)
227
298
if (con->socket.tcp.port != 0)
228
300
return con->socket.tcp.port;
230
303
if (con->options & DRIZZLE_CON_MYSQL)
231
305
return DRIZZLE_DEFAULT_TCP_PORT_MYSQL;
233
308
return DRIZZLE_DEFAULT_TCP_PORT;
239
314
void drizzle_con_set_tcp(drizzle_con_st *con, const char *host, in_port_t port)
241
321
drizzle_con_reset_addrinfo(con);
243
323
con->socket_type= DRIZZLE_CON_SOCKET_TCP;
245
325
if (host == NULL)
246
327
con->socket.tcp.host= NULL;
249
331
con->socket.tcp.host= con->socket.tcp.host_buffer;
257
339
const char *drizzle_con_user(const drizzle_con_st *con)
259
346
return con->user;
262
349
const char *drizzle_con_password(const drizzle_con_st *con)
264
356
return con->password;
267
359
void drizzle_con_set_auth(drizzle_con_st *con, const char *user,
268
360
const char *password)
270
367
if (user == NULL)
274
373
strncpy(con->user, user, DRIZZLE_MAX_USER_SIZE);
287
388
const char *drizzle_con_db(const drizzle_con_st *con)
292
398
void drizzle_con_set_db(drizzle_con_st *con, const char *db)
298
411
strncpy(con->db, db, DRIZZLE_MAX_DB_SIZE);
303
416
void *drizzle_con_context(const drizzle_con_st *con)
305
423
return con->context;
308
426
void drizzle_con_set_context(drizzle_con_st *con, void *context)
310
433
con->context= context;
313
436
void drizzle_con_set_context_free_fn(drizzle_con_st *con,
314
437
drizzle_con_context_free_fn *function)
316
444
con->context_free_fn= function;
319
447
uint8_t drizzle_con_protocol_version(const drizzle_con_st *con)
321
454
return con->protocol_version;
324
457
const char *drizzle_con_server_version(const drizzle_con_st *con)
326
464
return con->server_version;
329
467
uint32_t drizzle_con_server_version_number(const drizzle_con_st *con)
337
current= con->server_version;
339
major= (uint32_t)strtoul(current, &end, 10);
341
minor= (uint32_t)strtoul(current, &end, 10);
343
version= (uint32_t)strtoul(current, &end, 10);
345
return (major * 10000) + (minor * 100) + version;
471
const char *current= con->server_version;
474
uint32_t major= (uint32_t)strtoul(current, &end, 10);
476
uint32_t minor= (uint32_t)strtoul(current, &end, 10);
478
uint32_t version= (uint32_t)strtoul(current, &end, 10);
480
return (major * 10000) +(minor * 100) +version;
348
486
uint32_t drizzle_con_thread_id(const drizzle_con_st *con)
350
493
return con->thread_id;
353
496
const uint8_t *drizzle_con_scramble(const drizzle_con_st *con)
355
503
return con->scramble;
358
506
drizzle_capabilities_t drizzle_con_capabilities(const drizzle_con_st *con)
510
return drizzle_capabilities_t();
360
513
return drizzle_capabilities_t(con->capabilities);
363
516
drizzle_charset_t drizzle_con_charset(const drizzle_con_st *con)
520
return drizzle_charset_t();
365
523
return con->charset;
368
526
drizzle_con_status_t drizzle_con_status(const drizzle_con_st *con)
530
return drizzle_con_status_t();
370
533
return con->status;
373
536
uint32_t drizzle_con_max_packet_size(const drizzle_con_st *con)
375
543
return con->max_packet_size;
382
550
drizzle_return_t drizzle_con_connect(drizzle_con_st *con)
554
return DRIZZLE_RETURN_INVALID_ARGUMENT;
384
557
if (con->options & DRIZZLE_CON_READY)
385
559
return DRIZZLE_RETURN_OK;
387
562
if (drizzle_state_none(con))
436
611
drizzle_result_st *result,
437
612
drizzle_return_t *ret_ptr)
439
if (con->options & DRIZZLE_CON_MYSQL)
614
drizzle_return_t unused;
620
if (con and con->options & DRIZZLE_CON_MYSQL)
441
622
return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_SHUTDOWN,
442
623
"0", 1, 1, ret_ptr);
449
630
drizzle_result_st *drizzle_shutdown(drizzle_con_st *con,
450
drizzle_result_st *result, uint32_t level,
631
drizzle_result_st *result, uint32_t, // level is unused
451
632
drizzle_return_t *ret_ptr)
454
634
return drizzle_con_shutdown(con, result, ret_ptr);
459
639
uint32_t query_id,
460
640
drizzle_return_t *ret_ptr)
642
drizzle_return_t unused;
462
648
uint32_t sent= htonl(query_id);
463
649
return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_PROCESS_KILL,
464
650
&sent, sizeof(uint32_t), sizeof(uint32_t), ret_ptr);
487
673
drizzle_return_t *ret_ptr)
675
drizzle_return_t unused;
683
*ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
489
687
drizzle_result_st *old_result;
491
drizzle_return_t unused;
497
689
if (!(con->options & DRIZZLE_CON_READY))
499
691
if (con->options & DRIZZLE_CON_RAW_PACKET)
568
760
drizzle_return_t drizzle_con_listen(drizzle_con_st *con)
764
return DRIZZLE_RETURN_INVALID_ARGUMENT;
570
767
if (con->options & DRIZZLE_CON_READY)
571
769
return DRIZZLE_RETURN_OK;
573
772
if (drizzle_state_none(con))
582
781
int drizzle_con_backlog(const drizzle_con_st *con)
584
788
return con->backlog;
587
791
void drizzle_con_set_backlog(drizzle_con_st *con, int backlog)
589
798
con->backlog= backlog;
592
801
void drizzle_con_set_protocol_version(drizzle_con_st *con,
593
802
uint8_t protocol_version)
595
809
con->protocol_version= protocol_version;
598
812
void drizzle_con_set_server_version(drizzle_con_st *con,
599
813
const char *server_version)
601
820
if (server_version == NULL)
602
822
con->server_version[0]= 0;
605
826
strncpy(con->server_version, server_version,
611
832
void drizzle_con_set_thread_id(drizzle_con_st *con, uint32_t thread_id)
613
839
con->thread_id= thread_id;
616
842
void drizzle_con_set_scramble(drizzle_con_st *con, const uint8_t *scramble)
618
849
if (scramble == NULL)
619
851
con->scramble= NULL;
622
855
con->scramble= con->scramble_buffer;
627
860
void drizzle_con_set_capabilities(drizzle_con_st *con,
628
861
drizzle_capabilities_t capabilities)
630
868
con->capabilities= capabilities;
633
871
void drizzle_con_set_charset(drizzle_con_st *con, drizzle_charset_t charset)
635
878
con->charset= charset;
638
881
void drizzle_con_set_status(drizzle_con_st *con, drizzle_con_status_t status)
640
888
con->status= status;
643
891
void drizzle_con_set_max_packet_size(drizzle_con_st *con,
644
892
uint32_t max_packet_size)
646
899
con->max_packet_size= max_packet_size;
666
919
size_t *size, size_t *total,
667
920
drizzle_return_t *ret_ptr)
922
drizzle_return_t unused_ret;
925
ret_ptr= &unused_ret;
930
*ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
669
934
if (drizzle_state_none(con))
671
936
con->packet_number= 0;
676
941
drizzle_state_push(con, drizzle_state_packet_read);
679
*offset= con->command_offset;
946
*offset= con->command_offset;
681
949
*ret_ptr= drizzle_state_loop(con);
682
950
if (*ret_ptr == DRIZZLE_RETURN_PAUSE)
683
952
*ret_ptr= DRIZZLE_RETURN_OK;
685
*command= con->command;
686
*size= con->command_size;
687
*total= con->command_total;
957
*command= con->command;
962
*size= con->command_size;
967
*total= con->command_total;
689
970
return con->command_data;
696
977
size_t offset= 0;
980
drizzle_return_t unused_ret;
983
ret_ptr= &unused_ret;
989
total= &unused_total;
994
*ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
699
998
char *command_data= (char *)drizzle_con_command_read(con, command, &offset, &size, total, ret_ptr);
700
999
if (*ret_ptr != DRIZZLE_RETURN_OK)
703
1004
if (command_data == NULL)
724
1025
command_data= (char *)drizzle_con_command_read(con, command, &offset, &size, total, ret_ptr);
725
1026
if (*ret_ptr != DRIZZLE_RETURN_OK)
728
1031
memcpy(con->command_buffer + offset, command_data, size);
790
1103
if (tcp->port != 0)
791
1105
snprintf(port, NI_MAXSERV, "%u", tcp->port);
792
1107
else if (con->options & DRIZZLE_CON_MYSQL)
793
1109
snprintf(port, NI_MAXSERV, "%u", DRIZZLE_DEFAULT_TCP_PORT_MYSQL);
795
1113
snprintf(port, NI_MAXSERV, "%u", DRIZZLE_DEFAULT_TCP_PORT);
796
1115
port[NI_MAXSERV-1]= 0;
798
1117
memset(&ai, 0, sizeof(struct addrinfo));