.net Prepared query throwing error

47 views
Skip to first unread message

Ticket Voodoo

unread,
Sep 9, 2016, 6:53:50 AM9/9/16
to OrientDB
I have the following 2 tests (see code below)
The first test works fine CanQUeryDBNoParams,
However, the second test CanQueryDBWithParams
fails with the following error which I have unsuccessfuly tried to google for help with to no avail, so any help with this would be greatly appreciated.

I am using the latest .net from nuget against the lastest OrientDB running on windows 10, as the first test works I know the code and database works.

error:
Test Name:    CanQueryDBWithParams
Test FullName:    UnitTestTVGraphDB.UnitTestTVGraphDB.CanQueryDBWithParams
Test Source:    E:\TVMercurialSCM\johnc\Source\TicketVoodooGraphDB\UnitTestTVGraphDB\UnitTestTVGraphDB.cs : line 91
Test Outcome:    Failed
Test Duration:    0:00:00.0297952

Result StackTrace:   
at Orient.Client.Protocol.Response.Receive()
   at Orient.Client.Protocol.Connection.ExecuteOperationInternal(IOperation operation)
   at Orient.Client.Protocol.Connection.ExecuteOperation(IOperation operation)
   at Orient.Client.API.Query.PreparedQuery.RunInternal()
   at Orient.Client.API.Query.PreparedQuery.Run(String[] properties)
   at UnitTestTVGraphDB.UnitTestTVGraphDB.CanQueryDBWithParams() in E:\TVMercurialSCM\johnc\Source\TicketVoodooGraphDB\UnitTestTVGraphDB\UnitTestTVGraphDB.cs:line 106
Result Message:   
Test method UnitTestTVGraphDB.UnitTestTVGraphDB.CanQueryDBWithParams threw exception:
Orient.Client.OException: com.orientechnologies.orient.core.exception.OSerializationException: Error on unmarshalling content. Class: q
    DB name="VehicleHistoryGraph"
java.lang.ArrayIndexOutOfBoundsException:





[TestMethod]
 
public void CanQueryDBNoParams()
{
 
    using (GraphDbContext dbContext = new GraphDbContext())
    {
 
        using (ODatabase database = new ODatabase(GraphDbConnection.DatabaseAlias))
        {
            List<ODocument> result = database
                .Select("firstName").As("firstName")                        
                .Also("lastName").As("lastName")
                .Also("fullName").As("fullName")
                .Also("gender").As("gender")
                .Also("birthday").As("birthday")
                .From<Person>()
                .OrderBy("lastName").Descending()
                .ToList();
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count > 0);
            Console.WriteLine(String.Format("result count:{0}", result.Count));
 
            foreach (var doc in result)
            {
                Console.WriteLine(String.Format("CanQueryDBNoParams doc.OClassName:{0}", doc.OClassName ));
            }
        }
    }
}
 
[TestMethod]
 
public void CanQueryDBWithParams()
{
 
    using (GraphDbContext dbContext = new GraphDbContext())
    {
 
        using (ODatabase database = new ODatabase(GraphDbConnection.DatabaseAlias))
        {
          
            var query = new PreparedQuery(" SELECT FROM Person WHERE lastName = ? ""*:0");
 
            var selectedValue = database
                .Query(query)
                .Run("Murphy")
                .ToList();
 
            Assert.IsTrue(selectedValue.Count > 0);
 
        }
    }
}

Oleksandr Gubchenko

unread,
Sep 9, 2016, 9:08:54 AM9/9/16
to OrientDB
You have an ArrayIndexOutOfBoundsException, can you post the line numbers of your code?

Ticket Voodoo

unread,
Sep 9, 2016, 9:13:20 AM9/9/16
to OrientDB
line 106 is the .Query

thanks :-)
screen shot below


Auto Generated Inline Image 1

Ticket Voodoo

unread,
Sep 9, 2016, 9:18:04 AM9/9/16
to OrientDB
running the query
SELECT FROM Person WHERE lastName = 'Murphy'
in Studio brings back results so I know that the query works as well against the VehicleHistoryGraph example db.

Oleksandr Gubchenko

unread,
Sep 9, 2016, 9:42:27 AM9/9/16
to OrientDB
Can you try with this code snippet? I've tested it, and it works without exceptions.

var selectedValue = database
.Select()
.From("Person")
.Where("lastName")
.Equals("Murphy")
.ToList();

Hope it helps.

Ticket Voodoo

unread,
Sep 9, 2016, 9:55:07 AM9/9/16
to OrientDB
ah great thank you.
yes that worked - so what that implies is that:
1. don't use the PreparedQuery
2. use the select -> chained build query and insert the "parameters" into the chain.

is that a work around ?
Doesn't feel quite "right" if the PreparedQuery has a bug ?

thank you.
Reply all
Reply to author
Forward
0 new messages