Merge lp:~linuxjedi/libdrizzle/5.1-prep-stmt-cleanup into lp:libdrizzle

Proposed by Andrew Hutchings
Status: Merged
Approved by: Andrew Hutchings
Approved revision: 77
Merged at revision: 75
Proposed branch: lp:~linuxjedi/libdrizzle/5.1-prep-stmt-cleanup
Merge into: lp:libdrizzle
Diff against target: 1193 lines (+885/-100)
13 files modified
libdrizzle-5.1/constants.h (+0/-9)
libdrizzle-5.1/return.h (+2/-0)
libdrizzle-5.1/statement.h (+47/-16)
libdrizzle/common.h (+1/-0)
libdrizzle/error.cc (+2/-0)
libdrizzle/include.am (+2/-0)
libdrizzle/statement.cc (+19/-68)
libdrizzle/statement_local.h (+65/-0)
libdrizzle/statement_param.cc (+559/-0)
libdrizzle/structs.h (+8/-1)
tests/unit/include.am (+5/-0)
tests/unit/statement.c (+18/-6)
tests/unit/statement_char.c (+157/-0)
To merge this branch: bzr merge lp:~linuxjedi/libdrizzle/5.1-prep-stmt-cleanup
Reviewer Review Type Date Requested Status
Andrew Hutchings Needs Fixing
Review via email: mp+141510@code.launchpad.net

Description of the change

Adds a JDBC like interface to libdrizzle. Now to set query params there are functions like:

drizzle_return_t drizzle_stmt_set_long(drizzle_stmt_st *stmt, uint16_t param_num, uint32_t value, bool is_unsigned);

and

drizzle_return_t drizzle_stmt_set_string(drizzle_stmt_st *stmt, uint16_t param_num, char *value, size_t length);

And to get result params:

uint32_t drizzle_stmt_get_long(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr);

and

const char *drizzle_stmt_get_string(drizzle_stmt_st *stmt, uint16_t column_number, size_t *len, drizzle_return_t *ret_ptr);

To post a comment you must log in.
Revision history for this message
Andrew Hutchings (linuxjedi) wrote :

Need to change the names from 'long' to 'int'

review: Needs Fixing
77. By Andrew Hutchings

Change long to int in function names

78. By Andrew Hutchings

Fix statement_char test case

79. By Andrew Hutchings

