Skip to content

Commit c209c27

Browse files
committed
BUG30950184: Fix error when using the fractional part in DATETIME
In the X DevAPI implementation, an error is raised when using the fractional part in DATETIME types. This patch fixes this issue by taking in account the fractional part when detecting DATETIME types and adds tests for regression.
1 parent b6d5d57 commit c209c27

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

lib/mysqlx/result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -488,10 +488,10 @@ def _map_datetime(self):
488488
"""Map datetime."""
489489
if self._length == 10:
490490
self._col_type = ColumnType.DATE
491-
elif self._length == 19:
492-
self._col_type = ColumnType.DATETIME
493491
elif self._flags & DatetimeColumnFlags.TIMESTAMP > 0:
494492
self._col_type = ColumnType.TIMESTAMP
493+
elif self._length >= 19:
494+
self._col_type = ColumnType.DATETIME
495495
else:
496496
raise ValueError("Datetime mapping scenario unhandled")
497497

tests/test_mysqlx_crud.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License, version 2.0, as
@@ -2662,19 +2662,23 @@ def test_column_metadata(self):
26622662

26632663
self.session.sql(
26642664
"CREATE TABLE {0}(age INT, name VARCHAR(50), pic VARBINARY(100), "
2665-
"config JSON, created DATE, active BIT)"
2666-
"".format(table_name)).execute()
2665+
"config JSON, created DATE, updated DATETIME(6), ts TIMESTAMP(2), "
2666+
"active BIT)".format(table_name)).execute()
26672667
self.session.sql(
2668-
"INSERT INTO {0} VALUES (21, 'Fred', NULL, NULL, '2008-07-26', 0)"
2668+
"INSERT INTO {0} VALUES (21, 'Fred', NULL, NULL, '2008-07-26', "
2669+
"'2019-01-19 03:14:07.999999', '2020-01-01 10:10:10+05:30', 0)"
26692670
"".format(table_name)).execute()
26702671
self.session.sql(
2671-
"INSERT INTO {0} VALUES (28, 'Barney', NULL, NULL, '2012-03-12'"
2672-
", 0)".format(table_name)).execute()
2672+
"INSERT INTO {0} VALUES (28, 'Barney', NULL, NULL, '2012-03-12', "
2673+
"'2019-01-19 03:14:07.999999', '2020-01-01 10:10:10+05:30', 0)"
2674+
"".format(table_name)).execute()
26732675
self.session.sql(
2674-
"INSERT INTO {0} VALUES (42, 'Wilma', NULL, NULL, '1975-11-11', 1)"
2676+
"INSERT INTO {0} VALUES (42, 'Wilma', NULL, NULL, '1975-11-11', "
2677+
"'2019-01-19 03:14:07.999999', '2020-01-01 10:10:10+05:30', 1)"
26752678
"".format(table_name)).execute()
26762679
self.session.sql(
2677-
"INSERT INTO {0} VALUES (67, 'Betty', NULL, NULL, '2015-06-21', 0)"
2680+
"INSERT INTO {0} VALUES (67, 'Betty', NULL, NULL, '2015-06-21', "
2681+
"'2019-01-19 03:14:07.999999', '2020-01-01 10:10:10+05:30', 0)"
26782682
"".format(table_name)).execute()
26792683

26802684
table = self.schema.get_table("test")
@@ -2705,7 +2709,22 @@ def test_column_metadata(self):
27052709
self.assertEqual("test", col.get_table_name())
27062710
self.assertEqual(mysqlx.ColumnType.JSON, col.get_type())
27072711

2712+
col = result.columns[4]
2713+
self.assertEqual("created", col.get_column_name())
2714+
self.assertEqual("test", col.get_table_name())
2715+
self.assertEqual(mysqlx.ColumnType.DATE, col.get_type())
2716+
27082717
col = result.columns[5]
2718+
self.assertEqual("updated", col.get_column_name())
2719+
self.assertEqual("test", col.get_table_name())
2720+
self.assertEqual(mysqlx.ColumnType.DATETIME, col.get_type())
2721+
2722+
col = result.columns[6]
2723+
self.assertEqual("ts", col.get_column_name())
2724+
self.assertEqual("test", col.get_table_name())
2725+
self.assertEqual(mysqlx.ColumnType.TIMESTAMP, col.get_type())
2726+
2727+
col = result.columns[7]
27092728
self.assertEqual("active", col.get_column_name())
27102729
self.assertEqual("test", col.get_table_name())
27112730
self.assertEqual(mysqlx.ColumnType.BIT, col.get_type())

0 commit comments

Comments
 (0)