0

I'm working on a c# project that use a Versant Object Database back end and I'm trying to build a query that contains an arithmetic operator. The documentation states that it is supported but lack any example.

I'm trying to build something like this:

SELECT * FROM _orderItemObject WHERE _qtyOrdered - _qtySent > 0

If I try this statement in the Object Inspector I get a synthax error near the '-'.

Anyone has an example of a working VQL with that kind of statement?

Thanks

skaffman
  • 398,947
  • 96
  • 818
  • 769
Pascal
  • 712
  • 6
  • 12

2 Answers2

0

I am not sure that the Object Inspector will know the syntax for the arithmtic expression. However, in your code you should be referring to the fully qualified class. Then the syntax you are using should be perfectly fine.

Query query = new Query( session, "select * from com.yourCompany.yourClass where _qtyOrdered - _qtySent > 0 ");

QueryResult result = query.execute();

I just tried this out on one of my classes and it worked fine.

Cheers, -Robert

Robert
  • 368
  • 2
  • 8
  • After a lot of testing it appears that you are right, Object Inspector doesn't seem to be able to support this. But the problem was deeper then that. It seems the C# type decimal is weirdly supported in Versant and is transformed into a char array. That explains my error. Thanks for the answer. – Pascal Jun 09 '10 at 13:56
0

With C# and OQL you have to make sure you select the proper class extent. This is done by adding the "Extent" suffix to the class name. For example, in my Pet class I would identify all the pets with "PetExtent" in the OQL string.

Class members are accessed in the predicate by defining a local moniker, p in the code below. Any arithmetic expressions will be evaluated by the query engine.

string query="SELECT * FROM PetExtent AS p WHERE p.Name = \"Ferris\" AND (p.age + 5) > 4";
IQueryResult result = scope.GetOqlQuery(query).Execute();

foreach (object o in result)
   Out(o.ToString());

The best way to test OQL with Versant's C# binding is to use the OQL Query Browser integrated into Visual Studio. Look under the Versant Menu drop down in Visual Studio.

Best Regards,

Derek

Derek
  • 1
  • Thanks for pointing out the OQL Query Browser. It will save me a lot of hassle in the future. – Pascal Jun 09 '10 at 14:01
  • System.Decimal and BigDecimal (JDO binding) are indeed translated to strings for storage on the server. If you need to do math in your queries, you need to stick to one of the integer or floating point types. There is a table in the C# docs that explain the value type mappings from the CLR types to Versant server types. – Derek Jun 09 '10 at 17:18