diff --git a/pymysqlreplication/packet.py b/pymysqlreplication/packet.py index 936dc8c5..cb60ba9d 100644 --- a/pymysqlreplication/packet.py +++ b/pymysqlreplication/packet.py @@ -43,9 +43,9 @@ def read_offset_or_inline(packet, large): if t in (JSONB_TYPE_LITERAL, JSONB_TYPE_INT16, JSONB_TYPE_UINT16): - return (t, None, packet.read_binary_json_type_inlined(t)) + return (t, None, packet.read_binary_json_type_inlined(t, large)) if large and t in (JSONB_TYPE_INT32, JSONB_TYPE_UINT32): - return (t, None, packet.read_binary_json_type_inlined(t)) + return (t, None, packet.read_binary_json_type_inlined(t, large)) if large: return (t, packet.read_uint32(), None) @@ -255,7 +255,7 @@ def read_length_coded_pascal_string(self, size): def read_variable_length_string(self): """Read a variable length string where the first 1-5 bytes stores the length of the string. - + For each byte, the first bit being high indicates another byte must be read. """ @@ -384,9 +384,9 @@ def read_binary_json_type(self, t, length): raise ValueError('Json type %d is not handled' % t) - def read_binary_json_type_inlined(self, t): + def read_binary_json_type_inlined(self, t, large): if t == JSONB_TYPE_LITERAL: - value = self.read_uint16() + value = self.read_uint32() if large else self.read_uint16() if value == JSONB_LITERAL_NULL: return None elif value == JSONB_LITERAL_TRUE: diff --git a/pymysqlreplication/tests/test_data_type.py b/pymysqlreplication/tests/test_data_type.py index 8d222290..21351114 100644 --- a/pymysqlreplication/tests/test_data_type.py +++ b/pymysqlreplication/tests/test_data_type.py @@ -469,6 +469,16 @@ def test_json_large(self): self.assertEqual(event.rows[0]["values"]["value"], to_binary_dict(data)) + def test_json_large_with_literal(self): + if not self.isMySQL57(): + self.skipTest("Json is only supported in mysql 5.7") + data = dict([('foooo%i'%i, 'baaaaar%i'%i) for i in range(2560)], literal=True) # Make it large with literal + create_query = "CREATE TABLE test (id int, value json);" + insert_query = """INSERT INTO test (id, value) VALUES (1, '%s');""" % json.dumps(data) + event = self.create_and_insert_value(create_query, insert_query) + + self.assertEqual(event.rows[0]["values"]["value"], to_binary_dict(data)) + def test_json_types(self): if not self.isMySQL57(): self.skipTest("Json is only supported in mysql 5.7")