summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Nozdrin <alik@sun.com>2009-11-06 12:17:01 +0300
committerAlexander Nozdrin <alik@sun.com>2009-11-06 12:17:01 +0300
commit1a0728831084fabe1ccaa50e92aebfca761f8adf (patch)
tree48dcef0eb0f84d76e81fe1e11ddba5228118b601 /sql
parent52b1bfe4050e163d844df1c10c648b33d25e28c5 (diff)
parent0b43c4e74c81ff136093c3238e03fb0c38b562fd (diff)
downloadmariadb-git-1a0728831084fabe1ccaa50e92aebfca761f8adf.tar.gz
Auto-merge from mysql-trunk-merge.
Diffstat (limited to 'sql')
-rw-r--r--sql/item.cc34
1 files changed, 27 insertions, 7 deletions
diff --git a/sql/item.cc b/sql/item.cc
index dc0adfdc29e..90b209e880f 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -7064,17 +7064,37 @@ int stored_field_cmp_to_item(Field *field, Item *item)
/*
If comparing DATE with DATETIME, append the time-part to the DATE.
So that the strings are equally formatted.
- A DATE converted to string is 10 characters, and a DATETIME converted
- to string is 19 characters.
+ A DATE converted to string is 10 (MAX_DATE_WIDTH) characters,
+ and a DATETIME converted to string is 19 (MAX_DATETIME_WIDTH) characters.
*/
field_type= field->type();
+ uint32 item_length= item_result->length();
if (field_type == MYSQL_TYPE_DATE &&
- item_result->length() == 19)
+ item_length == MAX_DATETIME_WIDTH)
field_tmp.append(" 00:00:00");
- else if (field_type == MYSQL_TYPE_DATETIME &&
- item_result->length() == 10)
- item_result->append(" 00:00:00");
-
+ else if (field_type == MYSQL_TYPE_DATETIME)
+ {
+ if (item_length == MAX_DATE_WIDTH)
+ item_result->append(" 00:00:00");
+ else if (item_length > MAX_DATETIME_WIDTH)
+ {
+ /*
+ We don't store microsecond part of DATETIME in field
+ but item_result contains it. As we compare DATETIMEs as strings
+ we must trim trailing 0's in item_result's microsecond part
+ to ensure "YYYY-MM-DD HH:MM:SS" == "YYYY-MM-DD HH:MM:SS.0000"
+ */
+ char *end= (char *) item_result->ptr() + item_length - 1;
+ /* Trim trailing 0's */
+ while (*end == '0')
+ end--;
+ /* Trim '.' if no microseconds */
+ if (*end == '.')
+ end--;
+ DBUG_ASSERT(end - item_result->ptr() + 1 >= MAX_DATETIME_WIDTH);
+ item_result->length(end - item_result->ptr() + 1);
+ }
+ }
return stringcmp(&field_tmp,item_result);
}
if (res_type == INT_RESULT)