Skip to content

Commit a74e3ff

Browse files
committed
feat: add categorize test when invalid mode
1 parent 6f5939e commit a74e3ff

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pymysqlreplication/tests/test_basic.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,35 @@ def test_categorize_none(self):
591591
self.assertIsInstance(write_rows_event, WriteRowsEvent)
592592
self.assertEqual(write_rows_event.rows[0]['category_of_none']['col1'], 'null')
593593

594+
def test_categorize_none_invalid(self):
595+
self.execute("SET SESSION SQL_MODE='ALLOW_INVALID_DATES'")
596+
self.execute("CREATE TABLE test_table (col0 INT, col1 VARCHAR(10), col2 DATETIME, col3 DATE, col4 SET('a', 'b', 'c'))")
597+
self.execute("INSERT INTO test_table VALUES (NULL, NULL, '0000-00-00 00:00:00', NULL, NULL)")
598+
self.resetBinLog()
599+
self.execute("UPDATE test_table SET col1 = NULL, col2 = NULL, col3='0000-00-00',col4 = 'd' WHERE col0 IS NULL")
600+
self.execute("COMMIT")
601+
602+
self.assertIsInstance(self.stream.fetchone(), RotateEvent)
603+
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent)
604+
self.assertIsInstance(self.stream.fetchone(), QueryEvent)
605+
self.assertIsInstance(self.stream.fetchone(), TableMapEvent)
606+
607+
event = self.stream.fetchone()
608+
if self.isMySQL56AndMore():
609+
self.assertEqual(event.event_type, UPDATE_ROWS_EVENT_V2)
610+
else:
611+
self.assertEqual(event.event_type, UPDATE_ROWS_EVENT_V1)
612+
self.assertIsInstance(event, UpdateRowsEvent)
613+
self.assertEqual(event.rows[0]["before_category_of_none"]["col0"], 'null')
614+
self.assertEqual(event.rows[0]["before_category_of_none"]["col1"], 'null')
615+
self.assertEqual(event.rows[0]["before_category_of_none"]["col2"], 'out of datetime2 range')
616+
self.assertEqual(event.rows[0]["before_category_of_none"]["col3"], 'null')
617+
self.assertEqual(event.rows[0]["before_category_of_none"]["col4"], 'null')
618+
self.assertEqual(event.rows[0]["after_category_of_none"]["col0"], 'null')
619+
self.assertEqual(event.rows[0]["after_category_of_none"]["col1"], 'null')
620+
self.assertEqual(event.rows[0]["after_category_of_none"]["col2"], 'null')
621+
self.assertEqual(event.rows[0]["after_category_of_none"]["col3"], 'out of date range')
622+
self.assertEqual(event.rows[0]["after_category_of_none"]["col4"], 'empty set')
594623

595624

596625
class TestMultipleRowBinLogStreamReader(base.PyMySQLReplicationTestCase):

0 commit comments

Comments
 (0)