summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2004-10-16 00:12:59 +0400
committerunknown <konstantin@mysql.com>2004-10-16 00:12:59 +0400
commit9aefc403f9f707edf0f84ce401d32929067aea30 (patch)
tree49c6d8401938fd8137914328918f5f64de298327 /sql/item.cc
parentf125849dd1fa2b7eaca3aea5f84d7d79fb201ec2 (diff)
downloadmariadb-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/item.cc')
-rw-r--r--sql/item.cc14
1 files changed, 5 insertions, 9 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 0366ea29485..cff7b739893 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -988,9 +988,10 @@ String *Item_param::val_str(String* str)
return str;
case TIME_VALUE:
{
- if (str->reserve(MAX_DATE_REP_LENGTH))
+ if (str->reserve(MAX_DATE_STRING_REP_LENGTH))
break;
- TIME_to_string(&value.time, str);
+ str->length((uint) my_TIME_to_str(&value.time, (char*) str->ptr()));
+ str->set_charset(&my_charset_bin);
return str;
}
case NULL_VALUE:
@@ -1020,24 +1021,19 @@ const String *Item_param::query_val_str(String* str) const
case TIME_VALUE:
{
char *buf, *ptr;
- String tmp;
str->length(0);
/*
TODO: in case of error we need to notify replication
that binary log contains wrong statement
*/
- if (str->reserve(MAX_DATE_REP_LENGTH+3))
+ if (str->reserve(MAX_DATE_STRING_REP_LENGTH+3))
break;
/* Create date string inplace */
buf= str->c_ptr_quick();
ptr= buf;
*ptr++= '\'';
- tmp.set(ptr, MAX_DATE_REP_LENGTH, &my_charset_bin);
- tmp.length(0);
- TIME_to_string(&value.time, &tmp);
-
- ptr+= tmp.length();
+ ptr+= (uint) my_TIME_to_str(&value.time, ptr);
*ptr++= '\'';
str->length((uint32) (ptr - buf));
break;