0
$\begingroup$

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?

$\endgroup$
8
  • $\begingroup$ I think this would best be fixed when you are generating that string (which I assume you do programmatically?). Where does it come from? $\endgroup$ Commented Dec 23, 2016 at 20:37
  • $\begingroup$ 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? $\endgroup$ Commented Dec 23, 2016 at 20:44
  • $\begingroup$ The DB is MySQL. I think there are only rules to replace, so the solutions should suffice. $\endgroup$ Commented Dec 24, 2016 at 16:07
  • $\begingroup$ 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... $\endgroup$ Commented Dec 25, 2016 at 18:26
  • $\begingroup$ 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. $\endgroup$ Commented Jan 3, 2017 at 11:43

2 Answers 2

1
$\begingroup$

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

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

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]}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.