MacroExpression

The MacroExpression is part of the Dynamic Where feature; it represents a call to a macro function.

Implementation

Example

Target SQL where clause:

WHERE SUBSTRING(lastname FROM 1 FOR 3) = 'Col'

 

WhereExpression where = new BinaryExpression(
                          new MacroExpression("Copy",
                            {
                              new FieldExpression("lastname"),
                              new ConstantExpression(1),
                              new ConstantExpression(3)
                            }),
                          new ConstantExpression("Col"),
                          BinaryOperator.Equal);

 

let whereExpression = BinaryExpression(
                        MacroExpression("Copy",
                          [
                            FieldExpression("lastname"),
                            ConstantExpression(1),
                            ConstantExpression(3)
                          ]),
                        ConstantExpression("Col"),
                        BinaryOperator.Equal)

 

WhereExpression where = new BinaryExpression(
                          new MacroExpression("Copy",
                            {
                              new FieldExpression("lastname"),
                              new ConstantExpression(1),
                              new ConstantExpression(3)
                            }),
                          new ConstantExpression("Col"),
                          BinaryOperator.Equal);

 

let whereExpression = BinaryExpression(
                        MacroExpression("Copy",
                          [
                            FieldExpression("lastname"),
                            ConstantExpression(1),
                            ConstantExpression(3)
                          ]),
                        ConstantExpression("Col"),
                        BinaryOperator.Equal)

 

  we := TDAWhereBuilder.NewBinaryExpression(
                          TDAWhereBuilder.NewMacro('Copy',
                            [TDAWhereBuilder.NewField('','lastname'),
                             TDAWhereBuilder.NewConstant('1', datByte),
                             TDAWhereBuilder.NewConstant('3', datByte)]),
                          TDAWhereBuilder.NewConstant('Col'),
                          dboEqual);

 

myTable.dynamicWhere = new RemObjects.DataAbstract.DynamicWhere(
        new RemObjects.DataAbstract.BinaryExpression(
          new RemObjects.DataAbstract.MacroExpression("Copy",
            [new RemObjects.DataAbstract.FieldExpression("lastname"),
             new RemObjects.DataAbstract.ConstantExpression("Integer", 1),
             new RemObjects.DataAbstract.ConstantExpression("Integer", 3)]),
          new RemObjects.DataAbstract.ConstantExpression("String", "Col"), "Equal")
        ));

Generated XML/JSON

<?xml version="1.0"?>
<query xmlns="http://www.remobjects.com/schemas/dataabstract/queries/5.0" version="5.0">
  <where>
    <binaryoperation operator="Equal">
      <macro name="Copy">
        <field>lastname</field>
        <constant type="Byte" null="0">1</constant>
        <constant type="Byte" null="0">3</constant>
      </macro>
      <constant type="WideString" null="0">Col</constant>
    </binaryoperation>
  </where>
</query>
{
  "type": "query.where",
  "expression": {
    "type": "binaryoperation",
    "left": {
      "type": "macro",
      "name": "Copy",
      "items": [
        {
          "type": "field",
          "field": "lastname"
        },
        {
          "type": "constant",
          "datatype": "Byte",
          "value": "1"
        },
        {
          "type": "constant",
          "datatype": "Byte",
          "value": "3"
        }
      ]
    },
    "operator": "Equal",
    "right": {
      "type": "constant",
      "datatype": "WideString",
      "value": "Col"
    }
  }
}