diff options
author | unknown <konstantin@mysql.com> | 2004-06-09 03:21:50 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-06-09 03:21:50 +0400 |
commit | 27eda71204700eb6953205baf47d9cbeb4d367c1 (patch) | |
tree | ee6932d9f7ccdd66f6ccf84333180de34e7ac2a4 /sql/sql_prepare.cc | |
parent | 5cc410bb70dca2fad9dd7452ef294e1020186dda (diff) | |
download | mariadb-git-27eda71204700eb6953205baf47d9cbeb4d367c1.tar.gz |
Proposed fix for Bug#4026 "Microseconds part of TIME/DATETIME types
is broken (prepared statements)": fixed date handling in many places
of prepared statements code.
libmysql/libmysql.c:
Fix for Bug#4026:
- now buffer_length is defined for any buffer type. Network buffer
preallocation cleaned up.
- added constants for maximum buffer sizes necessary for MYSQL_TYPE_DATE,
MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME types.
- TIME/DATETIME packing/unpacking functions fixed
- now result set metadata is always updated from fields sent to COM_EXECUTE.
This is necessary to make 'SELECT ?' queries work without conversions.
sql/item.cc:
- added implementatoin of Item_param::get_date
sql/item.h:
- added enum_field_types Item_param::param_type. First step for proper
handling of placeholders.
- added get_date() implementation to prevent date -> string -> date
conversions when MYSQL_TYPE_DATE/DATETIME parameter is used in temporal
context.
sql/protocol.cc:
Fix for Bug#4026:
- PACKET_BUFFET_EXTRA_ALLOC -> PACKET_BUFFER_EXTRA_ALLOC.
The define itself was moved to .cc as it's used only in protocol.cc
- fixed Protocol_prep::store_time() call.
sql/protocol.h:
- PACKET_BUFFER_EXTRA_ALLOC moved to protocol.cc
sql/sql_prepare.cc:
Fix for Bug#4026:
- MYSQL_TYPE_TIME/DATETIME handling fixed.
- added initialization for Item_param::param_type in
setup_one_conversion_function
tests/client_test.c:
Test case for Bug#4026
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r-- | sql/sql_prepare.cc | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 1713c81a096..ab181e02735 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -332,20 +332,19 @@ static void set_param_time(Item_param *param, uchar **pos, ulong len) { uchar *to= *pos; TIME tm; - - /* TODO: why length is compared with 8 here? */ - tm.second_part= (length > 8 ) ? (ulong) sint4korr(to+7): 0; + tm.neg= (bool) to[0]; + day= (uint) sint4korr(to+1); /* Note, that though ranges of hour, minute and second are not checked here we rely on them being < 256: otherwise we'll get buffer overflow in make_{date,time} functions, which are called when time value is converted to string. */ - day= (uint) sint4korr(to+1); tm.hour= (uint) to[5] + day * 24; tm.minute= (uint) to[6]; tm.second= (uint) to[7]; + tm.second_part= (length > 8) ? (ulong) sint4korr(to+8) : 0; if (tm.hour > 838) { /* TODO: add warning 'Data truncated' here */ @@ -354,7 +353,6 @@ static void set_param_time(Item_param *param, uchar **pos, ulong len) tm.second= 59; } tm.day= tm.year= tm.month= 0; - tm.neg= (bool)to[0]; param->set_time(&tm, TIMESTAMP_TIME, MAX_TIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); @@ -365,14 +363,16 @@ static void set_param_time(Item_param *param, uchar **pos, ulong len) static void set_param_datetime(Item_param *param, uchar **pos, ulong len) { uint length; - + if ((length= get_param_length(pos, len)) >= 4) { uchar *to= *pos; TIME tm; - - tm.second_part= (length > 7 ) ? (ulong) sint4korr(to+7): 0; - + + tm.neg= 0; + tm.year= (uint) sint2korr(to); + tm.month= (uint) to[2]; + tm.day= (uint) to[3]; /* Note, that though ranges of hour, minute and second are not checked here we rely on them being < 256: otherwise @@ -386,11 +386,8 @@ static void set_param_datetime(Item_param *param, uchar **pos, ulong len) } else tm.hour= tm.minute= tm.second= 0; - - tm.year= (uint) sint2korr(to); - tm.month= (uint) to[2]; - tm.day= (uint) to[3]; - tm.neg= 0; + + tm.second_part= (length > 7) ? (ulong) sint4korr(to+7) : 0; param->set_time(&tm, TIMESTAMP_DATETIME, MAX_DATETIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); @@ -585,6 +582,7 @@ static void setup_one_conversion_function(THD *thd, Item_param *param, param->item_result_type= STRING_RESULT; } } + param->param_type= (enum enum_field_types) param_type; } #ifndef EMBEDDED_LIBRARY |