Where builder with Connection.NewDataset

I need to select all fields from a table in the database with a user defined where clause. I was going to do . . .

Connection.newDataSet(Format('SELECT * FROM %s WHERE %s',

Obviously this won’t work but how can i accomplish this same idea easily??


You can use the Connection.GetQueryBuilder for this purpose.

  FQueryBuilder := aConnection.GetQueryBuilder;

  FQueryBuilder.MainTable.MasterTable := aTable;
  FQueryBuilder.Options := FQueryBuilder.Options + [qboGenerateSimpleSelect]; // allow to generate `select * from table`
  FQueryBuilder.Where.Xml := aWhereXML;
  lDataset := aConnection.NewDataset(FQueryBuilder.GenerateSelectSQL);

Awesome! Can I also do


To support parameters and the where clause at the same time?

Yes, you can.

for generating statements like

CustomerID = :id

you should use

with Connection.GetQueryBuilder.Where do
   Expression :=  NewBinaryExpression(NewField('','CustomerID'),NewParameter('ID'),dboEqual);

One follow up question. I see the SQL generated correctly with parameters and where builder. I am doing the following but need to refresh the params in the IDADataset. How do I do that?

 ds := Connection.NewDataset(qb.GenerateSelectSQL);

When I go to do ad ds.ParambyName it is nil.


you can call ds.RefreshParams;