Merge lp:~linuxjedi/libdrizzle/date-time into lp:libdrizzle

Proposed by Andrew Hutchings
Status: Merged
Approved by: Andrew Hutchings
Approved revision: 118
Merged at revision: 111
Proposed branch: lp:~linuxjedi/libdrizzle/date-time
Merge into: lp:libdrizzle
Diff against target: 455 lines (+125/-88)
12 files modified
configure.ac (+3/-0)
libdrizzle-5.1/constants.h (+2/-0)
libdrizzle/pack.cc (+50/-44)
libdrizzle/pack.h (+2/-2)
libdrizzle/statement.cc (+2/-2)
libdrizzle/statement_param.cc (+40/-19)
tests/unit/common.c (+3/-3)
tests/unit/common.h (+15/-14)
tests/unit/connect_uds.c (+1/-1)
tests/unit/datetypes.c (+4/-1)
tests/unit/include.am (+1/-0)
tests/unit/numbers.c (+2/-2)
To merge this branch: bzr merge lp:~linuxjedi/libdrizzle/date-time
Reviewer Review Type Date Requested Status
Drizzle Trunk Pending
Review via email: mp+159989@code.launchpad.net

Description of the change

Wraps up Wim's date/time fixes and fixes libdrizzle trunk so it should pass Jenkins tests.

To post a comment you must log in.
lp:~linuxjedi/libdrizzle/date-time updated
119. By Andrew Hutchings

Fix connect SKIP in common.c

120. By Andrew Hutchings

