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
=== modified file 'libdrizzle/datetime.h'
--- libdrizzle/datetime.h 2013-01-27 11:55:48 +0000
+++ libdrizzle/datetime.h 2013-04-25 10:18:28 +0000
@@ -47,6 +47,7 @@
47 uint8_t second;47 uint8_t second;
48 uint32_t microsecond;48 uint32_t microsecond;
49 bool negative;49 bool negative;
50 bool show_microseconds;
50};51};
5152
5253
5354
=== modified file 'libdrizzle/pack.cc'
--- libdrizzle/pack.cc 2013-03-25 17:37:33 +0000
+++ libdrizzle/pack.cc 2013-04-25 10:18:28 +0000
@@ -256,7 +256,7 @@
256 return ptr + 1 + length;256 return ptr + 1 + length;
257}257}
258258
259void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime)259void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime, uint8_t decimals)
260{260{
261 memset(datetime, 0, sizeof(*datetime));261 memset(datetime, 0, sizeof(*datetime));
262262
@@ -271,10 +271,14 @@
271 {271 {
272 datetime->microsecond= drizzle_get_byte4(&field[8]);272 datetime->microsecond= drizzle_get_byte4(&field[8]);
273 }273 }
274 if (decimals)
275 {
276 datetime->show_microseconds= true;
277 }
274 }278 }
275}279}
276280
277void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime)281void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime, uint8_t decimals)
278{282{
279 memset(datetime, 0, sizeof(*datetime));283 memset(datetime, 0, sizeof(*datetime));
280284
@@ -294,6 +298,10 @@
294 datetime->microsecond= drizzle_get_byte4(&field[7]);298 datetime->microsecond= drizzle_get_byte4(&field[7]);
295 }299 }
296 }300 }
301 if (decimals)
302 {
303 datetime->show_microseconds= true;
304 }
297 }305 }
298}306}
299307
300308
=== modified file 'libdrizzle/pack.h'
--- libdrizzle/pack.h 2013-03-19 17:26:38 +0000
+++ libdrizzle/pack.h 2013-04-25 10:18:28 +0000
@@ -79,9 +79,9 @@
7979
80unsigned char *drizzle_pack_datetime(drizzle_datetime_st *datetime, unsigned char *ptr);80unsigned char *drizzle_pack_datetime(drizzle_datetime_st *datetime, unsigned char *ptr);
8181
82void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime);82void drizzle_unpack_time(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime, uint8_t decimals);
8383
84void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime);84void drizzle_unpack_datetime(drizzle_field_t field, size_t length, drizzle_datetime_st *datetime, uint8_t decimals);
8585
86/**86/**
87 * Unpack length-encoded string.87 * Unpack length-encoded string.
8888
=== modified file 'libdrizzle/statement.cc'
--- libdrizzle/statement.cc 2013-04-22 18:32:01 +0000
+++ libdrizzle/statement.cc 2013-04-25 10:18:28 +0000
@@ -485,13 +485,13 @@
485 break;485 break;
486 case DRIZZLE_COLUMN_TYPE_TIME:486 case DRIZZLE_COLUMN_TYPE_TIME:
487 param->data= param->data_buffer;487 param->data= param->data_buffer;
488 drizzle_unpack_time(row[current_column], param->length, (drizzle_datetime_st *)param->data);488 drizzle_unpack_time(row[current_column], param->length, (drizzle_datetime_st *)param->data, stmt->execute_result->column_buffer[current_column].decimals);
489 break;489 break;
490 case DRIZZLE_COLUMN_TYPE_DATE:490 case DRIZZLE_COLUMN_TYPE_DATE:
491 case DRIZZLE_COLUMN_TYPE_DATETIME:491 case DRIZZLE_COLUMN_TYPE_DATETIME:
492 case DRIZZLE_COLUMN_TYPE_TIMESTAMP:492 case DRIZZLE_COLUMN_TYPE_TIMESTAMP:
493 param->data= param->data_buffer;493 param->data= param->data_buffer;
494 drizzle_unpack_datetime(row[current_column], param->length, (drizzle_datetime_st *)param->data);494 drizzle_unpack_datetime(row[current_column], param->length, (drizzle_datetime_st *)param->data, stmt->execute_result->column_buffer[current_column].decimals);
495 break;495 break;
496 case DRIZZLE_COLUMN_TYPE_TINY_BLOB:496 case DRIZZLE_COLUMN_TYPE_TINY_BLOB:
497 case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:497 case DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB:
498498
=== modified file 'libdrizzle/statement_param.cc'
--- libdrizzle/statement_param.cc 2013-04-25 08:58:44 +0000
+++ libdrizzle/statement_param.cc 2013-04-25 10:18:28 +0000
@@ -642,7 +642,7 @@
642 used = snprintf(buffer, buffersize-used, "%s%02u:%02"PRIu8":%02"PRIu8, (time->negative) ? "-" : "", time->hour + 24 * time->day, time->minute, time->second);642 used = snprintf(buffer, buffersize-used, "%s%02u:%02"PRIu8":%02"PRIu8, (time->negative) ? "-" : "", time->hour + 24 * time->day, time->minute, time->second);
643643
644 /* 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 */644 /* 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 */
645 if (time->microsecond)645 if (time->microsecond || time->show_microseconds)
646 used += snprintf(buffer+used, buffersize-used, ".%06" PRIu32, time->microsecond);646 used += snprintf(buffer+used, buffersize-used, ".%06" PRIu32, time->microsecond);
647 647
648 assert(used < buffersize);648 assert(used < buffersize);
@@ -657,7 +657,7 @@
657 int buffersize = 27;657 int buffersize = 27;
658 int used = 0;658 int used = 0;
659 659
660 used += snprintf(buffer, buffersize-used, "%"PRIu16"-%02"PRIu8"-%02"PRIu32,660 used += snprintf(buffer, buffersize-used, "%04"PRIu16"-%02"PRIu8"-%02"PRIu32,
661 timestamp->year, timestamp->month, timestamp->day);661 timestamp->year, timestamp->month, timestamp->day);
662 assert(used < buffersize);662 assert(used < buffersize);
663 663
@@ -667,8 +667,7 @@
667 used += snprintf(buffer+used, buffersize-used, " %02"PRIu16":%02"PRIu8":%02"PRIu8,667 used += snprintf(buffer+used, buffersize-used, " %02"PRIu16":%02"PRIu8":%02"PRIu8,
668 timestamp->hour, timestamp->minute, timestamp->second);668 timestamp->hour, timestamp->minute, timestamp->second);
669669
670 /* 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 */670 if (timestamp->microsecond || timestamp->show_microseconds)
671 if (timestamp->microsecond)
672 {671 {
673 used += snprintf(buffer+used, buffersize-used, ".%06"PRIu32, timestamp->microsecond);672 used += snprintf(buffer+used, buffersize-used, ".%06"PRIu32, timestamp->microsecond);
674 }673 }
675674
=== modified file 'tests/unit/datetypes.c'
--- tests/unit/datetypes.c 2013-04-23 20:33:18 +0000
+++ tests/unit/datetypes.c 2013-04-25 10:18:28 +0000
@@ -252,7 +252,7 @@
252 if (cur_row == 2) {252 if (cur_row == 2) {
253 ASSERT_COL_STREQ_(2, "1984-02-29");253 ASSERT_COL_STREQ_(2, "1984-02-29");
254 } else if (cur_row == 4) {254 } else if (cur_row == 4) {
255 ASSERT_COL_STREQ_(2, "0084-02-29"); /* Yes, year 84, during the reign of Domitian */255 ASSERT_COL_STREQ_(2, "0084-02-09"); /* Yes, year 84, during the reign of Domitian */
256 }256 }
257257
258 /* 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. */258 /* 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. */
259259
=== modified file 'tests/unit/include.am'
--- tests/unit/include.am 2013-04-22 19:14:35 +0000
+++ tests/unit/include.am 2013-04-25 10:18:28 +0000
@@ -57,7 +57,6 @@
57tests_unit_datetypes_LDADD= libdrizzle/libdrizzle.la57tests_unit_datetypes_LDADD= libdrizzle/libdrizzle.la
58check_PROGRAMS+= tests/unit/datetypes58check_PROGRAMS+= tests/unit/datetypes
59noinst_PROGRAMS+= tests/unit/datetypes59noinst_PROGRAMS+= tests/unit/datetypes
60XFAIL_TESTS+= tests/unit/datetypes
6160
62tests_unit_nulls_SOURCES= tests/unit/nulls.c tests/unit/common.c61tests_unit_nulls_SOURCES= tests/unit/nulls.c tests/unit/common.c
63tests_unit_nulls_LDADD= libdrizzle/libdrizzle.la62tests_unit_nulls_LDADD= libdrizzle/libdrizzle.la

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: