79
79
const char *drizzle_verbose_name(drizzle_verbose_t verbose)
81
81
if (verbose >= DRIZZLE_VERBOSE_MAX)
86
84
return _verbose_name[verbose];
89
drizzle_st *drizzle_create()
87
drizzle_st *drizzle_create(drizzle_st *drizzle)
91
89
#if defined(_WIN32)
92
90
/* if it is MS windows, invoke WSAStartup */
101
99
sigaction(SIGPIPE, &act, NULL);
104
drizzle_st *drizzle= new (std::nothrow) drizzle_st;
106
102
if (drizzle == NULL)
104
drizzle= new drizzle_st;
105
drizzle->options= DRIZZLE_ALLOCATED;
108
drizzle->options= DRIZZLE_NONE;
111
110
/* @todo remove this default free flag with new API. */
112
drizzle->options.is_free_objects= true;
111
drizzle->options|= DRIZZLE_FREE_OBJECTS;
113
112
drizzle->error_code= 0;
115
113
/* drizzle->options set above */
116
114
drizzle->verbose= DRIZZLE_VERBOSE_NEVER;
117
115
drizzle->con_count= 0;
139
drizzle_st *drizzle_clone(const drizzle_st *source)
137
drizzle_st *drizzle_clone(drizzle_st *drizzle, const drizzle_st *from)
141
drizzle_st *drizzle= drizzle_create();
139
drizzle= drizzle_create(drizzle);
142
140
if (drizzle == NULL)
147
for (drizzle_con_st* con= source->con_list; con != NULL; con= con->next)
143
drizzle->options|= (from->options & ~DRIZZLE_ALLOCATED);
145
for (drizzle_con_st* con= from->con_list; con != NULL; con= con->next)
149
if (drizzle_con_clone(drizzle, con) == NULL)
147
if (drizzle_con_clone(drizzle, NULL, con) == NULL)
151
149
drizzle_free(drizzle);
159
157
void drizzle_free(drizzle_st *drizzle)
161
159
if (drizzle->context != NULL && drizzle->context_free_fn != NULL)
163
160
drizzle->context_free_fn(drizzle, drizzle->context);
166
if (drizzle->options.is_free_objects)
162
if (drizzle->options & DRIZZLE_FREE_OBJECTS)
168
164
drizzle_con_free_all(drizzle);
169
165
drizzle_query_free_all(drizzle);
171
else if (drizzle->options.is_assert_dangling)
167
else if (drizzle->options & DRIZZLE_ASSERT_DANGLING)
173
169
assert(drizzle->con_list == NULL);
174
170
assert(drizzle->query_list == NULL);
188
185
return drizzle->last_error;
191
drizzle_return_t drizzle_set_option(drizzle_st *drizzle, drizzle_options_t arg, bool set)
195
case DRIZZLE_NON_BLOCKING:
196
drizzle->options.is_non_blocking= set;
197
return DRIZZLE_RETURN_OK;
199
case DRIZZLE_FREE_OBJECTS:
200
return DRIZZLE_RETURN_OK;
202
case DRIZZLE_ASSERT_DANGLING:
203
return DRIZZLE_RETURN_OK;
209
return DRIZZLE_RETURN_INVALID_ARGUMENT;
212
188
int drizzle_errno(const drizzle_st *drizzle)
214
190
return drizzle->last_errno;
224
200
return drizzle->sqlstate;
203
int drizzle_options(const drizzle_st *drizzle)
205
return drizzle->options;
208
void drizzle_set_options(drizzle_st *drizzle, int options)
210
drizzle->options= options;
213
void drizzle_add_options(drizzle_st *drizzle, int options)
215
drizzle->options|= options;
218
void drizzle_remove_options(drizzle_st *drizzle, drizzle_options_t options)
220
drizzle->options&= ~options;
227
223
void *drizzle_context(const drizzle_st *drizzle)
229
225
return drizzle->context;
275
271
drizzle->event_watch_context= context;
278
drizzle_con_st *drizzle_con_create(drizzle_st *drizzle)
274
drizzle_con_st *drizzle_con_create(drizzle_st *drizzle, drizzle_con_st *con)
285
drizzle_con_st *con= new (std::nothrow) drizzle_con_st;
278
con= new drizzle_con_st;
279
con->options= DRIZZLE_CON_ALLOCATED;
292
284
if (drizzle->con_list != NULL)
294
285
drizzle->con_list->prev= con;
297
286
con->next= drizzle->con_list;
299
288
drizzle->con_list= con;
350
drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *source)
339
drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *con,
340
const drizzle_con_st *from)
352
drizzle_con_st *con= drizzle_con_create(drizzle);
342
con= drizzle_con_create(drizzle, con);
358
346
/* Clear "operational" options such as IO status. */
359
con->options|= (source->options & ~(DRIZZLE_CON_ALLOCATED|DRIZZLE_CON_READY|
347
con->options|= (from->options & ~(DRIZZLE_CON_ALLOCATED|DRIZZLE_CON_READY|
360
348
DRIZZLE_CON_NO_RESULT_READ|DRIZZLE_CON_IO_READY|
361
349
DRIZZLE_CON_LISTEN));
362
con->backlog= source->backlog;
363
strcpy(con->schema, source->schema);
364
strcpy(con->password, source->password);
365
strcpy(con->user, source->user);
350
con->backlog= from->backlog;
351
strcpy(con->db, from->db);
352
strcpy(con->password, from->password);
353
strcpy(con->user, from->user);
367
switch (source->socket_type)
355
switch (from->socket_type)
369
357
case DRIZZLE_CON_SOCKET_TCP:
370
drizzle_con_set_tcp(con, source->socket.tcp.host, source->socket.tcp.port);
358
drizzle_con_set_tcp(con, from->socket.tcp.host, from->socket.tcp.port);
373
361
case DRIZZLE_CON_SOCKET_UDS:
374
drizzle_con_set_uds(con, source->socket.uds.sockaddr.sun_path);
362
drizzle_con_set_uds(con, from->socket.uds.sockaddr.sun_path);
381
369
void drizzle_con_free(drizzle_con_st *con)
383
371
if (con->context != NULL && con->context_free_fn != NULL)
385
372
con->context_free_fn(con, con->context);
388
if (con->drizzle->options.is_free_objects)
374
if (con->drizzle->options & DRIZZLE_FREE_OBJECTS)
390
375
drizzle_result_free_all(con);
392
else if (con->drizzle->options.is_assert_dangling)
376
else if (con->drizzle->options & DRIZZLE_ASSERT_DANGLING)
394
377
assert(con->result_list == NULL);
397
379
if (con->fd != -1)
399
380
drizzle_con_close(con);
402
382
drizzle_con_reset_addrinfo(con);
404
384
if (con->drizzle->con_list == con)
406
385
con->drizzle->con_list= con->next;
408
386
if (con->prev != NULL)
410
387
con->prev->next= con->next;
412
388
if (con->next != NULL)
414
389
con->next->prev= con->prev;
416
390
con->drizzle->con_count--;
392
if (con->options & DRIZZLE_CON_ALLOCATED)
421
396
void drizzle_con_free_all(drizzle_st *drizzle)
423
398
while (drizzle->con_list != NULL)
425
399
drizzle_con_free(drizzle->con_list);
429
402
drizzle_return_t drizzle_con_wait(drizzle_st *drizzle)
549
520
* Client Definitions
552
drizzle_con_st *drizzle_con_add_tcp(drizzle_st *drizzle,
523
drizzle_con_st *drizzle_con_add_tcp(drizzle_st *drizzle, drizzle_con_st *con,
553
524
const char *host, in_port_t port,
554
525
const char *user, const char *password,
556
527
drizzle_con_options_t options)
558
drizzle_con_st *con= drizzle_con_create(drizzle);
529
con= drizzle_con_create(drizzle, con);
564
533
drizzle_con_set_tcp(con, host, port);
565
534
drizzle_con_set_auth(con, user, password);
572
drizzle_con_st *drizzle_con_add_uds(drizzle_st *drizzle,
541
drizzle_con_st *drizzle_con_add_uds(drizzle_st *drizzle, drizzle_con_st *con,
573
542
const char *uds, const char *user,
574
543
const char *password, const char *db,
575
544
drizzle_con_options_t options)
577
drizzle_con_st *con= drizzle_con_create(drizzle);
546
con= drizzle_con_create(drizzle, con);
583
550
drizzle_con_set_uds(con, uds);
584
551
drizzle_con_set_auth(con, user, password);
595
562
drizzle_con_st *drizzle_con_add_tcp_listen(drizzle_st *drizzle,
596
564
const char *host, in_port_t port,
598
566
drizzle_con_options_t options)
600
drizzle_con_st *con= drizzle_con_create(drizzle);
568
con= drizzle_con_create(drizzle, con);
606
572
drizzle_con_set_tcp(con, host, port);
607
573
drizzle_con_set_backlog(con, backlog);
613
579
drizzle_con_st *drizzle_con_add_uds_listen(drizzle_st *drizzle,
614
581
const char *uds, int backlog,
615
582
drizzle_con_options_t options)
617
drizzle_con_st *con= drizzle_con_create(drizzle);
584
con= drizzle_con_create(drizzle, con);
623
588
drizzle_con_set_uds(con, uds);
624
589
drizzle_con_set_backlog(con, backlog);
630
drizzle_con_st *drizzle_con_accept(drizzle_st *drizzle,
595
drizzle_con_st *drizzle_con_accept(drizzle_st *drizzle, drizzle_con_st *con,
631
596
drizzle_return_t *ret_ptr)
633
drizzle_return_t unused;
641
600
if (drizzle_con_st* ready= drizzle_con_ready_listen(drizzle))
643
602
int fd= accept(ready->fd, NULL, NULL);
645
drizzle_con_st *con= drizzle_con_create(drizzle);
604
con= drizzle_con_create(drizzle, con);
648
607
(void)closesocket(fd);
673
632
for (drizzle_con_st* ready= drizzle->con_list; ready != NULL; ready= ready->next)
675
634
if (ready->options & DRIZZLE_CON_LISTEN)
677
635
drizzle_con_set_events(ready, POLLIN);
681
638
*ret_ptr= drizzle_con_wait(drizzle);
682
639
if (*ret_ptr != DRIZZLE_RETURN_OK)
711
662
int written= vsnprintf(ptr, DRIZZLE_MAX_ERROR_SIZE - size, format, args);
716
size= DRIZZLE_MAX_ERROR_SIZE;
665
if (written < 0) size= DRIZZLE_MAX_ERROR_SIZE;
723
667
if (size >= DRIZZLE_MAX_ERROR_SIZE)
725
668
size= DRIZZLE_MAX_ERROR_SIZE - 1;
727
669
log_buffer[size]= 0;
729
671
if (drizzle->log_fn == NULL)
731
672
memcpy(drizzle->last_error, log_buffer, size + 1);
735
674
drizzle->log_fn(log_buffer, DRIZZLE_VERBOSE_ERROR, drizzle->log_context);
739
677
void drizzle_log(drizzle_st *drizzle, drizzle_verbose_t verbose,