Fix UDS test SKIP

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2013-01-27 21:26:07 +0000
3+++ configure.ac 2013-04-21 22:19:27 +0000
4@@ -62,6 +62,9 @@
5
6 AC_PATH_ZLIB
7
8+# Check for -lm
9+LT_LIB_M
10+
11 # Checks for header files.
12 AC_DEFUN([CHECK_FOR_CXXABI],
13 [AC_LANG_PUSH([C++])
14
15=== modified file 'libdrizzle-5.1/constants.h'
16--- libdrizzle-5.1/constants.h 2013-03-05 03:27:07 +0000
17+++ libdrizzle-5.1/constants.h 2013-04-21 22:19:27 +0000
18@@ -621,6 +621,8 @@
19 ((uint64_t)drizzle_get_byte4(((uint8_t *)__buffer)+4) << 32))
20
21 /* Protocol packing macros. */
22+#define drizzle_set_byte1(__buffer, __int) do { \
23+ (__buffer)[0] = (uint8_t)(__int); } while (0)
24 #define drizzle_set_byte2(__buffer, __int) do { \
25 (__buffer)[0]= (uint8_t)((__int) & 0xFF); \
26 (__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); } while (0)
27
28=== modified file 'libdrizzle/pack.cc'
29--- libdrizzle/pack.cc 2013-03-12 16:33:14 +0000
30+++ libdrizzle/pack.cc 2013-04-21 22:19:27 +0000
31@@ -193,71 +193,78 @@
32 {
33 uint8_t length= 0;
34
35- /* If nothing is set then we are sending a 0 length time */
36- if (time->day || time->hour || time->minute || time->second)
37- {
38- ptr[0]= (time->negative) ? 1 : 0;
39- drizzle_set_byte4(&ptr[1], time->day);
40- ptr[5]= (uint8_t) time->hour;
41- ptr[6]= time->minute;
42- ptr[7]= time->second;
43- length= 8;
44- }
45 /* NOTE: MySQL has a bug here and doesn't follow this part of the protocol
46 * when packing, we will for now, no idea if it works
47 * */
48 if (time->microsecond)
49 {
50- drizzle_set_byte4(&ptr[8], time->microsecond);
51+ drizzle_set_byte4(ptr+9, time->microsecond);
52 length= 12;
53 }
54- return ptr+length;
55+
56+ if (length || time->day || time->hour || time->minute || time->second)
57+ {
58+ ptr[1]= (time->negative) ? 1 : 0;
59+ drizzle_set_byte4(ptr+2, time->day);
60+ drizzle_set_byte1(ptr+6, time->hour);
61+ drizzle_set_byte1(ptr+7, time->minute);
62+ drizzle_set_byte1(ptr+8, time->second);
63+ /* If no microseconds, then we are packing 8 bytes */
64+ if (!length)
65+ length= 8;
66+ }
67+
68+ /* If nothing is set then we are sending a 0 length time */
69+
70+ drizzle_set_byte1(ptr, length);
71+ return ptr + 1 + length;
72 }
73
74 unsigned char *drizzle_pack_datetime(drizzle_datetime_st *datetime, unsigned char *ptr)
75 {
76 uint8_t length= 0;
77
78+ if (datetime->microsecond)
79+ {
80+ drizzle_set_byte4(ptr+8, datetime->microsecond);
81+ length = 11;
82+ }
83+
84+ if (length || datetime->hour || datetime->minute || datetime->second)
85+ {
86+ drizzle_set_byte1(ptr+5, datetime->hour);
87+ drizzle_set_byte1(ptr+6, datetime->minute);
88+ drizzle_set_byte1(ptr+7, datetime->second);
89+ /* If only date+time is provided then we are packing 7 bytes */
90+ if (!length)
91+ length = 7;
92+ }
93+
94+ if (length || datetime->year || datetime->month || datetime->day)
95+ {
96+ drizzle_set_byte2(ptr+1, datetime->year);
97+ drizzle_set_byte1(ptr+3, datetime->month);
98+ drizzle_set_byte1(ptr+4, datetime->day);
99+ /* If only date is provided then we are packing 4 bytes */
100+ if (!length)
101+ length = 4;
102+ }
103+
104 /* If nothing is set then we are sending a 0 length datetime */
105
106- /* If only date is provided then we are packing 4 bytes */
107- if (datetime->year || datetime->month || datetime->day)
108- {
109- drizzle_set_byte2(ptr, datetime->year);
110- ptr[2]= datetime->month;
111- ptr[3]= datetime->day;
112- length= 4;
113- }
114-
115- if (datetime->hour || datetime->minute || datetime->second)
116- {
117- ptr[4]= (uint8_t) datetime->hour;
118- ptr[5]= datetime->minute;
119- ptr[6]= datetime->second;
120- length= 7;
121- }
122-
123- if (datetime->microsecond)
124- {
125- drizzle_set_byte4(&ptr[7], datetime->microsecond);
126- length= 11;
127- }
128-
129- return ptr + length;
130+ drizzle_set_byte1(ptr, length);
131+ return ptr + 1 + length;
132 }
133
134-void drizzle_unpack_time(drizzle_field_t field, size_t length, unsigned char *data)
135+void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime)
136 {
137- drizzle_datetime_st *datetime= (drizzle_datetime_st*) data;
138- memset(datetime, 0, length);
139+ memset(datetime, 0, sizeof(*datetime));
140
141 if (length)
142 {
143 datetime->negative= field[0];
144 datetime->day= drizzle_get_byte4(&field[1]);
145 datetime->hour= field[5];
146- datetime->hour= datetime->day * 24;
147- datetime->day= 0;
148 datetime->minute= field[6];
149 datetime->second= field[7];
150 if (length > 8)
151@@ -267,10 +274,9 @@
152 }
153 }
154
155-void drizzle_unpack_datetime(drizzle_field_t field, size_t length, unsigned char *data)
156+void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime)
157 {
158- drizzle_datetime_st *datetime= (drizzle_datetime_st*) data;
159- memset(datetime, 0, length);
160+ memset(datetime, 0, sizeof(*datetime));
161
162 if (length)
163 {
164
165=== modified file 'libdrizzle/pack.h'
166--- libdrizzle/pack.h 2013-03-06 18:05:42 +0000
167+++ libdrizzle/pack.h 2013-04-21 22:19:27 +0000
168@@ -79,9 +79,9 @@
169
170 unsigned char *drizzle_pack_datetime(drizzle_datetime_st *datetime, unsigned char *ptr);
171
172-void drizzle_unpack_time(drizzle_field_t field, size_t length, unsigned char *data);
173+void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime);
174
175-void drizzle_unpack_datetime(drizzle_field_t field, size_t length, unsigned char *data);
176+void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime);
177
178 /**
179 * Unpack length-encoded string.
180
181=== modified file 'libdrizzle/statement.cc'
182--- libdrizzle/statement.cc 2013-03-21 10:44:02 +0000
183+++ libdrizzle/statement.cc 2013-04-21 22:19:27 +0000
184@@ -471,13 +471,13 @@
185 break;
186 case DRIZZLE_COLUMN_TYPE_TIME:
187 param->data= param->data_buffer;
188- drizzle_unpack_time(row[column_counter], param->length, (unsigned char*)param->data);
189+ drizzle_unpack_time(row[column_counter], param->length, (drizzle_datetime_st *)param->data);
190 break;
191 case DRIZZLE_COLUMN_TYPE_DATE:
192 case DRIZZLE_COLUMN_TYPE_DATETIME:
193 case DRIZZLE_COLUMN_TYPE_TIMESTAMP:
194 param->data= param->data_buffer;
195- drizzle_unpack_datetime(row[column_counter], param->length, (unsigned char*)param->data);
196+ drizzle_unpack_datetime(row[column_counter], param->length, (drizzle_datetime_st *)param->data);
197 break;
198 case DRIZZLE_COLUMN_TYPE_TINY_BLOB:
199 case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:
200
201=== modified file 'libdrizzle/statement_param.cc'
202--- libdrizzle/statement_param.cc 2013-03-11 17:33:00 +0000
203+++ libdrizzle/statement_param.cc 2013-04-21 22:19:27 +0000
204@@ -129,6 +129,8 @@
205 drizzle_datetime_st *time;
206 time= (drizzle_datetime_st*) stmt->query_params[param_num].data_buffer;
207
208+ bzero(time, sizeof(*time));
209+
210 time->negative= is_negative;
211 time->day= days;
212 time->hour= hours;
213@@ -145,6 +147,8 @@
214 drizzle_datetime_st *timestamp;
215 timestamp= (drizzle_datetime_st*) stmt->query_params[param_num].data_buffer;
216
217+ bzero(timestamp, sizeof(*timestamp));
218+
219 timestamp->negative= false;
220 timestamp->year= year;
221 timestamp->day= day;
222@@ -156,7 +160,7 @@
223 timestamp->microsecond= microseconds;
224
225 /* Length not important because we will figure that out when packing */
226- return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TIME, timestamp, 0, false);
227+ return drizzle_stmt_set_param(stmt, param_num, DRIZZLE_COLUMN_TYPE_TIMESTAMP, timestamp, 0, false);
228 }
229
230 bool drizzle_stmt_get_is_null_from_name(drizzle_stmt_st *stmt, const char *column_name, drizzle_return_t *ret_ptr)
231@@ -546,7 +550,7 @@
232 val= (double) (*(float*)param->data);
233 break;
234 case DRIZZLE_COLUMN_TYPE_DOUBLE:
235- val= (uint32_t) (*(double*)param->data);
236+ val= (*(double*)param->data);
237 break;
238 case DRIZZLE_COLUMN_TYPE_TIME:
239 case DRIZZLE_COLUMN_TYPE_DATE:
240@@ -619,29 +623,46 @@
241 {
242 /* Max time is -HHH:MM:SS.ssssss + NUL = 17 */
243 char* buffer= param->data_buffer + 50;
244- if (time->microsecond == 0)
245- {
246- snprintf(buffer, 17, "%s%"PRIu16":%"PRIu8":%"PRIu8, (time->negative) ? "-" : "", time->hour, time->minute, time->second);
247- }
248- else
249- {
250- snprintf(buffer, 17, "%s%"PRIu16":%"PRIu8":%"PRIu8".%"PRIu32, (time->negative) ? "-" : "", time->hour, time->minute, time->second, time->microsecond);
251- }
252+ int buffersize = 17;
253+ int used = 0;
254+
255+ /* Values are transferred with days separated from hours, but presented with days folded into hours. */
256+ used = snprintf(buffer, buffersize-used, "%s%02u:%02"PRIu8":%02"PRIu8, (time->negative) ? "-" : "", time->hour + 24 * time->day, time->minute, time->second);
257+
258+ /* TODO: the existence (and length) of the decimals should be decided based on the number of fields sent by the server or possibly the column's "decimals" value, not by whether the microseconds are 0 */
259+ if (time->microsecond)
260+ used += snprintf(buffer+used, buffersize-used, ".%06" PRIu32, time->microsecond);
261+
262+ assert(used < buffersize);
263+
264 return buffer;
265 }
266
267 char *timestamp_to_string(drizzle_bind_st *param, drizzle_datetime_st *timestamp)
268 {
269- /* Max timestamp is YYYY-MM-DD HH:MM:SS.ssssss + NUL = 26 */
270+ /* Max timestamp is YYYY-MM-DD HH:MM:SS.ssssss + NUL = 27 */
271 char* buffer= param->data_buffer + 50;
272- if (timestamp->microsecond == 0)
273- {
274- snprintf(buffer, 26, "%"PRIu16"-%"PRIu8"-%"PRIu32" %"PRIu16":%"PRIu8":%"PRIu8, timestamp->year, timestamp->month, timestamp->day, timestamp->hour, timestamp->minute, timestamp->second);
275- }
276- else
277- {
278- snprintf(buffer, 26, "%"PRIu16"-%"PRIu8"-%"PRIu32" %"PRIu16":%"PRIu8":%"PRIu8".%"PRIu32, timestamp->year, timestamp->month, timestamp->day, timestamp->hour, timestamp->minute, timestamp->second, timestamp->microsecond);
279- }
280+ int buffersize = 27;
281+ int used = 0;
282+
283+ used += snprintf(buffer, buffersize-used, "%"PRIu16"-%02"PRIu8"-%02"PRIu32,
284+ timestamp->year, timestamp->month, timestamp->day);
285+ assert(used < buffersize);
286+
287+ if (param->type == DRIZZLE_COLUMN_TYPE_DATE)
288+ return buffer;
289+
290+ used += snprintf(buffer+used, buffersize-used, " %02"PRIu16":%02"PRIu8":%02"PRIu8,
291+ timestamp->hour, timestamp->minute, timestamp->second);
292+
293+ /* TODO: the existence (and length) of the decimals should be decided based on the number of fields sent by the server or possibly the column's "decimals" value, not by whether the microseconds are 0 */
294+ if (timestamp->microsecond)
295+ {
296+ used += snprintf(buffer+used, buffersize-used, ".%06"PRIu32, timestamp->microsecond);
297+ }
298+
299+ assert(used < buffersize);
300+
301 return buffer;
302 }
303
304
305=== modified file 'tests/unit/common.c'
306--- tests/unit/common.c 2013-03-19 20:38:59 +0000
307+++ tests/unit/common.c 2013-04-21 22:19:27 +0000
308@@ -66,16 +66,16 @@
309 getenv("MYSQL_PASSWORD"),
310 getenv("MYSQL_SCHEMA"), 0);
311 ASSERT_NOT_NULL_(con, "Drizzle connection object creation error");
312- atexit(close_connection_on_exit);
313
314 driz_ret= drizzle_connect(con);
315 SKIP_IF_(driz_ret == DRIZZLE_RETURN_COULD_NOT_CONNECT, "%s", drizzle_strerror(driz_ret));
316+ atexit(close_connection_on_exit);
317 ASSERT_EQ_(DRIZZLE_RETURN_OK, driz_ret, "%s(%s)", drizzle_error(con), drizzle_strerror(driz_ret));
318 }
319
320 void set_up_schema(void)
321 {
322- drizzle_result_st *result;
323+ drizzle_result_st VARIABLE_IS_NOT_USED *result;
324 drizzle_return_t driz_ret;
325
326 CHECKED_QUERY("DROP SCHEMA IF EXISTS libdrizzle");
327@@ -85,7 +85,7 @@
328
329 void tear_down_schema(void)
330 {
331- drizzle_result_st *result;
332+ drizzle_result_st VARIABLE_IS_NOT_USED *result;
333 drizzle_return_t driz_ret;
334
335 CHECKED_QUERY("DROP SCHEMA IF EXISTS libdrizzle");
336
337=== modified file 'tests/unit/common.h'
338--- tests/unit/common.h 2013-03-19 20:38:59 +0000
339+++ tests/unit/common.h 2013-04-21 22:19:27 +0000
340@@ -37,18 +37,21 @@
341
342 #pragma once
343
344-#ifdef __cplusplus
345-# include <cstdlib>
346-# include <cstdio>
347+#include <stdlib.h>
348+#include <stdio.h>
349+
350+#include <libdrizzle-5.1/libdrizzle.h>
351+
352+#ifdef __GNUC__
353+#define VARIABLE_IS_NOT_USED __attribute__ ((unused))
354+#else
355+#define VARIABLE_IS_NOT_USED
356+#endif
357+
358+#ifdef __cplusplus
359 extern "C" {
360-#else
361-# include <stdlib.h>
362-# include <stdio.h>
363 #endif
364
365-#include <libdrizzle-5.1/libdrizzle.h>
366-
367-
368 extern drizzle_st *con;
369
370 /* Common connection setup used by the unit tests.
371@@ -61,10 +64,6 @@
372 extern void set_up_schema(void);
373 extern void tear_down_schema(void);
374
375-#ifdef __cplusplus
376-} /* extern "C" */
377-#endif
378-
379 /* Perform a query; assign the result to 'result' and the returncode to 'driz_ret'; assert that the returncode is DRIZZLE_RETURN_OK. */
380 #define CHECKED_QUERY(cmd) result = drizzle_query(con, cmd, 0, &driz_ret); \
381 ASSERT_EQ_(driz_ret, DRIZZLE_RETURN_OK, "Error (%s): %s, from \"%s\"", drizzle_strerror(driz_ret), drizzle_error(con), cmd);
382@@ -73,4 +72,6 @@
383 #define CHECK(s) driz_ret = (s); \
384 ASSERT_EQ_(driz_ret, DRIZZLE_RETURN_OK, "Error (%s): %s, in \"%s\"", drizzle_strerror(driz_ret), drizzle_error(con), #s);
385
386-
387+#ifdef __cplusplus
388+} /* extern "C" */
389+#endif
390
391=== modified file 'tests/unit/connect_uds.c'
392--- tests/unit/connect_uds.c 2013-03-19 20:38:59 +0000
393+++ tests/unit/connect_uds.c 2013-04-21 22:19:27 +0000
394@@ -55,10 +55,10 @@
395 getenv("MYSQL_PASSWORD"),
396 getenv("MYSQL_SCHEMA"), 0);
397 ASSERT_NOT_NULL_(con, "Drizzle connection object creation error");
398- atexit(close_connection_on_exit);
399
400 drizzle_return_t ret= drizzle_connect(con);
401 SKIP_IF_(ret == DRIZZLE_RETURN_COULD_NOT_CONNECT, "%s(%s)", drizzle_error(con), drizzle_strerror(ret));
402+ atexit(close_connection_on_exit);
403 ASSERT_EQ_(DRIZZLE_RETURN_OK, ret, "%s socket: %s", drizzle_strerror(ret), getenv("MYSQL_SOCK"));
404
405 drizzle_query(con, "SELECT 1", 0, &ret);
406
407=== modified file 'tests/unit/datetypes.c'
408--- tests/unit/datetypes.c 2013-03-19 21:04:42 +0000
409+++ tests/unit/datetypes.c 2013-04-21 22:19:27 +0000
410@@ -35,6 +35,8 @@
411 *
412 */
413
414+#define _GNU_SOURCE
415+
416 #include <yatl/lite.h>
417 #include "tests/unit/common.h"
418
419@@ -276,7 +278,8 @@
420 for (unsigned checking_column = 2; checking_column < 10; checking_column ++) {
421 const char *col_name = column_names[checking_column];
422 char *query_buf = NULL;
423- asprintf(&query_buf, "select a, %s, cast(%s as char) from libdrizzle.dt1",
424+ int VARIABLE_IS_NOT_USED unused;
425+ unused = asprintf(&query_buf, "select a, %s, cast(%s as char) from libdrizzle.dt1",
426 col_name, col_name);
427 query = query_buf;
428
429
430=== modified file 'tests/unit/include.am'
431--- tests/unit/include.am 2013-03-19 21:04:42 +0000
432+++ tests/unit/include.am 2013-04-21 22:19:27 +0000
433@@ -49,6 +49,7 @@
434
435 tests_unit_numbers_SOURCES= tests/unit/numbers.c tests/unit/common.c
436 tests_unit_numbers_LDADD= libdrizzle/libdrizzle.la
437+tests_unit_numbers_LDADD+= -lm
438 check_PROGRAMS+= tests/unit/numbers
439 noinst_PROGRAMS+= tests/unit/numbers
440
441
442=== modified file 'tests/unit/numbers.c'
443--- tests/unit/numbers.c 2013-03-19 20:38:59 +0000
444+++ tests/unit/numbers.c 2013-04-21 22:19:27 +0000
445@@ -257,8 +257,8 @@
446 ASSERT_STREQ(expect_strval, col_strval);
447 }
448
449- float expect_floatval;
450- double expect_dblval;
451+ float expect_floatval = 0.0;
452+ double expect_dblval = 0.0;
453 switch (columnA) {
454 case 1:
455 expect_floatval = 1.0;

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: