BinaryExpression

The BinaryExpression is the part of the Dynamic Where feature that represents operations such as

Addition
And
Concat
Divide
Equal
Greater
GreaterOrEqual
In
Less
LessOrEqual
Like
Modulo
Multiply
NotEqual
NotIn
NotLike
Or
Subtraction
Xor

It must contain exactly two subnodes, representing the Left and the Right expressions the operator applies to.

Implementations

Example

Target SQL Where clause:

price > 20 AND Amount <= 5

 

WhereExpression where =
  new BinaryExpression(
    new BinaryExpression(
      new FieldExpression("OrderDetails","price"),  
      new ConstantExpression(20),
      BinaryOperator.Greater),
    new BinaryExpression(
      new FieldExpression("OrderDetails","Amount"),  
      new ConstantExpression(5),BinaryOperator.LessOrEqual),
  BinaryOperator.And);

 

let whereExpression: WhereExpression = BinaryExpression(
  BinaryExpression(
    FieldExpression("OrderDetails","Price"),
    ConstantExpression(20),
    BinaryOperator.Greater
  ),
  BinaryExpression(
    FieldExpression("OrderDetails", "Amount"),
    ConstantExpression(5),
    BinaryOperator.LessOrEqual
  ),
  BinaryOperator.And
)

 

WhereExpression where =
    new BinaryExpression(
        new BinaryExpression(
            new FieldExpression("OrderDetails","price"),
            new ConstantExpression(20),
        BinaryOperator.Greater),
        new BinaryExpression(
            new FieldExpression("OrderDetails","Amount"),  
            new ConstantExpression(5),
        BinaryOperator.LessOrEqual),
    BinaryOperator.And);

 

let whereExpression: WhereExpression = BinaryExpression(
  BinaryExpression(
    FieldExpression("OrderDetails","Price"),
    ConstantExpression(20),
    BinaryOperator.Greater
  ),
  BinaryExpression(
    FieldExpression("OrderDetails", "Amount"),
    ConstantExpression(5),
    BinaryOperator.LessOrEqual
  ),
  BinaryOperator.And
)

 

with tbl_OrderDetails, DynamicWhere do begin
    Expression:=NewBinaryExpression(
      NewBinaryExpression(NewField(LogicalName,'price'),
          NewConstant(20),dboGreater),
      NewBinaryExpression(NewField(LogicalName,'Amount'),
          NewConstant(5),dboLessOrEqual),
    dboAnd);
end;

 

myTable.dynamicWhere = new RemObjects.DataAbstract.DynamicWhere(
  new RemObjects.DataAbstract.BinaryExpression(
    new RemObjects.DataAbstract.BinaryExpression(
      new RemObjects.DataAbstract.FieldExpression("price"),
      new RemObjects.DataAbstract.ConstantExpression("Byte", 20),
        "Greater"),
    new RemObjects.DataAbstract.BinaryExpression(
      new RemObjects.DataAbstract.FieldExpression("Amount"),
      new RemObjects.DataAbstract.ConstantExpression("Byte", 5),
        "LessOrEqual"),
    "And"
  )
);

Generated XML/JSON

<?xml version="1.0"?>
<query xmlns="http://www.remobjects.com/schemas/dataabstract/queries/5.0" version="5.0">
  <where>
    <binaryoperation operator="And">
      <binaryoperation operator="Greater">
        <field tablename="OrderDetails">price</field>
        <constant type="Byte" null="0">20</constant>
      </binaryoperation>
      <binaryoperation operator="LessOrEqual">
        <field tablename="OrderDetails">Amount</field>
        <constant type="Byte" null="0">5</constant>
      </binaryoperation>
    </binaryoperation>
  </where>
</query>
{
  "type": "query.where",
  "expression": {
    "type": "binaryoperation",
    "left": {
      "type": "binaryoperation",
      "left": {
        "type": "field",
        "field": "price",
        "table": "OrderDetails"
      },
      "operator": "Greater",
      "right": {
        "type": "constant",
        "datatype": "Byte",
        "value": "20"
      }
    },
    "operator": "And",
    "right": {
      "type": "binaryoperation",
      "left": {
        "type": "field",
        "field": "Amount",
        "table": "OrderDetails"
      },
      "operator": "LessOrEqual",
      "right": {
        "type": "constant",
        "datatype": "Byte",
        "value": "5"
      }
    }
  }
}