Pass special character string to Orient DB funcation

116 views
Skip to first unread message

Abhijit Shivathare

unread,
Aug 18, 2016, 9:31:06 AM8/18/16
to OrientDB
We are using the node.js to connect the Orient DB using orientjs node package.
when we pass the value with special character string to Orient DB function (JavaScript function) ,  it gives error when we create vertex. 

Please suggest the solution for same.  

alessand...@gmail.com

unread,
Aug 18, 2016, 9:34:11 AM8/18/16
to OrientDB
Hi,
do you have a test case to reproduce the problem?

Thanks,
Alessandro

Abhijit Shivathare

unread,
Aug 18, 2016, 9:48:01 AM8/18/16
to orient-...@googlegroups.com
 value to pass function

 desc: 'WhatsApp funny Videos 2016\nTry not to grin or Laugh Hardest\n',
 id = 1000

 function
var db = orient.getGraph();
var vkQuery = "CREATE VERTEX post CONTENT {'id':'"+ id+"', 'desc':'"+ desc +"'}";
var vkInsert = db.command("sql",vkQuery);

error : 
    addpost: 'error com.orientechnologies.orient.core.sql.parser.TokenMgrError: Lexical error at line 1, column 637.  Encountered: "\\n" (10), after : "\\\'WhatsApp funny Videos 2016"',


alessand...@gmail.com

unread,
Aug 18, 2016, 10:20:30 AM8/18/16
to OrientDB
Hi,
could you try with

desc = 'WhatsApp funny Videos 2016\\nTry not to grin or Laugh Hardest\\n';


var vkQuery = "CREATE VERTEX post CONTENT {'id':"+ id+", 'desc':'"+ desc +"'}";

Best regards,
Alessandro

Abhijit Shivathare

unread,
Aug 18, 2016, 10:31:22 AM8/18/16
to OrientDB
How to change the run time value to 'desc', does any encoder for value?


desc = 'WhatsApp funny Videos 2016\\nTry not to grin or Laugh Hardest\\n';

var vkQuery = "CREATE VERTEX post CONTENT {'id':"+ id+", 'desc':'"+ desc +"'}";



alessand...@gmail.com

unread,
Aug 18, 2016, 10:37:32 AM8/18/16
to OrientDB
I'm sorry, I don't understand what you mean, could you explain better?

Alessandro

alessand...@gmail.com

unread,
Aug 18, 2016, 10:43:24 AM8/18/16
to OrientDB
Hi,
did you mean update the records ?

If yes, you could use 
update Post set `desc`="yourDesc" where id=1000

beacuse desc is a reserved word and you must use `desc`

Thanks,
Alessandro

Abhijit Shivathare

unread,
Aug 18, 2016, 2:54:46 PM8/18/16
to OrientDB
I need to update input string special characters ,( e.g / to // ) when it use in query.

alessand...@gmail.com

unread,
Aug 19, 2016, 4:15:19 AM8/19/16
to OrientDB
Hi,
could you post an example of your query to update input string special characters ?

Thanks

Abhijit Shivathare

unread,
Aug 19, 2016, 4:57:39 AM8/19/16
to orient-...@googlegroups.com
I have one function 'addpost' with language  'JavaScript' & Input parameters for the function are id and desc. 'desc' parameter value  may be contain the spacial characters. like ('WhatsApp funny Videos 2016\nTry not to grin or Laugh Hardest\n')


var db = orient.getGraph();

var vkQuery = "CREATE VERTEX post CONTENT {'id':'"+ id+"', 'desc':'"+ desc +"'}"; 
var vkInsert = db.command("sql",vkQuery);

It cause for error  :     addpost: 'error com.orientechnologies.orient.core.sql.parser.TokenMgrError: Lexical error at line 1, column 637.  Encountered: "\\n" (10), after : "\\\'WhatsApp funny Videos 2016"',

Is there is any way resolve this issue.

alessand...@gmail.com

unread,
Aug 19, 2016, 5:13:48 AM8/19/16
to OrientDB
Hi,
I tried it and I did not have errors


Abhijit Shivathare

unread,
Aug 19, 2016, 5:31:59 AM8/19/16
to OrientDB
try with this value 
desc = ' Bollywood Superstar Akshay Kumar, Ileana D'Cruz'
you may get the error



alessand...@gmail.com

unread,
Aug 19, 2016, 9:02:49 AM8/19/16
to OrientDB
Hi,
you could use

var db = orient.getGraph();
var id= 1000;
var desc = "Bollywood Superstar Akshay Kumar, Ileana D'Cruz"

var vkQuery = 'CREATE VERTEX post CONTENT {"id":'+ id+',"desc":"'+ desc +'"}';
var vkInsert = db.command("sql",vkQuery);


Best regards,
Alessandro

prasad....@anzu.org

unread,
Aug 25, 2016, 2:31:33 AM8/25/16
to OrientDB
Hello, I have similar issue  where the desc field is a text box where user can add any text. I run into issues where the function breaks when there are special characters in desc like single or double quot's , / \ # ! $ % etc.
is there a way or inbuilt function that will take care or these special chars ?  you can use same function code to reproduce the issue with desc with different special characters .     

Suyog Kale

unread,
Aug 29, 2016, 1:19:23 AM8/29/16
to OrientDB
hi Alessandro,

What if source string contains both single and double quotes.

var
db = orient.getGraph();
var id= 1000;
var desc = "Bollywood Superstar "Akshay Kumar", Ileana D'Cruz"

var vkQuery = 'CREATE VERTEX post CONTENT {"id":'+ id+',"desc":"'+ desc +'"}';
var vkInsert = db.command("sql",vkQuery);

alessand...@gmail.com

unread,
Aug 29, 2016, 6:31:21 AM8/29/16
to OrientDB
Hi,
you could use 

var db = orient.getGraph();
var id= 1000;
var mydesc = "Bollywood Superstar \"Akshay Kumar\", Ileana D'Cruz";
var desc=JSON.stringify(mydesc);



var vkQuery = 'CREATE VERTEX post CONTENT {"id":'+ id+',"desc":'+ desc +'}';
var vkInsert = db.command("sql",vkQuery);



Hope it helps.


Best regards,

Alessandro


Reply all
Reply to author
Forward
0 new messages