Conversation
fulghum
left a comment
There was a problem hiding this comment.
Code looks good, but I'm not sure that we're matching MySQL's behavior for JSON_QUOTE, particularly around escape chars.
| arg: expression.NewLiteral(`\`, types.Text), | ||
| exp: `"\\"`, |
There was a problem hiding this comment.
Should this be an error, same as the test case for json_unquote?
There was a problem hiding this comment.
I'm not sure why json_unquote throws an error in the first place; I'm having trouble replicating in MySQL...
| arg: expression.NewLiteral(`"\t\u0032"`, types.Text), | ||
| exp: `"\"\\t\\u0032\""`, |
There was a problem hiding this comment.
Should this be escaping the backslashes in the control characters? It seems like MySQL doesn't return the same result. I'm not sure I totally understand what MySQL is doing here though... so I'm probably missing something. I don't get why it drops the \ in \u0032.
mysql> SELECT JSON_QUOTE('"\t\u0032"');
+--------------------------+
| JSON_QUOTE('"\t\u0032"') |
+--------------------------+
| "\"\tu0032\"" |
+--------------------------+There was a problem hiding this comment.
I believe this has something to do with the shell vs string literals?
When compiling and running dolt sql, I get the same output:
tmp/main> SELECT JSON_QUOTE('"\t\u0032"');
+--------------------------+
| JSON_QUOTE('"\t\u0032"') |
+--------------------------+
| "\"\tu0032\"" |
+--------------------------+
1 row in set (0.00 sec)| arg: expression.NewLiteral(`\b\f\n\r\t\"`, types.Text), | ||
| exp: `"\\b\\f\\n\\r\\t\\\""`, |
There was a problem hiding this comment.
For this one, with MySQL, I'm getting:
mysql> select JSON_QUOTE('\b\f\n\r\t\"');
+----------------------------+
| JSON_QUOTE('\b\f\n\r\t\"') |
+----------------------------+
| "\bf\n\r\t\"" |
+----------------------------+The MySQL docs call out that \f is a supported escape sequence, but it also says for non-supported escape sequences it ignores the \, which seems to be what it's doing here with \f.
There was a problem hiding this comment.
Same as above
tmp/main> select json_quote("\b\f\n\r\t\"");
+----------------------------+
| json_quote("\b\f\n\r\t\"") |
+----------------------------+
| "\bf\n\r\t\"" |
+----------------------------+
1 row in set (0.00 sec)
fulghum
left a comment
There was a problem hiding this comment.
Thanks for confirming with the dolt sql examples. Looks good to me!
MySQL Docs:
https://dev.mysql.com/doc/refman/8.0/en/json-creation-functions.html#function_json-quote