Brackets placement SQL Import.

With the SQL:

WHERE (   ADR.Advorname LIKE 'R%'
       OR ADR.Advorname LIKE 'I%')
  AND (   ADR.Adname LIKE 'U%'
       OR ADR.Adname LIKE 'O%')

We get the following error when importing from TatMetaSQL.


We use this source code:

procedure TForm1.BtnSqlStringAddClick(Sender: TObject);
  SQLStringToMetaSQL (MemoFelder.Text, MetaSql);
  MemoSQL.Text := MetaSQL.SQL;

The bracket placement in this example is definitely needed because otherwise the logic changes.

Best regards.

That function is targeted for internal use in Query Studio, and it was not intended to be a fully-functional SQL parser. Indeed, unfortunately, such expression construction is not supported by the parser.

Is there any way to create such a query with "TatMetaSQL"?

If not, is it possible to implement this functionality? 

Here is a code that constructs such meta sql:

  CondA, CondA1, CondA2: TatSQLCondition;
  CondB, CondB1, CondB2: TatSQLCondition;
  AdvOrName, Adname: TatSQLField;
  atMetaSQL1.SQLTables.Add.TableName := 'ADR';

  AdvOrName := atMetaSQL1.SQLFields.Add;
  AdvOrName.FieldName := 'Advorname';
  AdvOrName.DataType := ftString;
  AdvOrName.Active := False;
  AdvOrName.TableAlias := 'ADR';

  AdName := atMetaSQL1.SQLFields.Add;
  AdName.FieldName := 'Adname';
  AdName.DataType := ftString;
  AdName.Active := False;
  AdName.TableAlias := 'ADR';

  CondA := atMetaSQL1.Conditions.Add;
  CondA.SubConditionsLogicalOper := lgOr;
  CondA.ConditionType := ctSubConditions;
  CondA1 := CondA.SubConditions.Add;
  CondA1.FieldAlias := 'Advorname';
  CondA1.&Operator := 'LIKE';
  CondA1.Value := 'R%';
  CondA2 := CondA.SubConditions.Add;
  CondA2.FieldAlias := 'Advorname';
  CondA2.&Operator := 'LIKE';
  CondA2.Value := 'I%';

  CondB := atMetaSQL1.Conditions.Add;
  CondB.SubConditionsLogicalOper := lgOr;
  CondB.ConditionType := ctSubConditions;
  CondB1 := CondB.SubConditions.Add;
  CondB1.FieldAlias := 'Adname';
  CondB1.&Operator := 'LIKE';
  CondB1.Value := 'U%';

  CondB2 := CondB.SubConditions.Add;
  CondB2.FieldAlias := 'Adname';
  CondB2.&Operator := 'LIKE';
  CondB2.Value := 'O%';

  // get the sql
  SQL := atMetaSQL1.SQL;