summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mnogosearch.org>2013-09-12 21:31:14 +0400
committerAlexander Barkov <bar@mnogosearch.org>2013-09-12 21:31:14 +0400
commit499ddea5766d988adc858448c8eec549c7bedcc1 (patch)
treefd0a976fc3ac2b96c8f812c1bab2e0e57976cfce /sql/item.cc
parentc2b38529a9ca2ea09dfa73186d9350a0d6dcd6ac (diff)
downloadmariadb-git-499ddea5766d988adc858448c8eec549c7bedcc1.tar.gz
MDEV-4724 Some temporal functions do not preserve microseconds
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 1383500b007..5207d7d9ba3 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -488,6 +488,44 @@ uint Item::decimal_precision() const
}
+#if MARIADB_VERSION_ID < 1000000
+static uint ms_to_precision(uint ms)
+{
+ uint cut, precision;
+ for (cut= 10, precision= 6 ; precision > 0 ; cut*= 10, precision--)
+ {
+ if (ms % cut)
+ return precision;
+ }
+ return 0;
+}
+#else
+#error Change the code to use MYSQL_TIME_STATUS::precision instead.
+#endif
+
+
+uint Item::temporal_precision(enum_field_types type)
+{
+ if (const_item() && result_type() == STRING_RESULT &&
+ !is_temporal_type(field_type()))
+ {
+ MYSQL_TIME ltime;
+ String buf, *tmp;
+ int was_cut;
+ DBUG_ASSERT(fixed);
+ if ((tmp= val_str(&buf)) &&
+ (type == MYSQL_TYPE_TIME ?
+ str_to_time(tmp->ptr(), tmp->length(),
+ &ltime, TIME_TIME_ONLY, &was_cut) :
+ str_to_datetime(tmp->ptr(), tmp->length(),
+ &ltime, TIME_FUZZY_DATES, &was_cut)) >
+ MYSQL_TIMESTAMP_ERROR)
+ return min(ms_to_precision(ltime.second_part), TIME_SECOND_PART_DIGITS);
+ }
+ return min(decimals, TIME_SECOND_PART_DIGITS);
+}
+
+
void Item::print_item_w_name(String *str, enum_query_type query_type)
{
print(str, query_type);