OrientDB-NET.binary
OrientDB-NET.binary copied to clipboard
Backtick property names to avoid parsing errors
When running this query:
myDB.Create.Property("batch", OType.Boolean).Class("aClass").Run();
I get this error: Error parsing query: CREATE PROPERTY aClass.batch BOOLEAN Encountered " <BATCH> "batch "" at line 1, column 26. Was expecting one of: <TO> ... <VALUE> ... <VALUES> ... <SET> (...)
So, according to https://github.com/orientechnologies/orientdb/issues/7001#issuecomment-266767026 I backticked the property name:
myDB.Create.Property("`batch`", OType.Boolean).Class("aClass").Run();
Fix: backtick all property names by default. It would also allow the use of "-" in property names.
I would agree that this should be done through the API, I as a user should not have to provide the backticks for property names. I was hitting this issue when property names start with digits and contain special characters like /
.
Digit Example
ODatabase connection = new ODatabase(ConnectionOptions);
// Produces the error
connection.Create
.Property("10_name", OType.Float)
.Class("ClassName")
.Run();
// Works
connection.Create
.Property("`10_name`", OType.Float)
.Class("ClassName")
.Run();
Produces the error:
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error parsing query:
CREATE PROPERTY ClassName.10_name Float
^
Encountered " <FLOATING_POINT_LITERAL> ".10 "" at line 1, column 24.
Was expecting:
"." ...
DB name="DatabaseName"
Special Character Example
ODatabase connection = new ODatabase(ConnectionOptions);
// Produces the error
connection.Create
.Property("header/bottom", OType.Long)
.Class("ClassName")
.Run();
// Works
connection.Create
.Property("`header/bottom`", OType.Long)
.Class("ClassName")
.Run();
Produces the error:
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error parsing query:
CREATE PROPERTY ClassName.header/bottom Long
^
Encountered " "/" "/ "" at line 1, column 31.
Was expecting one of:
<TO> ...
<VALUE> ...
<VALUES> ...
<SET> ...
<ADD> ...
... plus 88 more ...
DB name="DatabaseName"