86
86
return _verbose_name[verbose];
89
drizzle_st *drizzle_create()
89
drizzle_st *drizzle_create(drizzle_st *drizzle)
91
91
#if defined(_WIN32)
92
92
/* if it is MS windows, invoke WSAStartup */
101
101
sigaction(SIGPIPE, &act, NULL);
104
drizzle_st *drizzle= new (std::nothrow) drizzle_st;
106
104
if (drizzle == NULL)
106
drizzle= new (std::nothrow) drizzle_st;
112
drizzle->options.is_allocated= true;
111
115
/* @todo remove this default free flag with new API. */
139
drizzle_st *drizzle_clone(const drizzle_st *source)
143
drizzle_st *drizzle_clone(drizzle_st *drizzle, const drizzle_st *from)
141
drizzle_st *drizzle= drizzle_create();
145
drizzle= drizzle_create(drizzle);
142
146
if (drizzle == NULL)
147
for (drizzle_con_st* con= source->con_list; con != NULL; con= con->next)
151
bool cache_state= drizzle->options.is_allocated;
152
drizzle->options= from->options;
153
drizzle->options.is_allocated= cache_state;
155
for (drizzle_con_st* con= from->con_list; con != NULL; con= con->next)
149
if (drizzle_con_clone(drizzle, con) == NULL)
157
if (drizzle_con_clone(drizzle, NULL, con) == NULL)
151
159
drizzle_free(drizzle);
188
199
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
202
int drizzle_errno(const drizzle_st *drizzle)
214
204
return drizzle->last_errno;
224
214
return drizzle->sqlstate;
217
int drizzle_options(const drizzle_st *)
222
void drizzle_set_options(drizzle_st *, int)
226
void drizzle_add_options(drizzle_st *, int)
227
230
void *drizzle_context(const drizzle_st *drizzle)
229
232
return drizzle->context;
275
278
drizzle->event_watch_context= context;
278
drizzle_con_st *drizzle_con_create(drizzle_st *drizzle)
281
drizzle_con_st *drizzle_con_create(drizzle_st *drizzle, drizzle_con_st *con)
285
drizzle_con_st *con= new (std::nothrow) drizzle_con_st;
285
con= new (std::nothrow) drizzle_con_st;
286
con->options= DRIZZLE_CON_ALLOCATED;
292
293
if (drizzle->con_list != NULL)
294
294
drizzle->con_list->prev= con;
297
296
con->next= drizzle->con_list;
350
drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *source)
349
drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *con,
350
const drizzle_con_st *from)
352
drizzle_con_st *con= drizzle_con_create(drizzle);
352
con= drizzle_con_create(drizzle, con);
358
358
/* Clear "operational" options such as IO status. */
359
con->options|= (source->options & ~(DRIZZLE_CON_ALLOCATED|DRIZZLE_CON_READY|
359
con->options|= (from->options & ~(DRIZZLE_CON_ALLOCATED|DRIZZLE_CON_READY|
360
360
DRIZZLE_CON_NO_RESULT_READ|DRIZZLE_CON_IO_READY|
361
361
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);
362
con->backlog= from->backlog;
363
strcpy(con->schema, from->schema);
364
strcpy(con->password, from->password);
365
strcpy(con->user, from->user);
367
switch (source->socket_type)
367
switch (from->socket_type)
369
369
case DRIZZLE_CON_SOCKET_TCP:
370
drizzle_con_set_tcp(con, source->socket.tcp.host, source->socket.tcp.port);
370
drizzle_con_set_tcp(con, from->socket.tcp.host, from->socket.tcp.port);
373
373
case DRIZZLE_CON_SOCKET_UDS:
374
drizzle_con_set_uds(con, source->socket.uds.sockaddr.sun_path);
374
drizzle_con_set_uds(con, from->socket.uds.sockaddr.sun_path);
549
552
* Client Definitions
552
drizzle_con_st *drizzle_con_add_tcp(drizzle_st *drizzle,
555
drizzle_con_st *drizzle_con_add_tcp(drizzle_st *drizzle, drizzle_con_st *con,
553
556
const char *host, in_port_t port,
554
557
const char *user, const char *password,
556
559
drizzle_con_options_t options)
558
drizzle_con_st *con= drizzle_con_create(drizzle);
561
con= drizzle_con_create(drizzle, con);
572
drizzle_con_st *drizzle_con_add_uds(drizzle_st *drizzle,
575
drizzle_con_st *drizzle_con_add_uds(drizzle_st *drizzle, drizzle_con_st *con,
573
576
const char *uds, const char *user,
574
577
const char *password, const char *db,
575
578
drizzle_con_options_t options)
577
drizzle_con_st *con= drizzle_con_create(drizzle);
580
con= drizzle_con_create(drizzle, con);
595
598
drizzle_con_st *drizzle_con_add_tcp_listen(drizzle_st *drizzle,
596
600
const char *host, in_port_t port,
598
602
drizzle_con_options_t options)
600
drizzle_con_st *con= drizzle_con_create(drizzle);
604
con= drizzle_con_create(drizzle, con);
613
617
drizzle_con_st *drizzle_con_add_uds_listen(drizzle_st *drizzle,
614
619
const char *uds, int backlog,
615
620
drizzle_con_options_t options)
617
drizzle_con_st *con= drizzle_con_create(drizzle);
622
con= drizzle_con_create(drizzle, con);
630
drizzle_con_st *drizzle_con_accept(drizzle_st *drizzle,
635
drizzle_con_st *drizzle_con_accept(drizzle_st *drizzle, drizzle_con_st *con,
631
636
drizzle_return_t *ret_ptr)
633
drizzle_return_t unused;
641
640
if (drizzle_con_st* ready= drizzle_con_ready_listen(drizzle))
643
642
int fd= accept(ready->fd, NULL, NULL);
645
drizzle_con_st *con= drizzle_con_create(drizzle);
644
con= drizzle_con_create(drizzle, con);
648
647
(void)closesocket(fd);
673
672
for (drizzle_con_st* ready= drizzle->con_list; ready != NULL; ready= ready->next)
675
674
if (ready->options & DRIZZLE_CON_LISTEN)
677
675
drizzle_con_set_events(ready, POLLIN);
681
678
*ret_ptr= drizzle_con_wait(drizzle);
682
679
if (*ret_ptr != DRIZZLE_RETURN_OK)