OrientDB-NET.binary icon indicating copy to clipboard operation
OrientDB-NET.binary copied to clipboard

Backtick property names to avoid parsing errors

Open tbertels opened this issue 8 years ago • 1 comments

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.

tbertels avatar Dec 15 '16 07:12 tbertels

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"

jmcdaniel83 avatar Apr 05 '17 20:04 jmcdaniel83