summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/cast.result6
-rw-r--r--mysql-test/t/cast.test9
-rw-r--r--sql/field.h2
3 files changed, 16 insertions, 1 deletions
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result
index 0917c1762f6..2d65f8816e7 100644
--- a/mysql-test/r/cast.result
+++ b/mysql-test/r/cast.result
@@ -452,3 +452,9 @@ SELECT CONVERT(t2.a USING UTF8) FROM t1, t1 t2 LIMIT 1
1
DROP TABLE t1;
End of 5.1 tests
+create table t1 (f1 time, f2 date, f3 datetime);
+insert into t1 values ('11:22:33','2011-12-13','2011-12-13 11:22:33');
+select cast(f1 as unsigned), cast(f2 as unsigned), cast(f3 as unsigned) from t1;
+cast(f1 as unsigned) cast(f2 as unsigned) cast(f3 as unsigned)
+112233 20111213 20111213112233
+drop table t1;
diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test
index 8e60d548c2f..577b9ff4dce 100644
--- a/mysql-test/t/cast.test
+++ b/mysql-test/t/cast.test
@@ -284,3 +284,12 @@ DROP TABLE t1;
--echo End of 5.1 tests
+
+#
+# lp:737458 Casting dates and times into integers works differently in 5.1-micro
+#
+create table t1 (f1 time, f2 date, f3 datetime);
+insert into t1 values ('11:22:33','2011-12-13','2011-12-13 11:22:33');
+select cast(f1 as unsigned), cast(f2 as unsigned), cast(f3 as unsigned) from t1;
+drop table t1;
+
diff --git a/sql/field.h b/sql/field.h
index dc24bc3be3d..f40a4e2fb3c 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -149,7 +149,7 @@ public:
virtual bool str_needs_quotes() { return FALSE; }
virtual Item_result result_type () const=0;
virtual Item_result cmp_type () const { return result_type(); }
- virtual Item_result cast_to_int_type () const { return result_type(); }
+ virtual Item_result cast_to_int_type () const { return cmp_type(); }
static bool type_can_have_key_part(enum_field_types);
static enum_field_types field_type_merge(enum_field_types, enum_field_types);
static Item_result result_merge_type(enum_field_types);