UnaryExpression

The UnaryExpression is part of the Dynamic Where feature; it represents logical operations:

  • Not
  • Minus

It contains one operand (an expression) and a unary operator.

Implementation

Example

Target SQL where clause:

WHERE lastname NOT LIKE 'D%'

 

WhereExpression where = new UnaryExpression(
                          new BinaryExpression(
                            new FieldExpression("SALESMEN","lastname"),
                            new ConstantExpression("D%", DataType.String),
                            BinaryOperator.Like),
                          UnaryOperator.Not);

 

let whereExpression = UnaryExpression(
            BinaryExpression(
              FieldExpression("SALESMEN", "lastname"),
              ConstantExpression("D%", DataType.String),
              BinaryOperator.Like),
            UnaryOperator.Not)

 

WhereExpression where = new UnaryExpression(
                          new BinaryExpression(
                              new FieldExpression("SALESMEN","lastname"),
                              new ConstantExpression("D%", DataType.String),
                              BinaryOperator.Like),
                          UnaryOperator.Not);

 

let whereExpression = UnaryExpression(
            BinaryExpression(
              FieldExpression("SALESMEN", "lastname"),
              ConstantExpression("D%", DataType.String),
              BinaryOperator.Like),
            UnaryOperator.Not)

 

with ClientDataModule.tbl_SALESMEN, DynamicWhere do begin
  Expression:=NewUnaryExpression(
                  NewBinaryExpression(
                    NewField(LogicalName,'lastname'),
                    NewConstant('D%', datString),
                    dboLike),
                  duoNot);
end;

 

myTable.dynamicWhere = new RemObjects.DataAbstract.DynamicWhere(
  new RemObjects.DataAbstract.UnaryExpression(
      new RemObjects.DataAbstract.BinaryExpression(
          new RemObjects.DataAbstract.FieldExpression("LastName"),
          new RemObjects.DataAbstract.ConstantExpression("String", "D%"), "Equal"), "Not")
  );

Generated XML/JSON

<?xml version="1.0"?>
<query xmlns="http://www.remobjects.com/schemas/dataabstract/queries/5.0" version="5.0">
  <where>
    <unaryoperation operator="Not">
      <binaryoperation operator="Like">
        <field tablename="SALESMEN">lastname</field>
        <constant type="String" null="0">D%</constant>
      </binaryoperation>
    </unaryoperation>
  </where>
</query>
{
  "type": "query.where",
  "expression": {
    "type": "unaryoperation",
    "operator": "Not",
    "expression": {
      "type": "binaryoperation",
      "left": {
        "type": "field",
        "field": "lastname",
        "table": "SALESMEN"
      },
      "operator": "Like",
      "right": {
        "type": "constant",
        "datatype": "String",
        "value": "D%"
      }
    }
  }
}