summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc43
1 files changed, 31 insertions, 12 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 69821df986a..22b5adc4597 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -7078,20 +7078,12 @@ bool Item_insert_value::fix_fields(THD *thd, Item **items)
}
if (arg->type() == REF_ITEM)
+ arg= static_cast<Item_ref *>(arg)->ref[0];
+ if (arg->type() != FIELD_ITEM)
{
- Item_ref *ref= (Item_ref *)arg;
- if (ref->ref[0]->type() != FIELD_ITEM)
- {
- my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function");
- return TRUE;
- }
- arg= ref->ref[0];
+ my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function");
+ return TRUE;
}
- /*
- According to our SQL grammar, VALUES() function can reference
- only to a column.
- */
- DBUG_ASSERT(arg->type() == FIELD_ITEM);
Item_field *field_arg= (Item_field *)arg;
@@ -7655,6 +7647,33 @@ bool Item_cache_datetime::cache_value()
str_value.copy(*res);
null_value= example->null_value;
unsigned_flag= example->unsigned_flag;
+
+ if (!null_value)
+ {
+ switch(field_type())
+ {
+ case MYSQL_TYPE_DATETIME:
+ case MYSQL_TYPE_TIMESTAMP:
+ {
+ MYSQL_TIME ltime;
+ int was_cut;
+ const timestamp_type tt=
+ str_to_datetime(str_value.charset(),
+ str_value.ptr(),
+ str_value.length(),
+ &ltime,
+ TIME_DATETIME_ONLY,
+ &was_cut);
+ if (tt != MYSQL_TIMESTAMP_DATETIME || was_cut)
+ null_value= true;
+ else
+ my_datetime_to_str(&ltime, const_cast<char*>(str_value.ptr()));
+ }
+ default:
+ {}
+ }
+ }
+
return TRUE;
}