Newline in query


The question is trivial, but I was not able to find this information in the docs.
How do I set (in OrientDB 3.0.19) a field with newlines inside? I’m using the following code:

OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
String dbname = "test";

OrientDB orientDB = new OrientDB("memory:", dbConfig);
orientDB.createIfNotExists( dbname, ODatabaseType.MEMORY );
session = new ODatabasePool( orientDB, dbname, "admin", "admin" ).acquire();

session.createVertexClass( "Test" );
OVertex v = session.newVertex( "Test" );

session.query( "UPDATE " + v.getIdentity() + " SET `prop`='A\nB'" );

but it gives this exception:

Exception in thread “main” com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Lexical error at line 1, column 28. Encountered: “\n” (10), after : “'A”
DB name=“test”
Error Code=“1”
at com.orientechnologies.orient.core.sql.parser.OStatementCache.throwParsingException(
at com.orientechnologies.orient.core.sql.parser.OStatementCache.parse(
at com.orientechnologies.orient.core.sql.parser.OStatementCache.get(
at com.orientechnologies.orient.core.sql.parser.OStatementCache.get(
at com.orientechnologies.orient.core.sql.OSQLEngine.parse(
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentEmbedded.query(

Hi @Maverick

In general, I strongly suggest you to avoid hard-wiring strings in the queries, use query parameters instead:

session.query("UPDATE " + v.getIdentity() + " SET prop = ?", "A\nB" );
` `

It also solves all the problems with special characters



Oh, and use session.command() (not query()) when doing updates :wink:

@luigidellaquila yes, I just copy-pasted some test code without actually checking it.

Actually, this kind of little documented tricks are (from my point of view) the biggest difficulty in using OrientDB.

Anyway, thank you, this works.