Merge lp:~linuxjedi/libdrizzle/5.1-fixes into lp:libdrizzle

Proposed by Andrew Hutchings on 2013-04-25
Status: Merged
Approved by: Andrew Hutchings on 2013-04-25
Approved revision: 117
Merged at revision: 116
Proposed branch: lp:~linuxjedi/libdrizzle/5.1-fixes
Merge into: lp:libdrizzle
Diff against target: 144 lines (+19/-12)
7 files modified
libdrizzle/datetime.h (+1/-0)
libdrizzle/pack.cc (+10/-2)
libdrizzle/pack.h (+2/-2)
libdrizzle/statement.cc (+2/-2)
libdrizzle/statement_param.cc (+3/-4)
tests/unit/datetypes.c (+1/-1)
tests/unit/include.am (+0/-1)
To merge this branch: bzr merge lp:~linuxjedi/libdrizzle/5.1-fixes
Reviewer Review Type Date Requested Status
Drizzle Trunk 2013-04-25 Pending
Review via email: mp+160847@code.launchpad.net

Description of the change

Fix datetime output for prepared statement

Microsecond handling and leading zeros were incorrect

(Wim's test case now passes! :)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdrizzle/datetime.h'
2--- libdrizzle/datetime.h 2013-01-27 11:55:48 +0000
3+++ libdrizzle/datetime.h 2013-04-25 10:18:28 +0000
4@@ -47,6 +47,7 @@
5 uint8_t second;
6 uint32_t microsecond;
7 bool negative;
8+ bool show_microseconds;
9 };
10
11
12
13=== modified file 'libdrizzle/pack.cc'
14--- libdrizzle/pack.cc 2013-03-25 17:37:33 +0000
15+++ libdrizzle/pack.cc 2013-04-25 10:18:28 +0000
16@@ -256,7 +256,7 @@
17 return ptr + 1 + length;
18 }
19
20-void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime)
21+void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime, uint8_t decimals)
22 {
23 memset(datetime, 0, sizeof(*datetime));
24
25@@ -271,10 +271,14 @@
26 {
27 datetime->microsecond= drizzle_get_byte4(&field[8]);
28 }
29+ if (decimals)
30+ {
31+ datetime->show_microseconds= true;
32+ }
33 }
34 }
35
36-void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime)
37+void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime, uint8_t decimals)
38 {
39 memset(datetime, 0, sizeof(*datetime));
40
41@@ -294,6 +298,10 @@
42 datetime->microsecond= drizzle_get_byte4(&field[7]);
43 }
44 }
45+ if (decimals)
46+ {
47+ datetime->show_microseconds= true;
48+ }
49 }
50 }
51
52
53=== modified file 'libdrizzle/pack.h'
54--- libdrizzle/pack.h 2013-03-19 17:26:38 +0000
55+++ libdrizzle/pack.h 2013-04-25 10:18:28 +0000
56@@ -79,9 +79,9 @@
57
58 unsigned char *drizzle_pack_datetime(drizzle_datetime_st *datetime, unsigned char *ptr);
59
60-void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime);
61+void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime, uint8_t decimals);
62
63-void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime);
64+void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime, uint8_t decimals);
65
66 /**
67 * Unpack length-encoded string.
68
69=== modified file 'libdrizzle/statement.cc'
70--- libdrizzle/statement.cc 2013-04-22 18:32:01 +0000
71+++ libdrizzle/statement.cc 2013-04-25 10:18:28 +0000
72@@ -485,13 +485,13 @@
73 break;
74 case DRIZZLE_COLUMN_TYPE_TIME:
75 param->data= param->data_buffer;
76- drizzle_unpack_time(row[current_column], param->length, (drizzle_datetime_st *)param->data);
77+ drizzle_unpack_time(row[current_column], param->length, (drizzle_datetime_st *)param->data, stmt->execute_result->column_buffer[current_column].decimals);
78 break;
79 case DRIZZLE_COLUMN_TYPE_DATE:
80 case DRIZZLE_COLUMN_TYPE_DATETIME:
81 case DRIZZLE_COLUMN_TYPE_TIMESTAMP:
82 param->data= param->data_buffer;
83- drizzle_unpack_datetime(row[current_column], param->length, (drizzle_datetime_st *)param->data);
84+ drizzle_unpack_datetime(row[current_column], param->length, (drizzle_datetime_st *)param->data, stmt->execute_result->column_buffer[current_column].decimals);
85 break;
86 case DRIZZLE_COLUMN_TYPE_TINY_BLOB:
87 case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:
88
89=== modified file 'libdrizzle/statement_param.cc'
90--- libdrizzle/statement_param.cc 2013-04-25 08:58:44 +0000
91+++ libdrizzle/statement_param.cc 2013-04-25 10:18:28 +0000
92@@ -642,7 +642,7 @@
93 used = snprintf(buffer, buffersize-used, "%s%02u:%02"PRIu8":%02"PRIu8, (time->negative) ? "-" : "", time->hour + 24 * time->day, time->minute, time->second);
94
95 /* 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 */
96- if (time->microsecond)
97+ if (time->microsecond || time->show_microseconds)
98 used += snprintf(buffer+used, buffersize-used, ".%06" PRIu32, time->microsecond);
99
100 assert(used < buffersize);
101@@ -657,7 +657,7 @@
102 int buffersize = 27;
103 int used = 0;
104
105- used += snprintf(buffer, buffersize-used, "%"PRIu16"-%02"PRIu8"-%02"PRIu32,
106+ used += snprintf(buffer, buffersize-used, "%04"PRIu16"-%02"PRIu8"-%02"PRIu32,
107 timestamp->year, timestamp->month, timestamp->day);
108 assert(used < buffersize);
109
110@@ -667,8 +667,7 @@
111 used += snprintf(buffer+used, buffersize-used, " %02"PRIu16":%02"PRIu8":%02"PRIu8,
112 timestamp->hour, timestamp->minute, timestamp->second);
113
114- /* 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 */
115- if (timestamp->microsecond)
116+ if (timestamp->microsecond || timestamp->show_microseconds)
117 {
118 used += snprintf(buffer+used, buffersize-used, ".%06"PRIu32, timestamp->microsecond);
119 }
120
121=== modified file 'tests/unit/datetypes.c'
122--- tests/unit/datetypes.c 2013-04-23 20:33:18 +0000
123+++ tests/unit/datetypes.c 2013-04-25 10:18:28 +0000
124@@ -252,7 +252,7 @@
125 if (cur_row == 2) {
126 ASSERT_COL_STREQ_(2, "1984-02-29");
127 } else if (cur_row == 4) {
128- ASSERT_COL_STREQ_(2, "0084-02-29"); /* Yes, year 84, during the reign of Domitian */
129+ ASSERT_COL_STREQ_(2, "0084-02-09"); /* Yes, year 84, during the reign of Domitian */
130 }
131
132 /* TODO: libdrizzle currently has no way to give us access to the actual returned values for time/date fields. If that changes, test the values here. */
133
134=== modified file 'tests/unit/include.am'
135--- tests/unit/include.am 2013-04-22 19:14:35 +0000
136+++ tests/unit/include.am 2013-04-25 10:18:28 +0000
137@@ -57,7 +57,6 @@
138 tests_unit_datetypes_LDADD= libdrizzle/libdrizzle.la
139 check_PROGRAMS+= tests/unit/datetypes
140 noinst_PROGRAMS+= tests/unit/datetypes
141-XFAIL_TESTS+= tests/unit/datetypes
142
143 tests_unit_nulls_SOURCES= tests/unit/nulls.c tests/unit/common.c
144 tests_unit_nulls_LDADD= libdrizzle/libdrizzle.la

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: