# SQLInsert SQLExpr not working in V11

This worked fine in Mathematica 7. Any ideas how to fix it for version 11?

output = "{\"Name\"->\"Bob\", \"Date\"\[Rule]\"30/9/2016\"}";

SQLInsert[conn, "Table", {"ID", "Data"}, {123, SQLExpr[output]}]


... JDBC: Incorrect string value: '\xEF\x94\xA2\"3...' for column 'Data' at row 1

Edit

Mathematica 11 works if \[Rule] is replaced with -> i.e.

output = "{\"Name\"->\"Bob\", \"Date\"->\"30/9/2016\"}";


This is not necessary in version 7.

What operation can replace every \[Rule] with -> for use in version 11?

• I think this would best be fixed when you are generating that string (which I assume you do programmatically?). Where does it come from? Dec 23 '16 at 20:37
• when I think about it, maybe it would even be worth to give some background. As your own answer shows the problem is related to character encodings and there could be other cases which would create problems. It looks like you are storing mathematica expressions as strings. Is it important that these are in InputForm? Will you do any search operations on them? Otherwise you could store them as Compressed strings, which would guarantee that the strings only contain ASCII characters. Otherwise you might need to ensure that both ends use the same encoding. What DB are you working with? Dec 23 '16 at 20:44
• The DB is MySQL. I think there are only rules to replace, so the solutions should suffice. Dec 24 '16 at 16:07
• if you have a solution that works for you there might not be any reason to dive deeper into this. My own experience is that such workarounds eventually will fail -- usually at a time where one doesn't remember the details and there is even less time to understand them... As MySQL offers the possibility to set character encodings at a column level it should be quite simple to investigate that. Have you tried whether writing/reading strings with non-ascii characters works correctly? Might be worth the effort once you try to store the first non-english "Name" properties... Dec 25 '16 at 18:26
• Normally SQLExpr would not contain a string but an expression, e.g. output = {"Name" -> "Bob", "Date" -> "30/9/2016"}; SQLExpr[output]. That works fine in Mathematica 11. However, that happens not to be the case I had to fix. Jan 3 '17 at 11:43

You can use StringReplace to replace \[Rule] with ->:

StringReplace[
"{\"Name\"->\"Bob\", \"Date\"\[Rule]\"30/9/2016\"}",
"\[Rule]" -> "->"
]

"{\"Name\"->\"Bob\", \"Date\"->\"30/9/2016\"}"


To replace \[Rule] with ->

output = "{\"Name\"->\"Bob\", \"Date\"\[Rule]\"30/9/2016\"}";

output = FromCharacterCode[ToCharacterCode[output] /. (62754 -> Sequence[45, 62])];

SQLInsert[conn, "Table", {"ID", "Data"}, {123, SQLExpr[output]}]