p6spy / p6spy

P6Spy is a framework that enables database data to be seamlessly intercepted and logged with no code changes to the application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logged query does not escape the newline ("\n") character in the json field, which breaks sql parsing

george24601 opened this issue · comments

Setup:

  • p6spy:3.8.6
  • spring-boot: 1.5.16
  • Mysql: 5.7
CREATE TABLE `json_test` (
  `id` bigint(20) NOT NULL,
  `metadata` json DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

The query logged by p6spy is

insert into json_test (id, metadata) values (1, '{"field": "\n"}');

The newline character will fails the sql parsing

mysql> insert into json_test (id, metadata) values (1, '{"field": "\n"}');
ERROR 3140 (22032): Invalid JSON text: "Invalid escape character in string." at position 10 in value for column 'json_test.metadata'.

Note that

  • The actual query sent through jdbc is successful
  • the above query is fine if the field is text
mysql> insert into text_test (id, metadata) values (1, '{"field": "\n"}');
Query OK, 1 row affected (0.01 sec)

@george24601 any chance to suggest the solution (Pull Request) from your side?