55
55
drizzle_return_t *ret_ptr)
57
size_t size= strlen(query);
59
return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_QUERY, (uint8_t *)query, size, size, ret_ptr);
61
return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_QUERY,
62
(uint8_t *)query, size, size, ret_ptr);
62
65
drizzle_result_st *drizzle_query_inc(drizzle_con_st *con,
64
67
const char *query, size_t size,
65
68
size_t total, drizzle_return_t *ret_ptr)
67
return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_QUERY, (uint8_t *)query, size, total, ret_ptr);
70
return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_QUERY,
71
(uint8_t *)query, size, total, ret_ptr);
70
74
drizzle_query_st *drizzle_query_add(drizzle_st *drizzle,
72
76
drizzle_con_st *con,
73
77
drizzle_result_st *result,
74
78
const char *query_string, size_t size,
75
drizzle_query_options_t,
79
drizzle_query_options_t options,
78
// @note drizzle_query_st handle the null drizzle case
79
82
query= drizzle_query_create(drizzle, query);
85
86
drizzle_query_set_con(query, con);
86
87
drizzle_query_set_result(query, result);
87
88
drizzle_query_set_string(query, query_string, size);
89
drizzle_query_add_options(query, options);
88
90
drizzle_query_set_context(query, context);
93
drizzle_query_st *drizzle_query_create(drizzle_st *drizzle, drizzle_query_st *query)
95
drizzle_query_st *drizzle_query_create(drizzle_st *drizzle,
96
drizzle_query_st *query)
100
98
if (query == NULL)
102
query= new (std::nothrow) drizzle_query_st;
108
query->options.is_allocated= true;
100
query= new drizzle_query_st;
101
query->options|= DRIZZLE_CON_ALLOCATED;
112
105
query->prev= NULL;
113
107
query->state= DRIZZLE_QUERY_STATE_INIT;
114
108
query->con= NULL;
115
109
query->result= NULL;
118
112
query->context= NULL;
119
113
query->context_free_fn= NULL;
120
query->options.is_allocated= false;
123
116
query->drizzle= drizzle;
125
118
if (drizzle->query_list)
127
119
drizzle->query_list->prev= query;
129
120
query->next= drizzle->query_list;
130
121
drizzle->query_list= query;
131
122
drizzle->query_count++;
137
128
void drizzle_query_free(drizzle_query_st *query)
144
130
if (query->context != NULL && query->context_free_fn != NULL)
146
131
query->context_free_fn(query, query->context);
149
133
if (query->drizzle->query_list == query)
151
134
query->drizzle->query_list= query->next;
156
136
query->prev->next= query->next;
161
138
query->next->prev= query->prev;
164
139
query->drizzle->query_count--;
166
if (query->options.is_allocated)
141
if (query->options & DRIZZLE_QUERY_ALLOCATED)
172
145
void drizzle_query_free_all(drizzle_st *drizzle)
174
147
while (drizzle->query_list != NULL)
176
148
drizzle_query_free(drizzle->query_list);
180
151
drizzle_con_st *drizzle_query_con(drizzle_query_st *query)
187
153
return query->con;
190
156
void drizzle_query_set_con(drizzle_query_st *query, drizzle_con_st *con)
200
161
drizzle_result_st *drizzle_query_result(drizzle_query_st *query)
207
163
return query->result;
210
166
void drizzle_query_set_result(drizzle_query_st *query,
211
167
drizzle_result_st *result)
218
169
query->result= result;
221
172
char *drizzle_query_string(drizzle_query_st *query, size_t *size)
228
174
*size= query->size;
229
175
return (char *)(query->string);
232
178
void drizzle_query_set_string(drizzle_query_st *query, const char *string,
240
181
query->string= string;
241
182
query->size= size;
244
int drizzle_query_options(drizzle_query_st *)
249
void drizzle_query_set_options(drizzle_query_st *, int)
253
void drizzle_query_add_options(drizzle_query_st *, int)
257
void drizzle_query_remove_options(drizzle_query_st *, int)
185
int drizzle_query_options(drizzle_query_st *query)
187
return query->options;
190
void drizzle_query_set_options(drizzle_query_st *query,
193
query->options= options;
196
void drizzle_query_add_options(drizzle_query_st *query,
199
query->options|= options;
202
void drizzle_query_remove_options(drizzle_query_st *query,
205
query->options&= ~options;
261
208
void *drizzle_query_context(drizzle_query_st *query)
268
210
return query->context;
271
213
void drizzle_query_set_context(drizzle_query_st *query, void *context)
278
215
query->context= context;
281
218
void drizzle_query_set_context_free_fn(drizzle_query_st *query,
282
219
drizzle_query_context_free_fn *function)
289
221
query->context_free_fn= function;
292
224
static void drizzle_query_run_state(drizzle_query_st* query,
293
225
drizzle_return_t* ret_ptr)
300
227
switch (query->state)
302
229
case DRIZZLE_QUERY_STATE_INIT:
303
230
query->state= DRIZZLE_QUERY_STATE_QUERY;
305
231
case DRIZZLE_QUERY_STATE_QUERY:
306
232
query->result= drizzle_query(query->con, query->result, query->string,
307
233
query->size, ret_ptr);
336
262
drizzle_query_st *drizzle_query_run(drizzle_st *drizzle,
337
263
drizzle_return_t *ret_ptr)
339
drizzle_return_t unused;
347
*ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
266
drizzle_query_st *query;
351
269
if (drizzle->query_new == 0 && drizzle->query_running == 0)
357
drizzle_st::options_t options= drizzle->options;
358
drizzle->options.is_non_blocking= false;
275
options= drizzle->options;
276
drizzle->options|= DRIZZLE_NON_BLOCKING;
360
278
/* Check to see if any queries need to be started. */
361
279
if (drizzle->query_new > 0)
363
for (drizzle_query_st *query= drizzle->query_list; query != NULL; query= query->next)
281
for (query= drizzle->query_list; query != NULL; query= query->next)
365
283
if (query->state != DRIZZLE_QUERY_STATE_INIT)
370
286
drizzle->query_new--;
371
287
drizzle->query_running++;
396
310
/* Loop through each active connection. */
397
311
while ((con= drizzle_con_ready(drizzle)) != NULL)
399
drizzle_query_st *query= con->query;
400
314
drizzle_query_run_state(query, ret_ptr);
401
315
if (query->state == DRIZZLE_QUERY_STATE_DONE)
426
340
drizzle_return_t drizzle_query_run_all(drizzle_st *drizzle)
430
return DRIZZLE_RETURN_INVALID_ARGUMENT;
342
drizzle_return_t ret;
433
344
while (drizzle->query_new > 0 || drizzle->query_running > 0)
435
drizzle_return_t ret;
437
346
(void)drizzle_query_run(drizzle, &ret);
438
347
if (ret != DRIZZLE_RETURN_OK && ret != DRIZZLE_RETURN_ERROR_CODE)
444
351
return DRIZZLE_RETURN_OK;
447
ssize_t drizzle_escape_string(char *to, size_t max_to_size, const char *from, size_t from_size)
354
ssize_t drizzle_safe_escape_string(char *to, size_t max_to_size, const char *from, size_t from_size)
449
356
ssize_t to_size= 0;
417
size_t drizzle_escape_string(char *to, const char *from, size_t from_size)
419
return (size_t) drizzle_safe_escape_string(to, (from_size * 2), from, from_size);
514
422
size_t drizzle_hex_string(char *to, const char *from, size_t from_size)
516
424
static const char hex_map[]= "0123456789ABCDEF";