Using wrong source for column_count

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdrizzle-5.1/constants.h'
2--- libdrizzle-5.1/constants.h 2012-12-30 02:23:50 +0000
3+++ libdrizzle-5.1/constants.h 2012-12-31 10:04:21 +0000
4@@ -567,15 +567,6 @@
5 DRIZZLE_STMT_FETCHED
6 } drizzle_stmt_state_t;
7
8-typedef enum
9-{
10- DRIZZLE_BIND_OPTION_NONE= 0,
11- DRIZZLE_BIND_OPTION_NULL= (1 << 0),
12- DRIZZLE_BIND_OPTION_UNSIGNED= (1 << 1),
13- DRIZZLE_BIND_OPTION_TRUNCATED= (1 << 2),
14- DRIZZLE_BIND_OPTION_LONG_DATA= (1 << 3)
15-} drizzle_bind_options_t;
16-
17 #ifndef __cplusplus
18 typedef enum drizzle_column_flags_t drizzle_column_flags_t;
19 #endif
20
21=== modified file 'libdrizzle-5.1/return.h'
22--- libdrizzle-5.1/return.h 2012-12-29 17:31:57 +0000
23+++ libdrizzle-5.1/return.h 2012-12-31 10:04:21 +0000
24@@ -71,6 +71,8 @@
25 DRIZZLE_RETURN_EOF,
26 DRIZZLE_RETURN_STMT_ERROR,
27 DRIZZLE_RETURN_BINLOG_CRC,
28+ DRIZZLE_RETURN_TRUNCATED,
29+ DRIZZLE_RETURN_INVALID_CONVERSION,
30 DRIZZLE_RETURN_MAX /* Always add new codes to the end before this one. */
31 };
32
33
34=== modified file 'libdrizzle-5.1/statement.h'
35--- libdrizzle-5.1/statement.h 2012-12-23 01:05:57 +0000
36+++ libdrizzle-5.1/statement.h 2012-12-31 10:04:21 +0000
37@@ -45,9 +45,6 @@
38 drizzle_stmt_st *drizzle_stmt_prepare(drizzle_st *con, const char *statement, size_t size, drizzle_return_t *ret_ptr);
39
40 DRIZZLE_API
41-drizzle_return_t drizzle_stmt_bind_param(drizzle_stmt_st *stmt, uint16_t param_num, drizzle_column_type_t type, void *data, uint32_t length, drizzle_bind_options_t options);
42-
43-DRIZZLE_API
44 drizzle_return_t drizzle_stmt_execute(drizzle_stmt_st *stmt);
45
46 DRIZZLE_API
47@@ -66,18 +63,6 @@
48 drizzle_return_t drizzle_stmt_close(drizzle_stmt_st *stmt);
49
50 DRIZZLE_API
51-drizzle_column_type_t drizzle_stmt_item_type(drizzle_stmt_st *stmt, uint16_t column_number);
52-
53-DRIZZLE_API
54-void *drizzle_stmt_item_data(drizzle_stmt_st *stmt, uint16_t column_number);
55-
56-DRIZZLE_API
57-uint32_t drizzle_stmt_item_length(drizzle_stmt_st *stmt, uint16_t column_number);
58-
59-DRIZZLE_API
60-drizzle_bind_options_t drizzle_stmt_item_options(drizzle_stmt_st *stmt, uint16_t column_number);
61-
62-DRIZZLE_API
63 uint16_t drizzle_stmt_column_count(drizzle_stmt_st *stmt);
64
65 DRIZZLE_API
66@@ -92,7 +77,53 @@
67 DRIZZLE_API
68 uint64_t drizzle_stmt_row_count(drizzle_stmt_st *stmt);
69
70-
71+DRIZZLE_API
72+drizzle_return_t drizzle_stmt_set_tiny(drizzle_stmt_st *stmt, uint16_t param_num, uint8_t value, bool is_unsigned);
73+
74+DRIZZLE_API
75+drizzle_return_t drizzle_stmt_set_short(drizzle_stmt_st *stmt, uint16_t param_num, uint16_t value, bool is_unsigned);
76+
77+DRIZZLE_API
78+drizzle_return_t drizzle_stmt_set_int(drizzle_stmt_st *stmt, uint16_t param_num, uint32_t value, bool is_unsigned);
79+
80+DRIZZLE_API
81+drizzle_return_t drizzle_stmt_set_bigint(drizzle_stmt_st *stmt, uint16_t param_num, uint64_t value, bool is_unsigned);
82+
83+DRIZZLE_API
84+drizzle_return_t drizzle_stmt_set_double(drizzle_stmt_st *stmt, uint16_t param_num, double value);
85+
86+DRIZZLE_API
87+drizzle_return_t drizzle_stmt_set_float(drizzle_stmt_st *stmt, uint16_t param_num, float value);
88+
89+DRIZZLE_API
90+drizzle_return_t drizzle_stmt_set_string(drizzle_stmt_st *stmt, uint16_t param_num, char *value, size_t length);
91+
92+DRIZZLE_API
93+drizzle_return_t drizzle_stmt_set_null(drizzle_stmt_st *stmt, uint16_t param_num);
94+
95+DRIZZLE_API
96+drizzle_return_t drizzle_stmt_set_time(drizzle_stmt_st *stmt, uint16_t param_num, uint32_t days, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t microseconds, bool is_negative);
97+
98+DRIZZLE_API
99+drizzle_return_t drizzle_stmt_set_timestamp(drizzle_stmt_st *stmt, uint16_t param_num, uint16_t year, uint8_t month, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t microseconds);
100+
101+DRIZZLE_API
102+bool drizzle_stmt_get_is_null(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr);
103+
104+DRIZZLE_API
105+bool drizzle_stmt_get_is_unsigned(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr);
106+
107+DRIZZLE_API
108+const char *drizzle_stmt_get_string(drizzle_stmt_st *stmt, uint16_t column_number, size_t *len, drizzle_return_t *ret_ptr);
109+
110+DRIZZLE_API
111+uint32_t drizzle_stmt_get_int(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr);
112+
113+DRIZZLE_API
114+uint64_t drizzle_stmt_get_bigint(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr);
115+
116+DRIZZLE_API
117+double drizzle_stmt_get_double(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr);
118
119 #ifdef __cplusplus
120 }
121
122=== modified file 'libdrizzle/common.h'
123--- libdrizzle/common.h 2012-12-31 00:19:49 +0000
124+++ libdrizzle/common.h 2012-12-31 10:04:21 +0000
125@@ -68,6 +68,7 @@
126 #include "libdrizzle/pack.h"
127 #include "libdrizzle/state.h"
128 #include "libdrizzle/sha1.h"
129+#include "libdrizzle/statement_local.h"
130 #include "libdrizzle/column.h"
131 #include "libdrizzle/binlog.h"
132
133
134=== modified file 'libdrizzle/error.cc'
135--- libdrizzle/error.cc 2012-12-29 17:31:57 +0000
136+++ libdrizzle/error.cc 2012-12-31 10:04:21 +0000
137@@ -70,6 +70,8 @@
138 case DRIZZLE_RETURN_EOF: return "DRIZZLE_RETURN_EOF";
139 case DRIZZLE_RETURN_STMT_ERROR: return "DRIZZLE_RETURN_STMT_ERROR";
140 case DRIZZLE_RETURN_BINLOG_CRC: return "DRIZZLE_RETURN_BINLOG_CRC";
141+ case DRIZZLE_RETURN_TRUNCATED: return "DRIZZLE_RETURN_TRUNCATED";
142+ case DRIZZLE_RETURN_INVALID_CONVERSION: return "DRIZZLE_RETURN_INVALID_CONVERSION";
143 case DRIZZLE_RETURN_MAX: return "DRIZZLE_RETURN_MAX";
144 }
145
146
147=== modified file 'libdrizzle/include.am'
148--- libdrizzle/include.am 2012-12-31 00:19:49 +0000
149+++ libdrizzle/include.am 2012-12-31 10:04:21 +0000
150@@ -11,6 +11,7 @@
151 noinst_HEADERS+= libdrizzle/pack.h
152 noinst_HEADERS+= libdrizzle/sha1.h
153 noinst_HEADERS+= libdrizzle/state.h
154+noinst_HEADERS+= libdrizzle/statement_local.h
155 noinst_HEADERS+= libdrizzle/structs.h
156
157 lib_LTLIBRARIES+= libdrizzle/libdrizzle.la
158@@ -46,5 +47,6 @@
159 libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/sha1.cc
160 libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/state.cc
161 libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/statement.cc
162+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/statement_param.cc
163
164 libdrizzle_libdrizzle_la_LDFLAGS+= -version-info ${LIBDRIZZLE_LIBRARY_VERSION}
165
166=== modified file 'libdrizzle/statement.cc'
167--- libdrizzle/statement.cc 2012-12-29 20:26:36 +0000
168+++ libdrizzle/statement.cc 2012-12-31 10:04:21 +0000
169@@ -110,27 +110,6 @@
170 return stmt;
171 }
172
173-drizzle_return_t drizzle_stmt_bind_param(drizzle_stmt_st *stmt, uint16_t param_num, drizzle_column_type_t type, void *data, uint32_t length, drizzle_bind_options_t options)
174-{
175- if ((stmt == NULL) || (param_num >= stmt->param_count) || (data == NULL))
176- {
177- return DRIZZLE_RETURN_INVALID_ARGUMENT;
178- }
179- if (stmt->state < DRIZZLE_STMT_PREPARED)
180- {
181- drizzle_set_error(stmt->con, __func__, "stmt object has bot been prepared");
182- return DRIZZLE_RETURN_STMT_ERROR;
183- }
184-
185- stmt->query_params[param_num].type= type;
186- stmt->query_params[param_num].data= data;
187- stmt->query_params[param_num].length= length;
188- stmt->query_params[param_num].options= options;
189- stmt->query_params[param_num].is_bound= true;
190-
191- return DRIZZLE_RETURN_OK;
192-}
193-
194 drizzle_return_t drizzle_stmt_execute(drizzle_stmt_st *stmt)
195 {
196 uint16_t current_param;
197@@ -213,7 +192,7 @@
198 if (stmt->new_bind)
199 {
200 uint16_t type= (uint16_t)param_ptr->type;
201- if (param_ptr->options & DRIZZLE_BIND_OPTION_UNSIGNED)
202+ if (param_ptr->options.is_unsigned)
203 {
204 /* Set the unsigned bit flag on the type data */
205 type |= 0x8000;
206@@ -222,7 +201,7 @@
207 buffer_pos+= 2;
208 }
209
210- if (param_ptr->options & DRIZZLE_BIND_OPTION_LONG_DATA)
211+ if (param_ptr->options.is_long_data)
212 {
213 /* Long data is sent separately, not in this buffer */
214 continue;
215@@ -367,7 +346,7 @@
216 drizzle_command_write(stmt->con, NULL, DRIZZLE_COMMAND_STMT_SEND_LONG_DATA,
217 buffer, len+6, len+6, &ret);
218 stmt->con->options= (drizzle_options_t)((uint8_t)stmt->con->options & (uint8_t)~DRIZZLE_CON_NO_RESULT_READ);
219- stmt->query_params[param_num].options= (drizzle_bind_options_t)((uint8_t)stmt->query_params[param_num].options | (uint8_t)DRIZZLE_BIND_OPTION_LONG_DATA);
220+ stmt->query_params[param_num].options.is_long_data= true;
221
222 free(buffer);
223 return ret;
224@@ -386,7 +365,7 @@
225
226 for (current_param= 0; current_param < stmt->param_count; current_param++)
227 {
228- stmt->query_params[current_param].options= (drizzle_bind_options_t)((uint8_t)stmt->query_params[current_param].options & (uint8_t)~DRIZZLE_BIND_OPTION_LONG_DATA);
229+ stmt->query_params[current_param].options.is_long_data= false;
230 }
231
232 drizzle_set_byte4(buffer, stmt->id);
233@@ -448,7 +427,7 @@
234 /* if this row is null in the result bitmap */
235 if (*stmt->execute_result->null_bitmap & ((column_counter^2) << 2))
236 {
237- param->options = (drizzle_bind_options_t)((uint8_t)param->options | (uint8_t) DRIZZLE_BIND_OPTION_NULL);
238+ param->options.is_null= true;
239 param->length= 0;
240 }
241 else
242@@ -459,7 +438,7 @@
243 param->length= stmt->execute_result->field_sizes[column_counter];
244 if (column->flags & DRIZZLE_COLUMN_FLAGS_UNSIGNED)
245 {
246- param->options = (drizzle_bind_options_t)((uint8_t)param->options | (uint8_t) DRIZZLE_BIND_OPTION_UNSIGNED);
247+ param->options.is_unsigned= true;
248 }
249
250 param->data= realloc(param->data, param->length);
251@@ -574,14 +553,22 @@
252 }
253
254 free(stmt->null_bitmap);
255+ for (uint16_t x= 0; x < stmt->param_count; x++)
256+ {
257+ if (stmt->query_params[x].options.is_allocated)
258+ {
259+ free(stmt->query_params[x].data);
260+ }
261+ }
262 free(stmt->query_params);
263- if (stmt->result_params)
264+ if (stmt->execute_result)
265 {
266- free(stmt->result_params->data);
267+ for (uint16_t x= 0; x < stmt->execute_result->column_count; x++)
268+ {
269+ free(stmt->result_params[x].data);
270+ free(stmt->result_params[x].converted_data);
271+ }
272 free(stmt->result_params);
273- }
274- if (stmt->execute_result)
275- {
276 drizzle_result_free(stmt->execute_result);
277 }
278 if (stmt->prepare_result)
279@@ -598,42 +585,6 @@
280 return ret;
281 }
282
283-drizzle_column_type_t drizzle_stmt_item_type(drizzle_stmt_st *stmt, uint16_t column_number)
284-{
285- if ((stmt == NULL) || (stmt->result_params == NULL))
286- {
287- return DRIZZLE_COLUMN_TYPE_NONE;
288- }
289- return stmt->result_params[column_number].type;
290-}
291-
292-void *drizzle_stmt_item_data(drizzle_stmt_st *stmt, uint16_t column_number)
293-{
294- if ((stmt == NULL) || (stmt->result_params == NULL))
295- {
296- return NULL;
297- }
298- return stmt->result_params[column_number].data;
299-}
300-
301-uint32_t drizzle_stmt_item_length(drizzle_stmt_st *stmt, uint16_t column_number)
302-{
303- if ((stmt == NULL) || (stmt->result_params == NULL))
304- {
305- return 0;
306- }
307- return stmt->result_params[column_number].length;
308-}
309-
310-drizzle_bind_options_t drizzle_stmt_item_options(drizzle_stmt_st *stmt, uint16_t column_number)
311-{
312- if ((stmt == NULL) || (stmt->result_params == NULL))
313- {
314- return DRIZZLE_BIND_OPTION_NONE;
315- }
316- return stmt->result_params[column_number].options;
317-}
318-
319 uint16_t drizzle_stmt_column_count(drizzle_stmt_st *stmt)
320 {
321 if ((stmt == NULL) || (stmt->prepare_result == NULL))
322
323=== added file 'libdrizzle/statement_local.h'
324--- libdrizzle/statement_local.h 1970-01-01 00:00:00 +0000
325+++ libdrizzle/statement_local.h 2012-12-31 10:04:21 +0000
326@@ -0,0 +1,65 @@
327+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
328+ *
329+ * Drizzle Client & Protocol Library
330+ *
331+ * Copyright (C) 2012 Drizzle Developer Group
332+ * All rights reserved.
333+ *
334+ * Redistribution and use in source and binary forms, with or without
335+ * modification, are permitted provided that the following conditions are
336+ * met:
337+ *
338+ * * Redistributions of source code must retain the above copyright
339+ * notice, this list of conditions and the following disclaimer.
340+ *
341+ * * Redistributions in binary form must reproduce the above
342+ * copyright notice, this list of conditions and the following disclaimer
343+ * in the documentation and/or other materials provided with the
344+ * distribution.
345+ *
346+ * * The names of its contributors may not be used to endorse or
347+ * promote products derived from this software without specific prior
348+ * written permission.
349+ *
350+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
351+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
352+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
353+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
354+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
355+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
356+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
357+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
358+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
359+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
360+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
361+ *
362+ */
363+
364+#pragma once
365+
366+#ifdef __cplusplus
367+extern "C" {
368+#endif
369+
370+DRIZZLE_LOCAL
371+drizzle_return_t drizzle_stmt_set_param(drizzle_stmt_st *stmt, uint16_t param_num, drizzle_column_type_t type, void *data, uint32_t length, bool is_unsigned, bool is_allocated);
372+
373+DRIZZLE_LOCAL
374+char *long_to_string(drizzle_bind_st *param, uint32_t val);
375+
376+DRIZZLE_LOCAL
377+char *longlong_to_string(drizzle_bind_st *param, uint64_t val);
378+
379+DRIZZLE_LOCAL
380+char *double_to_string(drizzle_bind_st *param, double val);
381+
382+DRIZZLE_LOCAL
383+char *time_to_string(drizzle_bind_st *param, drizzle_datetime_st *time);
384+
385+DRIZZLE_LOCAL
386+char *timestamp_to_string(drizzle_bind_st *param, drizzle_datetime_st *timestamp);
387+
388+#ifdef __cplusplus
389+}
390+#endif
391+
392
393=== added file 'libdrizzle/statement_param.cc'
394--- libdrizzle/statement_param.cc 1970-01-01 00:00:00 +0000
395+++ libdrizzle/statement_param.cc 2012-12-31 10:04:21 +0000
396@@ -0,0 +1,559 @@
397+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
398+ *
399+ * Drizzle Client & Protocol Library
400+ *
401+ * Copyright (C) 2012 Drizzle Developer Group
402+ * All rights reserved.
403+ *
404+ * Redistribution and use in source and binary forms, with or without
405+ * modification, are permitted provided that the following conditions are
406+ * met:
407+ *
408+ * * Redistributions of source code must retain the above copyright
409+ * notice, this list of conditions and the following disclaimer.
410+ *
411+ * * Redistributions in binary form must reproduce the above
412+ * copyright notice, this list of conditions and the following disclaimer
413+ * in the documentation and/or other materials provided with the
414+ * distribution.
415+ *
416+ * * The names of its contributors may not be used to endorse or
417+ * promote products derived from this software without specific prior
418+ * written permission.
419+ *
420+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
421+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
422+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
423+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
424+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
425+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
426+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
427+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
428+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
429+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
430+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
431+ *
432+ */
433+
434+#include "config.h"
435+#include "libdrizzle/common.h"
436+
437+/* Internal function */
438+drizzle_return_t drizzle_stmt_set_param(drizzle_stmt_st *stmt, uint16_t param_num, drizzle_column_type_t type, void *data, uint32_t length, bool is_unsigned, bool is_allocated)
439+{
440+ if ((stmt == NULL) || (param_num >= stmt->param_count) || (data == NULL))
441+ {
442+ return DRIZZLE_RETURN_INVALID_ARGUMENT;
443+ }
444+ if (stmt->state < DRIZZLE_STMT_PREPARED)
445+ {
446+ drizzle_set_error(stmt->con, __func__, "stmt object has bot been prepared");
447+ return DRIZZLE_RETURN_STMT_ERROR;
448+ }
449+
450+ stmt->query_params[param_num].type= type;
451+ stmt->query_params[param_num].data= data;
452+ stmt->query_params[param_num].length= length;
453+ stmt->query_params[param_num].options.is_unsigned= is_unsigned;
454+ stmt->query_params[param_num].options.is_allocated= is_allocated;
455+ stmt->query_params[param_num].is_bound= true;
456+
457+ return DRIZZLE_RETURN_OK;
458+}
459+
460+
461+drizzle_return_t drizzle_stmt_set_tiny(drizzle_stmt_st *stmt, uint16_t param_num, uint8_t value, bool is_unsigned)
462+{
463+ uint8_t *val;
464+ stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(uint8_t));
465+ val= (uint8_t*) stmt->query_params[param_num].data;
466+ *val= value;
467+
468+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TINY, val, 1, is_unsigned, false);
469+}
470+drizzle_return_t drizzle_stmt_set_short(drizzle_stmt_st *stmt, uint16_t param_num, uint16_t value, bool is_unsigned)
471+{
472+ uint16_t *val;
473+ stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(uint16_t));
474+ val= (uint16_t*) stmt->query_params[param_num].data;
475+ *val= value;
476+
477+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_SHORT, val, 2, is_unsigned, false);
478+}
479+
480+drizzle_return_t drizzle_stmt_set_int(drizzle_stmt_st *stmt, uint16_t param_num, uint32_t value, bool is_unsigned)
481+{
482+ uint32_t *val;
483+ stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(uint32_t));
484+ val= (uint32_t*) stmt->query_params[param_num].data;
485+ *val= value;
486+
487+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_LONG, val, 4, is_unsigned, true);
488+}
489+
490+drizzle_return_t drizzle_stmt_set_bigint(drizzle_stmt_st *stmt, uint16_t param_num, uint64_t value, bool is_unsigned)
491+{
492+ uint64_t *val;
493+ stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(uint64_t));
494+ val= (uint64_t*) stmt->query_params[param_num].data;
495+ *val= value;
496+
497+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_LONGLONG, val, 8, is_unsigned, false);
498+}
499+
500+drizzle_return_t drizzle_stmt_set_double(drizzle_stmt_st *stmt, uint16_t param_num, double value)
501+{
502+ double *val;
503+ stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(double));
504+ val= (double*) stmt->query_params[param_num].data;
505+ *val= value;
506+
507+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_DOUBLE, val, 8, false, false);
508+}
509+
510+drizzle_return_t drizzle_stmt_set_float(drizzle_stmt_st *stmt, uint16_t param_num, float value)
511+{
512+ float *val;
513+ stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(float));
514+ val= (float*) stmt->query_params[param_num].data;
515+ *val= value;
516+
517+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_FLOAT, val, 4, false, false);
518+}
519+
520+drizzle_return_t drizzle_stmt_set_string(drizzle_stmt_st *stmt, uint16_t param_num, char *value, size_t length)
521+{
522+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_STRING, value, length, false, false);
523+}
524+
525+drizzle_return_t drizzle_stmt_set_null(drizzle_stmt_st *stmt, uint16_t param_num)
526+{
527+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_NULL, NULL, 0, false, false);
528+}
529+
530+drizzle_return_t drizzle_stmt_set_time(drizzle_stmt_st *stmt, uint16_t param_num, uint32_t days, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t microseconds, bool is_negative)
531+{
532+ drizzle_datetime_st *time;
533+ stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(drizzle_datetime_st));
534+ time= (drizzle_datetime_st*) stmt->query_params[param_num].data;
535+
536+ time->negative= is_negative;
537+ time->day= days;
538+ time->hour= hours;
539+ time->minute= minutes;
540+ time->second= seconds;
541+ time->microsecond= microseconds;
542+
543+ /* Length not important because we will figure that out when packing */
544+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TIME, time, 0, false, true);
545+}
546+
547+drizzle_return_t drizzle_stmt_set_timestamp(drizzle_stmt_st *stmt, uint16_t param_num, uint16_t year, uint8_t month, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t microseconds)
548+{
549+ drizzle_datetime_st *timestamp;
550+ stmt->query_params[param_num].data = realloc(stmt->query_params[param_num].data, sizeof(drizzle_datetime_st));
551+ timestamp= (drizzle_datetime_st*) stmt->query_params[param_num].data;
552+
553+ timestamp->negative= false;
554+ timestamp->year= year;
555+ timestamp->day= day;
556+ timestamp->month= month;
557+ timestamp->year= year;
558+ timestamp->hour= hours;
559+ timestamp->minute= minutes;
560+ timestamp->second= seconds;
561+ timestamp->microsecond= microseconds;
562+
563+ /* Length not important because we will figure that out when packing */
564+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TIME, timestamp, 0, false, true);
565+}
566+
567+bool drizzle_stmt_get_is_null(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr)
568+{
569+ if ((stmt == NULL) || (stmt->result_params == NULL) || (column_number >= stmt->execute_result->column_count))
570+ {
571+ *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
572+ return false;
573+ }
574+
575+ *ret_ptr= DRIZZLE_RETURN_OK;
576+ return stmt->result_params[column_number].options.is_null;
577+}
578+
579+bool drizzle_stmt_get_is_unsigned(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr)
580+{
581+ if ((stmt == NULL) || (stmt->result_params == NULL) || (column_number >= stmt->execute_result->column_count))
582+ {
583+ *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
584+ return false;
585+ }
586+
587+ *ret_ptr= DRIZZLE_RETURN_OK;
588+ return stmt->result_params[column_number].options.is_unsigned;
589+}
590+
591+const char *drizzle_stmt_get_string(drizzle_stmt_st *stmt, uint16_t column_number, size_t *len, drizzle_return_t *ret_ptr)
592+{
593+ char *val;
594+ drizzle_bind_st *param;
595+ if ((stmt == NULL) || (stmt->result_params == NULL) || (column_number >= stmt->execute_result->column_count))
596+ {
597+ *len= 0;
598+ *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
599+ return NULL;
600+ }
601+
602+ param= &stmt->result_params[column_number];
603+ *ret_ptr= DRIZZLE_RETURN_OK;
604+ switch(param->type)
605+ {
606+ case DRIZZLE_COLUMN_TYPE_NULL:
607+ *ret_ptr= DRIZZLE_RETURN_NULL_SIZE;
608+ val= 0;
609+ break;
610+ case DRIZZLE_COLUMN_TYPE_TINY:
611+ val= long_to_string(param, (uint32_t)(*(uint8_t*)param->data));
612+ *len= strlen(val);
613+ break;
614+ case DRIZZLE_COLUMN_TYPE_SHORT:
615+ case DRIZZLE_COLUMN_TYPE_YEAR:
616+ val= long_to_string(param, (uint32_t)(*(uint16_t*)param->data));
617+ *len= strlen(val);
618+ break;
619+ case DRIZZLE_COLUMN_TYPE_INT24:
620+ case DRIZZLE_COLUMN_TYPE_LONG:
621+ val= long_to_string(param, *(uint32_t*)param->data);
622+ *len= strlen(val);
623+ break;
624+ case DRIZZLE_COLUMN_TYPE_LONGLONG:
625+ val= longlong_to_string(param, *(uint64_t*)param->data);
626+ *len= strlen(val);
627+ break;
628+ case DRIZZLE_COLUMN_TYPE_FLOAT:
629+ val= double_to_string(param, (double) (*(float*)param->data));
630+ *len= strlen(val);
631+ break;
632+ case DRIZZLE_COLUMN_TYPE_DOUBLE:
633+ val= double_to_string(param, *(double*)param->data);
634+ *len= strlen(val);
635+ break;
636+ case DRIZZLE_COLUMN_TYPE_TIME:
637+ val= time_to_string(param, (drizzle_datetime_st*)param->data);
638+ *len= strlen(val);
639+ break;
640+ case DRIZZLE_COLUMN_TYPE_DATE:
641+ case DRIZZLE_COLUMN_TYPE_DATETIME:
642+ case DRIZZLE_COLUMN_TYPE_TIMESTAMP:
643+ val= timestamp_to_string(param, (drizzle_datetime_st*)param->data);
644+ *len= strlen(val);
645+ break;
646+ case DRIZZLE_COLUMN_TYPE_TINY_BLOB:
647+ case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:
648+ case DRIZZLE_COLUMN_TYPE_LONG_BLOB:
649+ case DRIZZLE_COLUMN_TYPE_BLOB:
650+ case DRIZZLE_COLUMN_TYPE_BIT:
651+ case DRIZZLE_COLUMN_TYPE_STRING:
652+ case DRIZZLE_COLUMN_TYPE_VAR_STRING:
653+ case DRIZZLE_COLUMN_TYPE_DECIMAL:
654+ case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:
655+ val= (char*)param->data;
656+ *len= param->length;
657+ break;
658+ case DRIZZLE_COLUMN_TYPE_NEWDATE:
659+ case DRIZZLE_COLUMN_TYPE_VARCHAR:
660+ case DRIZZLE_COLUMN_TYPE_ENUM:
661+ case DRIZZLE_COLUMN_TYPE_SET:
662+ case DRIZZLE_COLUMN_TYPE_GEOMETRY:
663+ case DRIZZLE_COLUMN_TYPE_TIMESTAMP2:
664+ case DRIZZLE_COLUMN_TYPE_DATETIME2:
665+ case DRIZZLE_COLUMN_TYPE_TIME2:
666+ default:
667+ *ret_ptr= DRIZZLE_RETURN_INVALID_CONVERSION;
668+ val= NULL;
669+ *len= 0;
670+ }
671+
672+ return val;
673+}
674+
675+uint32_t drizzle_stmt_get_int(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr)
676+{
677+ uint32_t val;
678+ drizzle_bind_st *param;
679+
680+ if ((stmt == NULL) || (stmt->result_params == NULL) || (column_number >= stmt->execute_result->column_count))
681+ {
682+ *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
683+ return 0;
684+ }
685+
686+ param= &stmt->result_params[column_number];
687+ *ret_ptr= DRIZZLE_RETURN_OK;
688+ switch(param->type)
689+ {
690+ case DRIZZLE_COLUMN_TYPE_NULL:
691+ *ret_ptr= DRIZZLE_RETURN_NULL_SIZE;
692+ val= 0;
693+ break;
694+ case DRIZZLE_COLUMN_TYPE_TINY:
695+ val= (uint32_t) (*(uint8_t*)param->data);
696+ break;
697+ case DRIZZLE_COLUMN_TYPE_SHORT:
698+ case DRIZZLE_COLUMN_TYPE_YEAR:
699+ val= (uint32_t) (*(uint16_t*)param->data);
700+ break;
701+ case DRIZZLE_COLUMN_TYPE_INT24:
702+ case DRIZZLE_COLUMN_TYPE_LONG:
703+ val= (uint32_t) (*(uint32_t*)param->data);
704+ break;
705+ case DRIZZLE_COLUMN_TYPE_LONGLONG:
706+ val= (uint32_t) (*(uint64_t*)param->data);
707+ if (val > UINT32_MAX)
708+ {
709+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
710+ }
711+ break;
712+ case DRIZZLE_COLUMN_TYPE_FLOAT:
713+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
714+ val= (uint32_t) (*(float*)param->data);
715+ break;
716+ case DRIZZLE_COLUMN_TYPE_DOUBLE:
717+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
718+ val= (uint32_t) (*(double*)param->data);
719+ break;
720+ case DRIZZLE_COLUMN_TYPE_TIME:
721+ case DRIZZLE_COLUMN_TYPE_DATE:
722+ case DRIZZLE_COLUMN_TYPE_DATETIME:
723+ case DRIZZLE_COLUMN_TYPE_TIMESTAMP:
724+ case DRIZZLE_COLUMN_TYPE_TINY_BLOB:
725+ case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:
726+ case DRIZZLE_COLUMN_TYPE_LONG_BLOB:
727+ case DRIZZLE_COLUMN_TYPE_BLOB:
728+ case DRIZZLE_COLUMN_TYPE_BIT:
729+ case DRIZZLE_COLUMN_TYPE_STRING:
730+ case DRIZZLE_COLUMN_TYPE_VAR_STRING:
731+ case DRIZZLE_COLUMN_TYPE_DECIMAL:
732+ case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:
733+ case DRIZZLE_COLUMN_TYPE_NEWDATE:
734+ case DRIZZLE_COLUMN_TYPE_VARCHAR:
735+ case DRIZZLE_COLUMN_TYPE_ENUM:
736+ case DRIZZLE_COLUMN_TYPE_SET:
737+ case DRIZZLE_COLUMN_TYPE_GEOMETRY:
738+ case DRIZZLE_COLUMN_TYPE_TIMESTAMP2:
739+ case DRIZZLE_COLUMN_TYPE_DATETIME2:
740+ case DRIZZLE_COLUMN_TYPE_TIME2:
741+ default:
742+ *ret_ptr= DRIZZLE_RETURN_INVALID_CONVERSION;
743+ val= 0;
744+ }
745+
746+ return val;
747+}
748+
749+uint64_t drizzle_stmt_get_bigint(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr)
750+{
751+ uint32_t val;
752+ drizzle_bind_st *param;
753+
754+ if ((stmt == NULL) || (stmt->result_params == NULL) || (column_number >= stmt->execute_result->column_count))
755+ {
756+ *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
757+ return 0;
758+ }
759+
760+ param= &stmt->result_params[column_number];
761+ *ret_ptr= DRIZZLE_RETURN_OK;
762+ switch(param->type)
763+ {
764+ case DRIZZLE_COLUMN_TYPE_NULL:
765+ *ret_ptr= DRIZZLE_RETURN_NULL_SIZE;
766+ val= 0;
767+ break;
768+ case DRIZZLE_COLUMN_TYPE_TINY:
769+ val= (uint64_t) (*(uint8_t*)param->data);
770+ break;
771+ case DRIZZLE_COLUMN_TYPE_SHORT:
772+ case DRIZZLE_COLUMN_TYPE_YEAR:
773+ val= (uint64_t) (*(uint16_t*)param->data);
774+ break;
775+ case DRIZZLE_COLUMN_TYPE_INT24:
776+ case DRIZZLE_COLUMN_TYPE_LONG:
777+ val= (uint64_t) (*(uint32_t*)param->data);
778+ break;
779+ case DRIZZLE_COLUMN_TYPE_LONGLONG:
780+ val= (uint64_t) (*(uint64_t*)param->data);
781+ break;
782+ case DRIZZLE_COLUMN_TYPE_FLOAT:
783+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
784+ val= (uint64_t) (*(float*)param->data);
785+ break;
786+ case DRIZZLE_COLUMN_TYPE_DOUBLE:
787+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
788+ val= (uint64_t) (*(double*)param->data);
789+ break;
790+ case DRIZZLE_COLUMN_TYPE_TIME:
791+ case DRIZZLE_COLUMN_TYPE_DATE:
792+ case DRIZZLE_COLUMN_TYPE_DATETIME:
793+ case DRIZZLE_COLUMN_TYPE_TIMESTAMP:
794+ case DRIZZLE_COLUMN_TYPE_TINY_BLOB:
795+ case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:
796+ case DRIZZLE_COLUMN_TYPE_LONG_BLOB:
797+ case DRIZZLE_COLUMN_TYPE_BLOB:
798+ case DRIZZLE_COLUMN_TYPE_BIT:
799+ case DRIZZLE_COLUMN_TYPE_STRING:
800+ case DRIZZLE_COLUMN_TYPE_VAR_STRING:
801+ case DRIZZLE_COLUMN_TYPE_DECIMAL:
802+ case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:
803+ case DRIZZLE_COLUMN_TYPE_NEWDATE:
804+ case DRIZZLE_COLUMN_TYPE_VARCHAR:
805+ case DRIZZLE_COLUMN_TYPE_ENUM:
806+ case DRIZZLE_COLUMN_TYPE_SET:
807+ case DRIZZLE_COLUMN_TYPE_GEOMETRY:
808+ case DRIZZLE_COLUMN_TYPE_TIMESTAMP2:
809+ case DRIZZLE_COLUMN_TYPE_DATETIME2:
810+ case DRIZZLE_COLUMN_TYPE_TIME2:
811+ default:
812+ *ret_ptr= DRIZZLE_RETURN_INVALID_CONVERSION;
813+ val= 0;
814+ }
815+
816+ return val;
817+}
818+
819+double drizzle_stmt_get_double(drizzle_stmt_st *stmt, uint16_t column_number, drizzle_return_t *ret_ptr)
820+{
821+ double val;
822+ drizzle_bind_st *param;
823+ if ((stmt == NULL) || (stmt->result_params == NULL) || (column_number >= stmt->execute_result->column_count))
824+ {
825+ *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT;
826+ return 0;
827+ }
828+ param= &stmt->result_params[column_number];
829+ *ret_ptr= DRIZZLE_RETURN_OK;
830+ switch(param->type)
831+ {
832+ case DRIZZLE_COLUMN_TYPE_NULL:
833+ *ret_ptr= DRIZZLE_RETURN_NULL_SIZE;
834+ val= 0;
835+ break;
836+ case DRIZZLE_COLUMN_TYPE_TINY:
837+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
838+ val= (double) (*(uint8_t*)param->data);
839+ break;
840+ case DRIZZLE_COLUMN_TYPE_SHORT:
841+ case DRIZZLE_COLUMN_TYPE_YEAR:
842+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
843+ val= (double) (*(uint16_t*)param->data);
844+ break;
845+ case DRIZZLE_COLUMN_TYPE_INT24:
846+ case DRIZZLE_COLUMN_TYPE_LONG:
847+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
848+ val= (double) (*(uint32_t*)param->data);
849+ break;
850+ case DRIZZLE_COLUMN_TYPE_LONGLONG:
851+ *ret_ptr= DRIZZLE_RETURN_TRUNCATED;
852+ val= (double) (*(uint64_t*)param->data);
853+ break;
854+ case DRIZZLE_COLUMN_TYPE_FLOAT:
855+ val= (double) (*(float*)param->data);
856+ break;
857+ case DRIZZLE_COLUMN_TYPE_DOUBLE:
858+ val= (uint32_t) (*(double*)param->data);
859+ break;
860+ case DRIZZLE_COLUMN_TYPE_TIME:
861+ case DRIZZLE_COLUMN_TYPE_DATE:
862+ case DRIZZLE_COLUMN_TYPE_DATETIME:
863+ case DRIZZLE_COLUMN_TYPE_TIMESTAMP:
864+ case DRIZZLE_COLUMN_TYPE_TINY_BLOB:
865+ case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:
866+ case DRIZZLE_COLUMN_TYPE_LONG_BLOB:
867+ case DRIZZLE_COLUMN_TYPE_BLOB:
868+ case DRIZZLE_COLUMN_TYPE_BIT:
869+ case DRIZZLE_COLUMN_TYPE_STRING:
870+ case DRIZZLE_COLUMN_TYPE_VAR_STRING:
871+ case DRIZZLE_COLUMN_TYPE_DECIMAL:
872+ case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:
873+ case DRIZZLE_COLUMN_TYPE_NEWDATE:
874+ case DRIZZLE_COLUMN_TYPE_VARCHAR:
875+ case DRIZZLE_COLUMN_TYPE_ENUM:
876+ case DRIZZLE_COLUMN_TYPE_SET:
877+ case DRIZZLE_COLUMN_TYPE_GEOMETRY:
878+ case DRIZZLE_COLUMN_TYPE_TIMESTAMP2:
879+ case DRIZZLE_COLUMN_TYPE_DATETIME2:
880+ case DRIZZLE_COLUMN_TYPE_TIME2:
881+ default:
882+ *ret_ptr= DRIZZLE_RETURN_INVALID_CONVERSION;
883+ val= 0;
884+ }
885+
886+ return val;
887+}
888+
889+char *long_to_string(drizzle_bind_st *param, uint32_t val)
890+{
891+ /* Max length is -INT32_MAX + NUL = 12 */
892+ param->converted_data= (char*)realloc(param->converted_data, 12);
893+ if (param->options.is_unsigned)
894+ {
895+ snprintf(param->converted_data, 12, "%"PRIu32, val);
896+ }
897+ else
898+ {
899+ snprintf(param->converted_data, 12, "%"PRId32, (int32_t)val);
900+ }
901+ return param->converted_data;
902+}
903+
904+char *longlong_to_string(drizzle_bind_st *param, uint64_t val)
905+{
906+ /* Max length is -INT64_MAX + NUL = 21 */
907+ param->converted_data= (char*)realloc(param->converted_data, 21);
908+ if (param->options.is_unsigned)
909+ {
910+ snprintf(param->converted_data, 21, "%"PRIu64, val);
911+ }
912+ else
913+ {
914+ snprintf(param->converted_data, 21, "%"PRId64, (int64_t)val);
915+ }
916+ return param->converted_data;
917+}
918+
919+char *double_to_string(drizzle_bind_st *param, double val)
920+{
921+ /* Max length is 23 */
922+ param->converted_data= (char*)realloc(param->converted_data, 23);
923+ snprintf(param->converted_data, 23, "%f", val);
924+ return param->converted_data;
925+}
926+
927+char *time_to_string(drizzle_bind_st *param, drizzle_datetime_st *time)
928+{
929+ /* Max time is -HHH:MM:SS.ssssss + NUL = 17 */
930+ param->converted_data= (char*)realloc(param->converted_data, 17);
931+ if (time->microsecond == 0)
932+ {
933+ snprintf(param->converted_data, 17, "%s%"PRIu16":%"PRIu8":%"PRIu8, (time->negative) ? "-" : "", time->hour, time->minute, time->second);
934+ }
935+ else
936+ {
937+ snprintf(param->converted_data, 17, "%s%"PRIu16":%"PRIu8":%"PRIu8".%"PRIu32, (time->negative) ? "-" : "", time->hour, time->minute, time->second, time->microsecond);
938+ }
939+ return param->converted_data;
940+}
941+
942+char *timestamp_to_string(drizzle_bind_st *param, drizzle_datetime_st *timestamp)
943+{
944+ /* Max timestamp is YYYY-MM-DD HH:MM:SS.ssssss + NUL = 26 */
945+ param->converted_data= (char*)realloc(param->converted_data, 26);
946+ if (timestamp->microsecond == 0)
947+ {
948+ snprintf(param->converted_data, 26, "%"PRIu16"-%"PRIu8"-%"PRIu32" %"PRIu16":%"PRIu8":%"PRIu8, timestamp->year, timestamp->month, timestamp->day, timestamp->hour, timestamp->minute, timestamp->second);
949+ }
950+ else
951+ {
952+ snprintf(param->converted_data, 26, "%"PRIu16"-%"PRIu8"-%"PRIu32" %"PRIu16":%"PRIu8":%"PRIu8".%"PRIu32, timestamp->year, timestamp->month, timestamp->day, timestamp->hour, timestamp->minute, timestamp->second, timestamp->microsecond);
953+ }
954+ return param->converted_data;
955+}
956
957=== modified file 'libdrizzle/structs.h'
958--- libdrizzle/structs.h 2012-12-30 02:23:50 +0000
959+++ libdrizzle/structs.h 2012-12-31 10:04:21 +0000
960@@ -357,7 +357,14 @@
961 void *data;
962 uint32_t length;
963 bool is_bound;
964- drizzle_bind_options_t options;
965+ char *converted_data;
966+ struct
967+ {
968+ bool is_null;
969+ bool is_unsigned;
970+ bool is_long_data;
971+ bool is_allocated;
972+ } options;
973 };
974
975 #ifdef __cplusplus
976
977=== modified file 'tests/unit/include.am'
978--- tests/unit/include.am 2012-12-27 22:09:42 +0000
979+++ tests/unit/include.am 2012-12-31 10:04:21 +0000
980@@ -67,3 +67,8 @@
981 check_PROGRAMS+= tests/unit/statement
982 noinst_PROGRAMS+= tests/unit/statement
983
984+tests_unit_statement_char_SOURCES= tests/unit/statement_char.c
985+tests_unit_statement_char_LDADD= libdrizzle/libdrizzle.la
986+check_PROGRAMS+= tests/unit/statement_char
987+noinst_PROGRAMS+= tests/unit/statement_char
988+
989
990=== modified file 'tests/unit/statement.c'
991--- tests/unit/statement.c 2012-12-31 00:06:53 +0000
992+++ tests/unit/statement.c 2012-12-31 10:04:21 +0000
993@@ -91,7 +91,7 @@
994 ASSERT_EQ_(1, drizzle_stmt_param_count(stmt), "Retrieved bad param count");
995
996 uint32_t val= 1;
997- ret = drizzle_stmt_bind_param(stmt, 0, DRIZZLE_COLUMN_TYPE_LONG, &val, 4, DRIZZLE_BIND_OPTION_NONE);
998+ ret = drizzle_stmt_set_int(stmt, 0, val, false);
999 if (ret != DRIZZLE_RETURN_OK)
1000 {
1001 printf("Bind failure\n");
1002@@ -119,12 +119,24 @@
1003 uint32_t i= 1;
1004 while (drizzle_stmt_fetch(stmt) != DRIZZLE_RETURN_ROW_END)
1005 {
1006- uint32_t *res_val;
1007- res_val= (uint32_t*)drizzle_stmt_item_data(stmt, 0);
1008+ uint32_t res_val;
1009+ const char* char_val;
1010+ char comp_val[3];
1011+ size_t len;
1012+ res_val= drizzle_stmt_get_int(stmt, 0, &ret);
1013+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "drizzle_stmt_get_int");
1014+ char_val= drizzle_stmt_get_string(stmt, 0, &len, &ret);
1015+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "drizzle_stmt_get_string");
1016 i++;
1017- if (*res_val != i)
1018- {
1019- printf("Retrieved unexpected value\n");
1020+ if (res_val != i)
1021+ {
1022+ printf("Retrieved unexpected int value\n");
1023+ return EXIT_FAILURE;
1024+ }
1025+ snprintf(comp_val, 3, "%"PRIu32, i);
1026+ if (strcmp(comp_val, char_val) != 0)
1027+ {
1028+ printf("Retrieved unexpected string value\n");
1029 return EXIT_FAILURE;
1030 }
1031 }
1032
1033=== added file 'tests/unit/statement_char.c'
1034--- tests/unit/statement_char.c 1970-01-01 00:00:00 +0000
1035+++ tests/unit/statement_char.c 2012-12-31 10:04:21 +0000
1036@@ -0,0 +1,157 @@
1037+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1038+ *
1039+ * Drizzle Client & Protocol Library
1040+ *
1041+ * Copyright (C) 2012 Drizzle Developer Group
1042+ * All rights reserved.
1043+ *
1044+ * Redistribution and use in source and binary forms, with or without
1045+ * modification, are permitted provided that the following conditions are
1046+ * met:
1047+ *
1048+ * * Redistributions of source code must retain the above copyright
1049+ * notice, this list of conditions and the following disclaimer.
1050+ *
1051+ * * Redistributions in binary form must reproduce the above
1052+ * copyright notice, this list of conditions and the following disclaimer
1053+ * in the documentation and/or other materials provided with the
1054+ * distribution.
1055+ *
1056+ * * The names of its contributors may not be used to endorse or
1057+ * promote products derived from this software without specific prior
1058+ * written permission.
1059+ *
1060+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1061+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1062+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1063+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1064+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1065+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1066+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1067+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1068+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1069+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1070+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1071+ *
1072+ */
1073+
1074+#include <yatl/lite.h>
1075+
1076+#include <libdrizzle-5.1/libdrizzle.h>
1077+#include <stdio.h>
1078+#include <stdlib.h>
1079+#include <stdint.h>
1080+#include <string.h>
1081+#include <inttypes.h>
1082+#include <string.h>
1083+
1084+int main(int argc, char *argv[])
1085+{
1086+ (void) argc;
1087+ (void) argv;
1088+ drizzle_stmt_st *stmt;
1089+
1090+ drizzle_st *con= drizzle_create_tcp(getenv("MYSQL_SERVER"),
1091+ getenv("MYSQL_PORT") ? atoi("MYSQL_PORT") : DRIZZLE_DEFAULT_TCP_PORT,
1092+ getenv("MYSQL_USER"),
1093+ getenv("MYSQL_PASSWORD"),
1094+ getenv("MYSQL_SCHEMA"), 0);
1095+
1096+ ASSERT_NOT_NULL_(con, "Drizzle connection object creation error");
1097+
1098+ drizzle_return_t ret= drizzle_connect(con);
1099+ if (ret == DRIZZLE_RETURN_COULD_NOT_CONNECT)
1100+ {
1101+ const char *error= drizzle_error(con);
1102+ drizzle_quit(con);
1103+ SKIP_IF_(ret == DRIZZLE_RETURN_COULD_NOT_CONNECT, "%s(%s)", error, drizzle_strerror(ret));
1104+ }
1105+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "drizzle_connect(): %s(%s)", drizzle_error(con), drizzle_strerror(ret));
1106+
1107+ drizzle_query_str(con, "DROP SCHEMA IF EXISTS libdrizzle", &ret);
1108+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "CREATE SCHEMA libdrizzle (%s)", drizzle_error(con));
1109+
1110+ drizzle_query_str(con, "CREATE SCHEMA libdrizzle", &ret);
1111+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "CREATE SCHEMA libdrizzle (%s)", drizzle_error(con));
1112+
1113+ drizzle_result_st *result= drizzle_select_db(con, "libdrizzle", &ret);
1114+ ASSERT_TRUE(result);
1115+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "USE libdrizzle");
1116+
1117+ drizzle_query_str(con, "create table libdrizzle.t1 (a varchar(50))", &ret);
1118+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "create table libdrizzle.t1 (a int): %s", drizzle_error(con));
1119+
1120+ drizzle_query_str(con, "insert into libdrizzle.t1 values ('hello'),('drizzle'),('people')", &ret);
1121+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s", drizzle_error(con));
1122+
1123+ const char *query= "select * from libdrizzle.t1 where a = ?";
1124+ stmt= drizzle_stmt_prepare(con, query, strlen(query), &ret);
1125+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s", drizzle_error(con));
1126+
1127+ /* Query should have 1 param */
1128+ ASSERT_EQ_(1, drizzle_stmt_param_count(stmt), "Retrieved bad param count");
1129+
1130+ char val[]= "hello";
1131+ ret = drizzle_stmt_set_string(stmt, 0, val, strlen(val));
1132+ if (ret != DRIZZLE_RETURN_OK)
1133+ {
1134+ printf("Bind failure\n");
1135+ return EXIT_FAILURE;
1136+ }
1137+
1138+ ret = drizzle_stmt_execute(stmt);
1139+ if (ret != DRIZZLE_RETURN_OK)
1140+ {
1141+ printf("Execute failure\n");
1142+ return EXIT_FAILURE;
1143+ }
1144+ ret = drizzle_stmt_buffer(stmt);
1145+ if (ret != DRIZZLE_RETURN_OK)
1146+ {
1147+ printf("Buffer failure\n");
1148+ return EXIT_FAILURE;
1149+ }
1150+ /* Result should have 1 row */
1151+ if (drizzle_stmt_row_count(stmt) != 1)
1152+ {
1153+ printf("Retrieved bad row count\n");
1154+ return EXIT_FAILURE;
1155+ }
1156+ uint32_t i= 0;
1157+ while (drizzle_stmt_fetch(stmt) != DRIZZLE_RETURN_ROW_END)
1158+ {
1159+ const char* char_val;
1160+ size_t len;
1161+ char_val= drizzle_stmt_get_string(stmt, 0, &len, &ret);
1162+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "drizzle_stmt_get_string");
1163+ i++;
1164+ if (strncmp(val, char_val, len) != 0)
1165+ {
1166+ printf("Retrieved unexpected string value\n");
1167+ return EXIT_FAILURE;
1168+ }
1169+ }
1170+ /* Should have cycled through 1 row */
1171+ if (i != 1)
1172+ {
1173+ printf("Retrieved bad number of rows\n");
1174+ return EXIT_FAILURE;
1175+ }
1176+ ret = drizzle_stmt_close(stmt);
1177+ if (ret != DRIZZLE_RETURN_OK)
1178+ {
1179+ printf("Statement close failure ret: %d, err: %d, msg: %s\n", ret, drizzle_errno(con), drizzle_error(con));
1180+ return EXIT_FAILURE;
1181+ }
1182+
1183+ drizzle_query_str(con, "DROP TABLE libdrizzle.t1", &ret);
1184+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "DROP TABLE libdrizzle.t1");
1185+
1186+ drizzle_query_str(con, "DROP SCHEMA IF EXISTS libdrizzle", &ret);
1187+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "DROP SCHEMA libdrizzle (%s)", drizzle_error(con));
1188+
1189+ ret= drizzle_quit(con);
1190+ ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s", drizzle_strerror(ret));
1191+
1192+ return EXIT_SUCCESS;
1193+}

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: