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