Escaping backslashes and newlines in strings has problems
The whole explanation can be found in this thread: https://groups.google.com/forum/#!topic/orient-database/znZhid64EjU
Trying to store newlines in a property, I tried things like
UPDATE MyClass set mytext = 'Hello\nWorld'
and
UPDATE MyClass set mytext = "Hello\nWorld"
but no luck.
insert into MyClass content { key: 1, mytext: "Hello\nWorld" }
does work as expected...
Then I thought I found a workaround using the MERGE command
update V merge { "value2": "Hello\nWorld! Backslash = \ " } where key = "x"
BUT there are other strange issues with escaped BACKSLASHES!
The following FAILS with java.lang.IllegalStateException: Missing closed string character: '"', position: 75
update V merge { "value2": "Backslash = \" } where key = "x"
while this seems to work (added a space character at the very end)
update V merge { "value2": "Backslash = \ " } where key = "x"
but when I want to update a javascript function, I have to escape each backslash twice !!!
The following will not behave as expected
update OFunction merge { code : "// \/\/" } where name = 'testBackslashInComment'
A select query on the database will return
"code": "// //"
instead of the expected
"code": "// \/\/"
But the following query
update OFunction merge { code : "// \\/\\/" } where name = 'testBackslashInComment'
will produce
"code": "// \/\/"
But using SET instead of MERGE, we get:
update OFunction set code = "// \/\/" where name = 'testBackslashInComment'
we get the expected
"code": "// \/\/"
(but then we are back to the \n not working...)
Is this still valid against 1.7.8 or majors?
Yes, the bug still exists. This is most annoying for javascript functions (since it will damage regular expressions using \ for escaping a special char, or javascript strings containg \n, and comments etc. )
Simple test:
go to studio, and try to save a function with the folowing code
// \/
will become after saving
// /
Is this fixed? I'm not running into this anymore since c0af38b.
maybe my last commit also fixed this, it would be really good news. I'm going to check it
Yes, it's fixed too. @maggiolo00 could you take a final look at this (regarding Studio functions, maybe I'm missing something) and in case close it?
Thanks
@luigidellaquila i've checked on this https://github.com/orientechnologies/orientdb-studio/issues/75 and it is fixed
I'm still experiencing this problem in a different form. All my latex equations are stripped of backslashes. Example: "\frac{2}{3}" is stripped to "rac{2}{3}". The worst thing is that I have little control over the data source
I also have trouble escaping. I can't find a clear definition of how it is supposed to work. Can someone give me list of characters that need to be escaped inside a single-quoted string in an SQL-query and how to escape them?
This is still an issue. It should not be closed
This comment helped me https://github.com/orientechnologies/orientdb/issues/5469#issuecomment-164777360