diff options
author | unknown <konstantin@mysql.com> | 2004-10-16 00:12:59 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-10-16 00:12:59 +0400 |
commit | 9aefc403f9f707edf0f84ce401d32929067aea30 (patch) | |
tree | 49c6d8401938fd8137914328918f5f64de298327 /sql/time.cc | |
parent | f125849dd1fa2b7eaca3aea5f84d7d79fb201ec2 (diff) | |
download | mariadb-git-9aefc403f9f707edf0f84ce401d32929067aea30.tar.gz |
A fix and test case for Bug#6049 "Loss of sign when using prepared
statements and negative time/date values".
The bug was in wrong sprintf format used in the client library.
The fix moves TIME -> string conversion functions to sql-common and
utilized them in the client library.
include/my_time.h:
Declarations for new functions shared between the client and server.
libmysql/libmysql.c:
Fix for Bug#6049 "Loss of sign when using prepared statements and negative
time/date values": use the same function as the server to convert
date/time/datetime values to strings.
sql-common/my_time.c:
Implementation of my_{time,datetime,date,TIME}_to_str: it's
needed by the client library, so it should be shared.
sql/field.cc:
Don't create String object if it's not needed.
sql/item.cc:
Don't create String object if it's not needed: TIME_to_string was
moved to my_TIME_to_str, with different arguments.
sql/item_timefunc.cc:
Don't create String object if it's not needed.
sql/mysql_priv.h:
TIME_to_string and MAX_DATE_REP_LENGTH moved to the client library.
MAX_DATE_REP_LENGTH was renamed to MAX_DATE_STRING_REP_LENGTH to not
conflict with the same name in libmysql.c
sql/protocol.cc:
Don't create String object if it's not needed.
sql/time.cc:
Implementation of my_{time,date,datetime,TIME}_to_str moved to my_time.c
shared between the client and the server.
tests/client_test.c:
A test case for Bug#6049.
Diffstat (limited to 'sql/time.cc')
-rw-r--r-- | sql/time.cc | 59 |
1 files changed, 3 insertions, 56 deletions
diff --git a/sql/time.cc b/sql/time.cc index 4421b6aa00f..e76b169b336 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -747,13 +747,7 @@ const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format, void make_time(const DATE_TIME_FORMAT *format __attribute__((unused)), const TIME *l_time, String *str) { - long length= my_sprintf((char*) str->ptr(), - ((char*) str->ptr(), - "%s%02d:%02d:%02d", - (l_time->neg ? "-" : ""), - l_time->hour, - l_time->minute, - l_time->second)); + uint length= (uint) my_time_to_str(l_time, (char*) str->ptr()); str->length(length); str->set_charset(&my_charset_bin); } @@ -762,12 +756,7 @@ void make_time(const DATE_TIME_FORMAT *format __attribute__((unused)), void make_date(const DATE_TIME_FORMAT *format __attribute__((unused)), const TIME *l_time, String *str) { - long length= my_sprintf((char*) str->ptr(), - ((char*) str->ptr(), - "%04d-%02d-%02d", - l_time->year, - l_time->month, - l_time->day)); + uint length= (uint) my_date_to_str(l_time, (char*) str->ptr()); str->length(length); str->set_charset(&my_charset_bin); } @@ -776,15 +765,7 @@ void make_date(const DATE_TIME_FORMAT *format __attribute__((unused)), void make_datetime(const DATE_TIME_FORMAT *format __attribute__((unused)), const TIME *l_time, String *str) { - long length= my_sprintf((char*) str->ptr(), - ((char*) str->ptr(), - "%04d-%02d-%02d %02d:%02d:%02d", - l_time->year, - l_time->month, - l_time->day, - l_time->hour, - l_time->minute, - l_time->second)); + uint length= (uint) my_datetime_to_str(l_time, (char*) str->ptr()); str->length(length); str->set_charset(&my_charset_bin); } @@ -894,38 +875,4 @@ ulonglong TIME_to_ulonglong(const TIME *time) return 0; } - -/* - Convert struct DATE/TIME/DATETIME value to string using built-in - MySQL time conversion formats. - - SYNOPSIS - TIME_to_string() - - NOTE - The string must have at least MAX_DATE_REP_LENGTH bytes reserved. -*/ - -void TIME_to_string(const TIME *time, String *str) -{ - switch (time->time_type) { - case MYSQL_TIMESTAMP_DATETIME: - make_datetime((DATE_TIME_FORMAT*) 0, time, str); - break; - case MYSQL_TIMESTAMP_DATE: - make_date((DATE_TIME_FORMAT*) 0, time, str); - break; - case MYSQL_TIMESTAMP_TIME: - make_time((DATE_TIME_FORMAT*) 0, time, str); - break; - case MYSQL_TIMESTAMP_NONE: - case MYSQL_TIMESTAMP_ERROR: - str->length(0); - str->set_charset(&my_charset_bin); - break; - default: - DBUG_ASSERT(0); - } -} - #endif |